Mahal Systems

AOT Library

Our AOT Library collects agent optimization strategies and the evidence behind them. Updated regularly.

Browse the library here, search for strategies to implement below, or plug it into your coding agent with the prompt in the left rail.

optimizations
61
61 complete, 0 in development
research papers
381
of 459 sources cited
benchmarks
61
named in the evidence
measured results
570
of 853 cited
results against
267
mixed or contradicting, kept in
last updated
Nov 10
released weekly

Search the library

Show me changes that for by changing , are of type , and mention .

61 optimizations

1Models

b.Finding specialists

  1. i.

    Match the model and its effort to each call site and query class

    Start each call site at a low reasoning effort and a model chosen on its own eval, instead of the top setting everywhere: on agentic coding tasks that every effort level solved, xhigh effort cost 2.5 to 5.3 times low effort, and on Terminal-Bench every one of eight models lost some tasks its lowest level had solved.

    Better qualityLower costFaster

    Tier 3 · tuning · changes model, prompt · any agent · 26 sources, 13 measured

2Tools

a.Refactoring

  1. i.

    Reduce the tool surface: remove and consolidate tools, then defer the rest behind search

    Give an agent only the tools its tasks need, and put the rest behind tool search once the catalog is large.

    Better qualityLower costMore secureMixed performance

    Tier 1 · hygiene · changes tool surface, context · tool use agents · 36 sources, 27 measured

  2. ii.

    Rewrite the tool surface: names, schemas, descriptions

    Rewrite each tool's name, parameters and description for the model, starting from the calls it gets wrong.

    Better qualityMore secureMixed costMixed performance

    Tier 1 · hygiene · changes tool surface · tool use agents · 22 sources, 12 measured

  3. iii.

    Choose how the agent acts: typed tools, code execution, or shell, matched to the model and task

    Choose the agent's action interface per model and task: typed tools, a shell, or code that calls tools.

    Lower costMixed qualityMixed performance

    Tier 3 · tuning · changes tool surface, model · tool use agents · 27 sources, 15 measured

b.Avoiding misuse

  1. i.

    Make tool calls and tool results fail soft, and retry transient failures

    Keep a failed call from ending the run: validate tool calls and model responses, return tool errors to the agent as results, and retry only failures that are transient and safe to repeat.

    Better qualityHigher cost

    Tier 2 · reliability · changes tool surface, control flow · tool use agents · 9 sources, 4 measured

  2. ii.

    Tell the agent when to use each tool, in context it always sees

    Write down when the agent should use each tool, and put it where the model always reads it.

    Better qualityBetter governanceMixed costMixed performance

    Tier 3 · tuning · changes tool surface, prompt · tool use agents · 13 sources, 8 measured

c.Trimming results

  1. i.

    Bound tool output: cap it, or write it to a file the agent can read

    Keep big tool results from flooding the context: return what fits whole, cut larger ones by whole lines or records and say so, and put the rest in a file the agent can read.

    Lower costMixed qualityMixed performance

    Tier 3 · tuning · changes tool surface, context · any agent · 12 sources, 5 measured

3Prompts

a.Structuring

  1. i.

    Add worked examples to the prompt (few-shot), or curated example queries for data agents

    Put a few solved examples of the task in the prompt (the input and the exact output wanted), or give a data agent commented example queries for its custom metrics and an index of past queries it retrieves per question.

    Mixed qualityHigher costSlower

    Tier 3 · tuning · changes prompt · any agent · 7 sources, 6 measured

  2. ii.

    Avoid few-shot ruts

    Keep the model from copying its own context: when it fills with near-identical steps or items, vary how new entries are written, label or describe repeats instead of replaying them, and give independent items their own context.

    Better governanceMixed qualityMixed costMixed performance

    Tier 3 · tuning · changes prompt · any agent · 17 sources, 12 measured

  3. iii.

    Dynamic context injection

    Tell the model the runtime facts it cannot know: today's date and timezone, the working directory, OS and git state, the tools available, the user and locale.

    More secureBetter for brandMixed quality

    Tier 3 · tuning · changes prompt, context · any agent · 13 sources, 8 measured

  4. iv.

    Restructure the system prompt: every requirement once, up front, in named sections; nothing the model doesn't need

    State each requirement once, in its own named section near the top of the system prompt, and cut what the model does not need.

    FasterMixed qualityMixed cost

    Tier 3 · tuning · changes prompt · any agent · 15 sources, 6 measured

