A pattern language for working with agents
Each pattern is named, numbered and quoted from the people who published it or run it.
- Person
- Model call
- Agent
- Tool
- Code
- Context
People and agents
- 1Plan before codingHave the agent research and write a plan, and approve it yourself before it edits anything.
- 2Human approvalA person approves sensitive or irreversible actions before the agent takes them.
- 29Asynchronous coding agentHand a task to an agent that works unattended in the cloud and returns a pull request to review.
- 30Parallel agents in separate worktreesRun several agents at once, each in its own checkout, then review and merge each one.
- 33Checkpoint and rewindSnapshot the code before each agent turn, and go back to it when the agent goes off track.
Systems of agents
- 3Prompt chainingSplit a task into fixed steps; each call works on the output of the one before.
- 4RoutingClassify each input, then send it to the prompt, model or agent built for that kind.
- 5ParallelizationRun independent subtasks or repeated attempts at once, then combine the results.
- 6Orchestrator and workersA lead model splits a task as it goes, hands the parts to workers and combines their results.
- 7Evaluator and optimizerOne model writes, another judges against clear criteria, and the loop repeats until it passes.
- 8AdvisorA fast, cheap model does the work and asks a stronger model for guidance at hard moments.
- 9HandoffOne agent passes the conversation to another that specializes in what comes next.
- 13Subagent with its own context windowSend a side task to a subagent with a fresh context window; only its short summary comes back.
- 20GuardrailsScreen user input before the agent sees it, and its output and actions before they take effect.
- 26Plan-and-executeA planner model writes the whole plan, executors carry out the steps, and the planner replans.
- 32LLM cascadeA cheap model answers first; only answers that fail a confidence check go to a stronger model.
- 34Multi-agent debateHave agents argue over each other’s answers for several rounds, then let a judge settle the result.
- 37Dual LLMKeep untrusted text away from the model that can act; a second model with no tools reads it instead.
One agent
- 10Agent loopA model uses tools in a loop, deciding each next step from what the last one returned.
- 11ReflectionThe agent critiques its own output or past attempts, then tries again.
- 12CompactionWhen the context window fills, summarize the conversation and continue from the summary.
- 14Structured note-takingThe agent writes notes to a file outside its context window and reads them back later.
- 15Tool result clearingReplace old tool results in the history with a short placeholder once the agent has used them.
- 16Just-in-time context retrievalKeep file paths, queries and links in context; load the data with tools only when it is needed.
- 21SandboxingRun the agent inside set limits on files and network so it can act without asking each time.
- 22Code actionsThe agent writes code that calls its tools, and an interpreter runs it and returns the result.
- 27Todo listThe agent keeps a task list in its context and rewrites it as it works, so the goal stays in view.
- 28SkillsKeep each skill’s name and description in context; load its instructions only when a task needs it.
- 35Tool searchGive the agent a search over its tools, and load only the tool definitions a task needs.
One call
- 17LLM as a judgeOne model call grades another model’s output against written criteria.
- 18Retrieval-augmented generationOne retrieval step before the call: add passages relevant to the query to the prompt.
- 23Contextual retrievalBefore indexing, prepend to each chunk a short model-written note on where it sits in its document.
- 24RerankingRetrieve many candidates, then let a reranker keep only the most relevant few for the model.
- 25Query rewritingHave a model rewrite the user’s query, with the conversation so far, before searching with it.
- 36SpotlightingMark untrusted text inside the prompt so the model can tell it apart from your instructions.