Agents and Agentic Patterns
An agent is a system in which an LLM uses tools in a loop and decides the next step by itself. Anthropic's advice: start simple — single call → workflow → agent, and add complexity only when needed.
14.1 Workflow vs Agent
| Point | Workflow | Agent |
|---|---|---|
| Control | Path written in code in advance | The LLM decides the path itself |
| Predictability | Higher | Lower |
| When | The task is clearly defined | Open-ended, steps not known in advance |
| Cost / latency | Lower | Higher |
14.2 Building blocks ("Building effective agents")
| Pattern | How it works | Example |
|---|---|---|
| Augmented LLM | LLM + retrieval + tools + memory | The base of every pattern |
| Prompt chaining | Output A → input B, with checks (gates) in between | Outline → check → full article |
| Routing | Classify the input and send it to the right handler/model | Refund vs tech support; easy → Haiku |
| Parallelization | Sectioning (separate parts) or Voting (same task several times) | Review different aspects of code |
| Orchestrator-workers | A lead LLM splits the task, gives it to workers and combines the results | Multi-file code change |
| Evaluator-optimizer | One LLM produces, another critiques, in a loop | Translation polish |
| Autonomous agent | A loop with tools + environment feedback | Claude Code, research agent |
- 1.Orchestrator (Opus): plans and splits the task
- 2.Worker 1: read file A
- 3.Worker 2: read file B
- 4.Worker 3: run the tests
- 5.Synthesizer: combines the results into the final answer
Workers keep their own context, the lead's context stays clean
14.3 4 ways to build an agent
| # | Approach | Harness (loop) | Deployment | When |
|---|---|---|---|---|
| 1 | Manual loop (Messages API) | You write it | You host it | You need full control |
| 2 | Tool Runner (SDK) | SDK | You host it | Custom tools, no loop to write |
| 3 | Claude Agent SDK | Claude Code's harness + built-in tools | You host it | A files/bash agent on your own infra |
| 4 | Managed Agents (beta) | Anthropic | Anthropic sandbox | Hosted, long-running, scheduled agents |
14.4 Claude Agent SDK
Claude Agent SDK essentially gives you Claude Code as a library: built-in tools (Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch), context management, hooks, subagents, permissions, MCP and sessions. Available in Python (claude-agent-sdk) and TypeScript (@anthropic-ai/claude-agent-sdk).
# pip install claude-agent-sdk
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
options = ClaudeAgentOptions(allowed_tools=["Read", "Grep", "Glob"])
async for msg in query(prompt="Find SQL injection risks in this repo", options=options):
print(msg)
asyncio.run(main())14.5 Managed Agents (Claude Platform)
- An Agent is a stored, versioned config (model, system prompt, tools, skills, MCP) — create it once, reuse it by ID.
- A Session is each run; every session gets its own container/workspace where bash, files and code run.
- Events arrive as a stream (SSE); you send messages and tool results.
- Extras: Vaults (secrets are not visible in the sandbox), scheduled deployments (cron), outcomes (iterate until graded against a rubric), multi-agent workflows, memory stores.
14.6 Agent design best practices
- Keep tools few and good; write each tool's description as if it were docs for a new engineer.
- Treat the context window as precious: write big output to a file and return a summary.
- For long tasks keep progress files / memory so work continues even after a context reset.
- Human-in-the-loop approval on destructive actions (delete, deploy, payment).
- Give a way to verify every change: tests, linters, screenshots.
- Build evals: measure both the agent's trajectories and the final outcome.