b.Caching

  1. i.

    Keep the prompt prefix cache-stable

    Build each agent request as a byte-identical static prefix followed by an append-only history, so every turn reads the prompt cache instead of reprocessing it.

    Lower costFaster

    Tier 1 · hygiene · changes context · any agent · 13 sources, 5 measured

  2. ii.

    Mask tools instead of removing them

    Keep every tool defined for the whole session and change only which ones the agent may call.

    Lower costBetter governanceMixed qualityMixed performance

    Tier 3 · tuning · changes context, tool surface · any agent · 15 sources, 8 measured

c.Sizing reasoning effort

  1. i.

    Self-Discover reasoning structures

    Self-Discover has the model compose a reasoning structure once per task type (select useful modules from 39 seed heuristics, adapt them to the task, write them as a step-by-step plan), then follow that cached structure on every instance, so each instance costs one call.

    Mixed qualityHigher costSlower

    Tier 3 · tuning · changes model, prompt · reasoning agents · 11 sources, 9 measured

4Memory

b.Resuming

  1. i.

    Filesystem-based agent state and checkpoints

    Save the agent's state at each step boundary (the conversation, the workspace files, process state when it matters, and a ledger of external side effects) so a crashed or stuck run resumes or rolls back instead of starting over.

    Better qualityLower costMixed performance

    Tier 2 · reliability · changes state · any agent · 6 sources, 4 measured

  2. ii.

    Initializer-maintainer dual agent

    Give the first session of a multi-session build a setup-only prompt (expand the spec into a JSON list of end-to-end tests, all failing, and write an init script, a progress file and a first commit) and every later session a maintainer prompt that reads that state, re-tests what passed, builds one failing item, verifies it end to end and commits.

    Better qualityBetter governanceMixed costSlower

    Tier 4 · restructuring · changes state · planning, code generation agents · 6 sources, 1 measured

  3. iii.

    Keep plan, progress and results in files when work outlives one context window

    Keep a long task's plan, progress, decisions and large results in files, and start every new context window by reading them back.

    Better qualityLower costBetter governanceMixed performance

    Tier 4 · restructuring · changes state · planning agents · 20 sources, 14 measured

c.Reusing work

  1. i.

    Episodic memory retrieval

    Log every agent session as a raw trace, distill a few verified lessons from them (user corrections, definitions, workflows that worked, mistakes) into short memory files, show the agent an index of those files at the start of each task, and let it search both.

    Better for brandMixed qualityMixed costMixed performance

    Tier 4 · restructuring · changes state · memory agents · 9 sources, 7 measured

  2. ii.

    Skill library evolution

    Have the agent turn runs that passed a verifier into reusable skills (a code function or a SKILL.md procedure), store them in a library, and on later tasks show it only the few a separate selection step picks, reviewing what goes in and pruning what goes unused.

    Mixed qualityMixed costMixed performance

    Tier 4 · restructuring · changes state · memory agents · 6 sources, 4 measured

5Context

a.Compacting

  1. i.

    Compact conversation history in stages: elide stale tool outputs, then keep an anchored summary

    Clear old tool outputs, then summarize, only when the context window binds, and carry the task's rules and the last completed call forward verbatim, because summaries drop them.

    Better qualityLower costMixed performance

    Tier 2 · reliability · changes context · any agent · 26 sources, 12 measured

b.Filtering input

  1. i.

    Give the model the schema it queries, in context: descriptions, keys, codes, sample values

    Tell a SQL-writing agent what its data means, not only what it is called: what each column, code and NULL means and how each metric is computed, with keys and sample values.

    Better qualityMixed cost

    Tier 3 · tuning · changes knowledge access, context · data analysis agents · 8 sources, 6 measured

c.Isolating subtasks

  1. i.

    Discrete phase separation

    Run research, planning and implementation as separate agent sessions, each starting from a fresh context that holds only the previous phase's written output (a research document, then a plan file), and have a person review that document before the next phase starts.

    Mixed qualityMixed costSlower

    Tier 4 · restructuring · changes context · any agent · 6 sources, 3 measured

  2. ii.

    Sub-agent architectures with clean contexts

    Hand a context-heavy side task (code search, reading many files, documents or logs) to a sub-agent with a fresh context and only the tools it needs, and have it return a short result or file references so the parent's context stays small.

    Mixed qualityMixed costMixed performance

    Tier 4 · restructuring · changes context · any agent · 16 sources, 14 measured

6Topologies

