Reference
Optimization sessions¶
An optimization session takes your agent from a baseline to a reviewable verdict from one config file. It runs your agent on fixed tasks, finds wasted work, turns eligible findings into candidate changes, measures them with a bounded search, and judges the result against an acceptance contract you froze in advance. It never applies a change.
The parts it uses are documented separately:
- findings;
- source receipts;
- the transformation registry;
- the optimization search;
- its acceptance contract.
A session connects them so you don't write pass requests or an evaluation callback yourself.
What you need¶
- A git checkout of your agent. Sessions run it at the commit you're on. Uncommitted edits aren't included.
- A runner that speaks the guided runner protocol:
it reads a JSON request from standard input (
task_id,inputandtrace_path) and writes a native trace totrace_path. Put the agent's answer intrace.metadata["output"]. - A workload of tasks with independent expected answers and a deterministic scorer, as in guided optimization.
- Source receipts on the functions a pass may change:
@traceable(capture_source=True).
The config¶
{
"schema": "agentloop.session_config/v1",
"repo": ".",
"workload": "tasks.json",
"tuning": ["t1", "t2", "t3"],
"held_out": ["h1", "h2", "h3", "h4", "h5", "h6"],
"runner": ["{python}", "runner.py"],
"objective": "runtime_ms",
"effects": {
"app/agent.py:lookup": {"effect": "none", "deterministic": true}
},
"passes": {
"ast.memoize_pure_function": {
"cache": {"maxsize": 128, "scope": "process", "freshness": "static"},
"arguments": "hashable",
"returns": "immutable"
}
},
"acceptance": {"min_improvement_pct": 20, "min_quality": 1.0, "repetitions": 2, "min_tasks": 5},
"budget": {"max_attempts": 200, "max_elapsed_s": 900},
"timeout_s": 60
}
| Field | Meaning |
|---|---|
repo, workload |
Paths relative to the config file |
tuning, held_out |
Task ids. The search tunes on the first and judges once on the second. They can't overlap. |
runner |
The runner's argv, run in each temporary checkout. {python} is the interpreter running AgentLoop. |
objective |
runtime_ms (the trace's elapsed time) or cost_usd |
effects |
What you declare about functions, keyed by path:qualname as the source receipt records them. Passes need these declarations; they aren't inferred. |
passes |
Your settings for each pass, for example the memoize pass's cache contract. A pass without settings abstains. |
acceptance |
The acceptance contract. Required. |
budget |
max_attempts, max_elapsed_s and max_cost_usd for the search |
timeout_s |
Per-run limit for the runner |
env, inherit_env |
The runner's environment, as for candidate execution |
seed |
The search's seed |
What it does¶
- Freezes the config, source revision, workload, runner and pass versions
into
session.jsonas hashes, with the tuning and held-out manifests, before anything runs. - Captures a baseline: each tuning task once, in a temporary worktree.
- Binds findings to passes. It attaches your effect declarations to the
matching spans, then maps each finding to the passes registered for its
rule. For example, repeated identical tool calls (
parallelize_tools) map to the memoize pass, with the call's span as evidence. Each binding is proposed, abstained (with reasons) or unsupported (no pass applies). Candidates that make the same change are merged. - Searches candidate combinations on the tuning tasks, each in its own worktree, then runs repeated, counterbalanced pairs on the held-out tasks. Two candidates that edit the same file are never combined.
- Reports.
report.jsonandreport.mdhold: - the verdict and its reasons;
- every binding;
- the held-out evidence and its interval;
- each candidate's diff, receipt and rollback;
git applyandgit apply -Rcommands to use after your review.
The verdict is recommend_for_review, rejected, indeterminate,
incomplete (the budget ran out) or no_candidates.
Interrupting and resuming¶
Every attempt is appended to journal.jsonl. Each entry includes the hash of
the one before, so an edited or reordered journal is detected. Press Ctrl+C,
or let the process stop, then:
The search replays the recorded attempts in order, without running them again, and runs only what's left. The time budget restarts with each run. Resuming refuses when:
- the frozen config, workload or manifest was edited;
- a candidate file was changed;
- the journal was changed;
- a recorded trace no longer matches its digest;
- the checkout moved to another commit.
agentloop session verify DIR runs the same checks without running anything.
Limits¶
- The runner runs on this machine as you, in temporary worktrees that aren't a
sandbox. It gets a minimal environment plus
env. - Only findings with a registered pass become candidates. Today that's the
memoize pass for repeated calls, plus explicit
config.json_setrequests you list underpasses. The report shows every other finding as unsupported. - The baseline runs each tuning task once. Timing noise is handled by the held-out pairs and the acceptance contract, not by the baseline.
- A recommendation describes these tasks on this machine. Review the diff, and measure again under your real load before relying on it.