Wrap, don’t port: bgumbel as an agent-callable skill
You ask your coding agent to fit a bimodal extreme-value model to a series of pressure maxima. The method exists, published and implemented in an R package, but the agent works in Python and offers the obvious shortcut: it will write the likelihood itself, in a few dozen lines, and fit it with a general optimizer. The code runs, the numbers look plausible, and from that moment you own an untested reimplementation of a published model that nobody else will ever check against the original.
The alternative is to leave the method where it was validated and give the agent a narrow, typed way to call it. This post makes the case for that choice, wrapping instead of porting, with the package bgumbel as the worked example. The contract, bridge and dispatcher that make up the pattern are summarized, with a cost estimate, in an earlier post on the token cost of agent-driven R analysis, so here the focus is on why the wrap is the better engineering choice and on what a good wrap adds to the package it calls.
This post expands a LinkedIn Article of May 6, 2026: Wrapping a CRAN package as an agent-callable skill, with bgumbel as the first wrapped package of community-skills.
The model and the package
The bimodal Gumbel distribution was introduced with Cira Otiniano, Roberto Vila and Marcelo Bourguignon in the Austrian Journal of Statistics (OTINIANO et al., 2023) to model extreme data with two regimes. It takes the classical Gumbel density f_G(x;\mu,\sigma) and multiplies it by a quadratic term in a third parameter \delta:
f_{BG}(x;\mu,\sigma,\delta) = \frac{\left[(1-\delta x)^2 + 1\right] f_G(x;\mu,\sigma)}{Z_\delta}, \qquad Z_\delta = 1 + \delta^2\sigma^2\frac{\pi^2}{6} + (\delta\mu + \delta\sigma\gamma - 1)^2,
where \gamma is Euler’s constant. With \delta = 0 the density reduces to the classical Gumbel. With \delta \neq 0 it can have two modes, using three parameters where a free mixture of two Gumbel components needs five. The paper applies it to block maxima of daily atmospheric pressure from an automatic weather station in Corumbá, Mato Grosso do Sul, between 2015 and 2020, 29 blocks of about 60 days from 1,774 daily observations.
Two details of the paper matter for what follows. The maximum likelihood estimates have, in general, no closed form and must be obtained numerically. And the numerical work was done with the R package bgumbel, on CRAN since March 2021 and at version 0.0.3 since 2021-03-31, which exports the density, distribution function, quantile, random generation, the two closed-form moments and the maximum likelihood fit. By the cranlogs count cited in the LinkedIn Article, in a snapshot taken on 2026-05-01, the package had passed 48,000 cumulative downloads.
Why porting is the expensive option
A port looks cheap because the formula above fits on one line. What does not fit on one line is everything that made the original trustworthy. The functions in bgumbel pass the checks CRAN runs on every release, and the papers that build on the model exercise the mathematics indirectly every time they use it. A Python rewrite starts that validation from nothing. It also creates a debt that never closes, since every fix upstream has to be mirrored by hand, and the day someone forgets, the port drifts away from the published model without any error to announce it.
There is a third option between the two, embedding R inside the agent’s process with a binding such as rpy2. It avoids the cost of starting a new process for each call, but it ties the calling interpreter to the binary interface of the target runtime, requires native dependencies at build time and turns a version mismatch into an opaque crash. For an agent, where each call is a deliberate step and not an inner loop, a spawn of about 100 milliseconds is irrelevant. Portability and the ability to debug a failed call are not.
Why the wrap is also the better record
The second argument for wrapping has nothing to do with cost. When an analyst runs a command by hand, sees an odd number and copies it into a notebook, the path back to the exact input is usually gone. When an agent calls a wrapped skill, the input goes in as one JSON object and the output comes back as another. That pair can be stored, read by a reviewer and replayed by another team on the same input. Reproducibility stops being a promise in the methods section and becomes the default behavior of the tool.
The two arguments are independent. A mature package with years of validation is worth wrapping on the first ground alone, and a fragile workflow that needs deterministic logs is worth wrapping on the second alone. A well-cited statistical package meets both.
What the wrap adds to bgumbel
A wrap that only translated JSON into function calls would already be useful. The bgumbel skill in community-skills goes further, because the most common failure of numerical maximum likelihood is not in the model but in the starting values.
Call bgumbel::mlebgumbel with the package’s own automatic start switched off and a degenerate starting point of (0, 0, 0), and the optimizer stops with the message valor inicial em 'vmmin' não é finito, the R error for a non-finite initial value. An analyst at the console reads that, picks new values and tries again. An agent should not have to guess, so the skill exposes the guess as a function of its own, init_theta, which takes the data and returns a starting triple: the sample median for \mu, the median absolute deviation with the usual 1.4826 rescaling and a floor of 0.001 for \sigma, and \delta = 0.1 as a near-unimodal seed from which the optimizer can move toward two modes. It needs at least four observations.
The repository’s own example runs it on ten values:
echo '{"fn":"init_theta","data":[1.2,2.3,0.5,4.1,3.0,5.5,1.8,2.7,0.9,3.3]}' \
| Rscript --vanilla skills/bgumbel/invoke.R{"ok":true,"fn":"init_theta","result":{"mu":2.5,"sigma":1.55673,"delta":0.1,"strategy":"median + MAD + delta=0.1 (near-unimodal seed)","n":10}}The answer can be checked by hand, which is the point of making the heuristic visible. The two central values of the sorted sample are 2.3 and 2.7, so the median is 2.5. The absolute deviations from 2.5 have a median of 1.05, and 1.05 times 1.4826 is 1.55673. An agent, or the person reviewing its work, can inspect the seed before any fit is attempted.
The fit itself then uses that heuristic as its default. If the caller passes only the data, the dispatcher seeds the optimizer with init_theta and reports "init_strategy": "auto". If the caller passes its own theta, the dispatcher uses it and reports "user_supplied". If that theta makes the optimizer fail, the dispatcher retries with the heuristic seed and reports "fallback_auto_after_user_failed", along with the theta_used. If even the fallback fails, the response is "ok": false with a message that points the caller to init_theta. A call with a bad seed looks like this:
echo '{"fn":"mlebgumbel","data":[<observations>],"theta":[0,0,0],"auto":false}' \
| Rscript --vanilla skills/bgumbel/invoke.RThe response carries the estimates, their standard errors, the log-likelihood, the sample size, the strategy that was actually used and the seed it started from. The most common failure of numerical maximum likelihood no longer reaches the agent as an exception it has to interpret. It arrives as a field it can read, and as a line in the record that tells a reviewer which path produced the estimate.
Beyond bgumbel
The bimodal Gumbel skill is the example, not the point. The same recipe wraps anything an analyst loads with library(), and the LinkedIn Article named forecast, lme4 and mgcv as the next candidates. As a matter of design, the contract does not depend on R. A subprocess that reads JSON and writes JSON leaves the caller indifferent to the language behind it, and that independence falls out of the choice from the start rather than being added later. As a matter of scope, the hub chose otherwise. Since 2026-05-11 its public scope is R packages only, as the repository’s changelog records, and the post on community-skills v0.2.0 describes what the hub ships within that scope. The Bayesian side of the same bimodal model, where a pooled posterior can look right while every chain is stuck in one mode, is in the post on parallel tempering.
So, the next time an agent offers to rewrite a published estimator in its own language, ask what it would take to check the rewrite against the original. If the honest answer is “nobody will”, the wrap is the cheaper path, and the more auditable one too.
Paper. OTINIANO, C. E. G.; VILA, R.; BROM, P. C.; BOURGUIGNON, M. On the bimodal Gumbel model with application to environmental data. Austrian Journal of Statistics, v. 52, n. 2, p. 45-65, 2023. DOI: 10.17713/ajs.v52i2.1392. Page on this site: pcbrom.com/papers.
References.
BROM, P. C.; OTINIANO, C. E. G.; VILA, R.; BOURGUIGNON, M. bgumbel: bimodal Gumbel distribution. R package version 0.0.3. CRAN, 2021. Available at: https://cran.r-project.org/package=bgumbel.
BROM, P. C. community-skills: a community hub for wrapping packages as agent-callable skills. GitHub, 2026. Available at: https://github.com/pcbrom/community-skills.
The package is on CRAN at cran.r-project.org/package=bgumbel, the paper is at DOI 10.17713/ajs.v52i2.1392, and the skill is open on GitHub: github.com/pcbrom/community-skills. I write about this kind of work, scientific method, statistics, and AI applied with rigor, on LinkedIn: linkedin.com/in/pcbrom.