a.Escalating

  1. i.

    Oracle-worker multi-model

    Let a cheap model do the work and call an expensive one only when a trigger fires: a cascade escalates when the cheap answer looks unreliable or fails a check, a router picks the model before the call, and an advisor tool lets a cheap agent consult a stronger model mid-task.

    Better governanceMixed qualityMixed costMixed performance

    Tier 4 · restructuring · changes model · any agent · 6 sources, 5 measured

b.Parallelizing

  1. i.

    Parallel tool execution for read-only calls

    Let the model put several independent read-only tool calls (searches, fetches, file reads) in one turn and have the harness run them at once, while calls that write, share state or need another call's result run one at a time in the order the model emitted them.

    Lower costFasterMixed quality

    Tier 3 · tuning · changes control flow · any agent · 6 sources, 3 measured

  2. ii.

    LLM map-reduce

    Give each piece of a large or untrusted input its own tool-less model call that sees only that piece and must answer in a fixed schema, then combine the answers in code or in a reducer that never sees the raw text.

    More secureBetter governanceMixed qualityMixed costMixed performance

    Tier 2 · reliability · changes control flow · any agent · 6 sources, 4 measured

  3. iii.

    Use multi-agent orchestration only for breadth-first, independent sub-tasks

    Fan work out to parallel sub-agents only when it splits into independent parts, and check that one agent given the same budget doesn't do as well.

    Mixed qualityMixed performanceHigher cost

    Tier 4 · restructuring · changes control flow, context · any agent · 28 sources, 13 measured

c.Separating privileges

  1. i.

    Code-then-execute (CaMeL)

    Have a privileged model turn the trusted request into a small program before any untrusted data is read, then run it in an interpreter that labels every value with where it came from and checks a per-tool policy before each call, so injected text can neither add actions nor send private data to the wrong place.

    More secureBetter governanceMixed costLower qualitySlower

    Tier 4 · restructuring · changes guardrails · any agent · 7 sources, 5 measured

  2. ii.

    Plan-then-execute

    Have the agent fix its tool calls (an ordered list or a dependency graph) from the trusted request before it reads any tool output, and let a controller execute only those calls, so injected text cannot add an action.

    More secureBetter governanceBetter for brandMixed qualityMixed costSlower

    Tier 4 · restructuring · changes guardrails, control flow · any agent · 6 sources, 4 measured

7Orchestration

a.Routing

  1. i.

    Route metric questions through a deterministic semantic layer; fall back to text-to-SQL

    Have a data agent answer metric questions by picking metrics and dimensions that a semantic layer compiles into SQL, and write SQL itself only when the layer can't answer.

    Better qualityBetter governanceMixed performanceHigher cost

    Tier 3 · tuning · changes control flow, knowledge access · data analysis agents · 16 sources, 15 measured

  2. ii.

    Prompt chaining with gate checks

    Split a cleanly decomposable task into a fixed chain of model calls with a code check between steps, and rerun only the step that fails.

    Better qualityMore secureBetter governanceBetter for brandMixed costMixed performance

    Tier 4 · restructuring · changes control flow · any agent · 15 sources, 12 measured

b.Bounding execution

  1. i.

    Detect stalls and loops: warn, then stop early

    When an agent repeats the same call and gets the same result, push it to change approach after a few repeats, and end the run only after a long streak of identical failures.

    Better governanceBetter for brandMixed qualityMixed costMixed performance

    Tier 2 · reliability · changes control flow · any agent · 17 sources, 7 measured

  2. ii.

    Keep errors in context

    Show the agent every failed action as a marked error it can read, with the next step it can take, instead of hiding it, and collapse the error once it is fixed.

    Better governanceBetter for brandMixed qualityMixed cost

    Tier 2 · reliability · changes control flow, context · any agent · 15 sources, 11 measured

  3. iii.

    Size run budgets so productive runs aren't cut off: turn caps, deadlines, command timeouts

    Set turn caps, deadlines and command timeouts from what your successful runs actually used, show the agent how much budget is left, and never run a command without a timeout.

    Mixed qualityMixed costMixed performance

    Tier 2 · reliability · changes control flow · any agent · 9 sources, 5 measured

  4. iv.

    Track explicit progress: a task list with a status per item, re-injected each turn

    Give the agent one tool that holds a task list (a status per item, one item in progress), require the list on the first turn of non-trivial tasks, and show the current list every turn instead of keeping old copies in history.

    Mixed qualityMixed costMixed performance

    Tier 3 · tuning · changes control flow, context · planning agents · 5 sources, 4 measured

