Claude Seekho

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

PointWorkflowAgent
ControlPath written in code in advanceThe LLM decides the path itself
PredictabilityHigherLower
WhenThe task is clearly definedOpen-ended, steps not known in advance
Cost / latencyLowerHigher

14.2 Building blocks ("Building effective agents")

PatternHow it worksExample
Augmented LLMLLM + retrieval + tools + memoryThe base of every pattern
Prompt chainingOutput A → input B, with checks (gates) in betweenOutline → check → full article
RoutingClassify the input and send it to the right handler/modelRefund vs tech support; easy → Haiku
ParallelizationSectioning (separate parts) or Voting (same task several times)Review different aspects of code
Orchestrator-workersA lead LLM splits the task, gives it to workers and combines the resultsMulti-file code change
Evaluator-optimizerOne LLM produces, another critiques, in a loopTranslation polish
Autonomous agentA loop with tools + environment feedbackClaude Code, research agent
Orchestrator-workers pattern
  1. 1.Orchestrator (Opus): plans and splits the task
  2. 2.Worker 1: read file A
  3. 3.Worker 2: read file B
  4. 4.Worker 3: run the tests
  5. 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

#ApproachHarness (loop)DeploymentWhen
1Manual loop (Messages API)You write itYou host itYou need full control
2Tool Runner (SDK)SDKYou host itCustom tools, no loop to write
3Claude Agent SDKClaude Code's harness + built-in toolsYou host itA files/bash agent on your own infra
4Managed Agents (beta)AnthropicAnthropic sandboxHosted, 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.