An atlas_session wraps an LLM agent, an R working environment holding your
data, and a run directory on disk. The agent builds models by executing R
code; every code chunk and conversation turn is checkpointed to the run
directory, so a session survives crashes and R restarts (see
atlas_resume()). The agent pauses and asks for your approval or input via
the console when it needs a decision (interactive sessions only).
Run directory contents
data.rds,meta.rds- inputs, so the session can be rebuilt coldcode.R/code.rds- every code chunk the agent executedturns.rds- the full conversationreport.md,leaderboard.csv,models.rds- final artifacts
Public fields
chatThe underlying ellmer chat object.
envEnvironment the agent's code runs in (
datalives here).dirRun directory used for checkpoints and artifacts.
codeCharacter vector of every code chunk executed so far.
test_dataHeld-out test rows (when
test_prop > 0); never placed in the agent's environment.tallyLive experiment tally: one row per recorded attempt (
attempt,name,metric,value,best,verdict), kept by atlas from the agent'srecord_attemptcalls and persisted totally.csvin the run directory.
Methods
atlas_session$new()
Create a session.
Usage
atlas_session$new(
data,
outcome,
n_models = 3,
goal = NULL,
constraints = NULL,
chat = NULL,
dir = NULL,
on_ask = NULL,
display = c("console", "markdown"),
stopping_rounds = 3,
stopping_tolerance = 0.05,
exclude = NULL,
interject = NULL,
autonomous = FALSE,
test_prop = 0,
compact_at = 1e+05,
max_steps = Inf,
max_runtime = Inf
)Arguments
dataA data.frame.
outcomeName of the outcome column (string).
n_modelsHow many final candidate models to build.
goalOptional extra instructions for the agent, e.g. "prioritise interpretability" or a full custom brief.
constraintsDomain knowledge as hard requirements: a list of strings and/or
constraint()objects (see alsocon_uses(),con_monotone()). Machine-checked constraints are verified against every final model.chatAn ellmer chat object. Defaults to
ellmer::chat_anthropic(). Any ellmer provider works.dirRun directory for checkpoints and all output (reports, validation plots, model bundles). Defaults to a timestamped folder under
getOption("atlas.dir", ".atlas")- setoptions(atlas.dir = "~/atlas-runs")once to send every run to a location of your choosing, or passdirexplicitly per run.on_askOptional handler for the agent's questions:
function(question)returning the user's answer as a string. WhenNULL(default), questions are asked in the console (interactive sessions) or answered with "use your best judgment" (scripts). Used byatlas_app()to route questions to the browser.displayHow verbose progress is formatted:
"console"(cli rules and colours) or"markdown"(fenced code blocks, for front-ends that render the stream as markdown, likeatlas_app()).stopping_roundsStopping rule: give up on an iteration (adding candidates, or a refinement loop) after this many consecutive attempts without improvement.
stopping_toleranceStopping rule: an attempt only counts as an improvement if it beats the best validation metric so far by at least this relative fraction, between 0 and 1 (e.g.
0.05for 5%).excludeColumns the models must not use (not available at prediction time, or leakage). They are removed from the data before the agent ever sees it - the strongest possible guarantee.
interjectOptional
function()polled after every tool call. Return a string to interrupt the agent with a message mid-build (it is delivered with its next tool result, marked as highest priority); returnNULLwhen there is nothing to say. Used byatlas_app()'s "Send now" box; front-ends typically read the message from a file or queue.autonomousRun without a human: the agent states its plan and proceeds instead of asking for approval, and never calls
ask_user.test_propProportion of rows (0 to <1) to hold out as a final test set the agent never sees. Final models are evaluated on it by Atlas itself after the run (
$results()$test_leaderboard), so the comparison can't be gamed by overfitting the agent's own validation scheme.0(default) disables the split.compact_atToken budget for the conversation. When the context grows past this many input tokens, it is compacted before the next message: the transcript is archived to the run directory, the window is cleared, and the agent is re-oriented with a briefing built from the session state (no extra LLM call). Long runs stay inside the model's context window and stop paying to re-read their own history. Set to
Infto disable.max_stepsHard budget: the maximum number of code executions the agent gets in this session. Unlike the stopping rules (which the agent applies itself), this is mechanically enforced - past the limit the
run_r_codetool refuses to execute and instructs the agent to finalise from what it has.Inf(default) disables.max_runtimeHard budget: wall-clock seconds for this session process, enforced the same way as
max_steps. Timing restarts onatlas_resume().Inf(default) disables.
atlas_session$build()
Run the full model-building loop. Streams the agent's
narration and asks for approval/input in the console when needed.
After the build, machine-checked constraints are verified against
every final model; violations are sent back to the agent to fix, up
to max_fix_rounds times.
Arguments
verboseShow the agent's narration, code, and output live.
max_fix_roundsHow many constraint-repair rounds to allow.
refineAfter the winning algorithm is found (and constraints pass), iterate on its feature selection and engineering - one change per attempt, same validation scheme - until the session's stopping rules trigger (
stopping_roundsattempts without astopping_tolerancegain). The refined model is added to the results alongside the original.validateProduce reviewable validation output (gain, calibration, grouped residuals, one-ways, PDPs) for the winning model as interactive HTML files in the run directory. Needs the
modelblueprintpackage; silently skipped when it isn't installed.
atlas_session$tell()
Send a follow-up instruction or question to the agent in the same context ("why did you drop cyl?", "add a 4th model", ...).
atlas_session$results()
Collect results: the fitted models, the leaderboard, the report, and the full code trail.
atlas_session$add_budget()
Grant the agent more mechanical budget. The hard caps
(max_steps, max_runtime) protect unattended runs, but they also
bind follow-up $tell() calls on a finished session - top the
budget up explicitly when you want more work done:
res$session$add_budget(steps = 25).
atlas_session$compact()
Compact the conversation to save tokens: archive the
transcript to the run directory, clear the context window, and
re-orient the agent with a state briefing on the next message. The
R environment (models, data) and code log are untouched - they are
the durable memory. Called automatically when the context exceeds
compact_at; call it yourself before a long follow-up to start
from a lean window.
atlas_session$checkpoint()
Write the current code log and conversation to the run directory. Called automatically after every tool call and reply.
Examples
if (FALSE) { # \dontrun{
s <- atlas_session$new(mtcars, outcome = "mpg", n_models = 3)
res <- s$build() # agent works, asking for approval as needed
res # leaderboard + per-model report
s$tell("try a model with only 3 predictors as a 4th candidate")
# later, in a new R session:
s <- atlas_resume(".atlas/20260703-141500")
} # }