c.Scaling compute

  1. i.

    Reflection loop

    The same model critiques and revises its own output for a few rounds (Self-Refine), or after a failed attempt writes a short lesson it carries into the next try (Reflexion).

    Better for brandMixed qualityHigher costSlower

    Tier 3 · tuning · changes control flow · any agent · 11 sources, 10 measured

  2. ii.

    Self-critique evaluator loop

    Train or tune the system's own judge from its own outputs and synthetic judgments (contrastive pairs with one side deliberately degraded, the judge's own verdicts kept only where they match the construction label) instead of human labels, then use it to score, select or train in the loop.

    Mixed qualityHigher cost

    Tier 3 · tuning · changes control flow · any agent · 11 sources, 10 measured

  3. iii.

    Evaluator-optimizer loop

    Have a separate, skeptical evaluator check each output against written criteria and send back specific findings, revising until it passes or a low round cap.

    Better governanceBetter for brandMixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · any agent · 21 sources, 19 measured

  4. iv.

    Graph-of-Thought

    Graph-of-Thought runs one task as a graph of model calls: split the input into parts, generate and score several candidates per part, keep the best, then merge the partial results and refine the merged answer.

    Mixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · reasoning agents · 9 sources, 7 measured

  5. v.

    Language Agent Tree Search (LATS)

    Language Agent Tree Search runs the agent as a Monte Carlo tree search over its own actions: sample several next actions, execute each in the environment, score the resulting states with the model, reflect on failed endings, and back the scores up the tree until a branch succeeds or the budget runs out.

    Mixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · reasoning, planning agents · 14 sources, 13 measured

  6. vi.

    Multi-agent debate

    Several model instances answer the same question, read each other's answers and revise over one or more rounds, and a vote or judge settles the final answer.

    Better governanceMixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · reasoning agents · 6 sources, 4 measured

  7. vii.

    Tree-of-Thought

    Tree-of-Thought replaces one reasoning chain with a search: the model proposes several next steps, an evaluator (the model itself, a trained verifier or a rule check) scores the partial solutions, and breadth-first or depth-first search keeps the best or backtracks.

    Mixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · reasoning agents · 11 sources, 9 measured

d.Shaping the loop

  1. i.

    Continuous autonomous task loop

    Run the coding agent from a shell or harness loop that starts a fresh headless session every iteration with the same short prompt; each session reads the plan, progress notes and git history, does one item, runs its tests, commits and exits, until an iteration cap, a budget or a stop rule ends the run.

    Mixed qualityMixed performanceHigher cost

    Tier 4 · restructuring · changes control flow · planning agents · 6 sources, 3 measured

  2. ii.

    Inversion of control

    Give the agent the goal, the tools and the acceptance checks and let it choose the sequence of steps, instead of coding a fixed workflow; the goal, permissions, budget and evaluation stay outside the agent.

    Mixed qualityHigher costSlower

    Tier 4 · restructuring · changes control flow · any agent · 6 sources, 4 measured

  3. iii.

    ReAct loop

    Run the agent as a loop: the model reasons, calls a tool, reads the result and picks the next step, until it answers or hits a cap.

    Better qualityMixed performanceHigher cost

    Tier 4 · restructuring · changes control flow · any agent · 15 sources, 13 measured

8Retrieval

a.Expanding sources

  1. i.

    Choose the retriever by corpus size and question type

    Match the retriever to the corpus: let the agent grep and read the raw files while the corpus is bounded, and put a retriever in front of grep once it grows.

    Better qualityLower costMixed performance

    Tier 3 · tuning · changes knowledge access, control flow · retrieval agents · 30 sources, 27 measured

  2. ii.

    Surface information the source holds but the agent cannot read

    Find what your agent's sources hold but its readers never pass on, and expose it: file formats and channels a converter drops (font color, highlight, comments, footnotes, PDF or spreadsheet content) and, in a warehouse, tables, joins and past queries the agent never reads.

    Better qualityHigher cost

    Tier 3 · tuning · changes knowledge access · retrieval, data analysis, document extraction agents · 15 sources, 7 measured

b.Querying precisely

  1. i.

    Tune the search tool: snippets, enough results, retries, reformulation, filters, source quality

    Make the search tool show the agent enough to choose what to open, give it a reader that keeps the pages it opens, and have the tool say plainly when it found nothing.

    Better governanceMixed qualityMixed cost

    Tier 2 · reliability · changes knowledge access · retrieval, web research agents · 12 sources, 7 measured

  2. ii.

    Link large schemas by exploration: start broad, grow the linked set with probing queries, favor recall

    When a database schema is too large to load whole, let the agent find the tables and columns each question needs by exploring it, instead of retrieving once up front.

    Mixed qualityMixed costSlower

    Tier 3 · tuning · changes knowledge access, control flow · data analysis agents · 16 sources, 13 measured

9Verification

a.Checking externally

  1. i.

    Feed back a sound external verifier's verdict; never the model's own critique

    Have the harness check every output with something the model cannot fool, such as tests, a compiler, a schema or policy check, execution or a solver, and send the verdict back for another try.

    Better qualityMore secureBetter governanceHigher costSlower

    Tier 2 · reliability · changes control flow · any agent · 34 sources, 20 measured

  2. ii.

    Verify citations claim by claim for factual support

    Check every citation in a research agent's report against the page it cites, and fix or drop what fails before the report goes out.

    Better qualityMixed costMixed performance

    Tier 3 · tuning · changes control flow, knowledge access · web research, retrieval agents · 12 sources, 9 measured

b.Confirming completion

  1. i.

    Make the final answer reliably extractable: state the format, extract robustly, force an answer at the limit

    Ask for the final answer in one marked place after the reasoning, extract it with a parser you have checked, and force an answer when a run hits its limit instead of returning nothing.

    Better qualityHigher cost

    Tier 2 · reliability · changes control flow, prompt · structured output agents · 8 sources, 4 measured

  2. ii.

    Triage false success with a cheap trained detector, not an LLM judge

    To catch agent runs that claim success but failed, rank finished runs with a small model trained on your own labeled runs and send the top of the ranking to human review, instead of asking an LLM judge that reads the agent's own claim.

    Better qualityLower costFaster

    Tier 2 · reliability · changes control flow · judging agents · 10 sources, 10 measured

  3. iii.

    Verify completion against the environment before the agent stops

    Before an agent stops, check its claim that it is done against evidence it cannot write (the environment's end state, tests it cannot edit, or a separate reviewer that runs the result) and send it back with what failed.

    Better qualityBetter governanceHigher costSlower

    Tier 2 · reliability · changes control flow · any agent · 28 sources, 15 measured

c.Sizing verification

  1. i.

    Drop ad-hoc test-writing prompts; tell test-heavy models not to write tests

    Telling a coding agent to write its own tests mostly buys cost, not fixes, so drop the instruction and tell test-heavy models not to.

    Lower costFaster

    Tier 3 · tuning · changes control flow · code generation agents · 8 sources, 4 measured

  2. ii.

    Spend extra samples before extra verification: parallel attempts with a vote or judge; verify only where it pays

    Run several independent attempts and pick the answer by vote before paying for a verifier.

    Better qualityHigher costSlower

    Tier 3 · tuning · changes control flow · any agent · 41 sources, 38 measured

  3. iii.

    Audit a verifier-gated cascade against a gold sample the verifier never sees

    Check a verifier-gated cascade against a small human-labeled sample the verifier never sees: the verifier's own numbers can hide most of the error.

    Better qualityBetter governanceHigher cost

    Tier 4 · restructuring · changes control flow, model · any agent · 17 sources, 17 measured

  4. iv.

    Write a fail-to-pass test before the fix, and harden it against wrong fixes

    Make a coding agent's test a real check: write it before any source edit, admit it only if it fails on the unpatched code, then harden it against plausible wrong fixes or have a separate strong model write it and hold it fixed while the agent repairs.

    Better qualityBetter governanceHigher costSlower

    Tier 3 · tuning · changes control flow · code generation agents · 7 sources, 4 measured

10Safety

a.Sandboxing

  1. i.

    Constrain what the agent can touch

    Limit what the agent can reach at the operating system, not in its prompt or tool wrappers.

    More secureMixed performanceLower qualityHigher cost

    Tier 2 · reliability · changes guardrails · any agent · 9 sources, 4 measured

b.Gating risky actions

  1. i.

    Gate irreversible actions: allow, ask or deny by side effect

    Sort every action the agent can take by its side effect (read, reversible write, irreversible or visible to others) and let it run, ask first, or block it by class.

    More secureMixed qualityHigher costSlower

    Tier 2 · reliability · changes guardrails · any agent · 13 sources, 4 measured

c.Containing data

  1. i.

    Contain sensitive data and untrusted input

    Treat everything the agent reads from tools, the web, repository files and skills as data, not instructions, and keep personal data out of the model's context.

    More secureBetter governanceMixed qualityHigher costSlower

    Tier 2 · reliability · changes guardrails · any agent · 8 sources, 4 measured

Before you go...

Build better agents, weekly

Our latest research, performance benchmarks, optimization strategies, and updates around AOT development.

One email a week, nothing else. Unsubscribe anytime.