Learn: building AI agents
Two tracks. Design patterns are how you build an agent — prompt chaining, routing, reflection, multi-agent, and more. Operational practices are how you run it in production — evals, guardrails, reliability, observability, and cost control.
Design patterns
15 patternsAdapted from Antonio Gullí's Agentic Design Patterns — how to compose an agent.
Prompt chaining: decompose, verify each step
Prompt chaining splits a complex task into a fixed sequence of focused LLM steps, each feeding the next, with a deterministic check between them so one bad step can't poison the rest.
Routing: send each input to the right handler
Routing puts a thin classifier in front of your specialists — it inspects each input, picks the handler best suited to it, and dispatches without doing the work itself.
Parallelization: fan out independent work
Parallelization runs independent sub-tasks concurrently — split-and-merge for speed, or same-task-N-ways for accuracy — but only when no step depends on another's output.
Reflection: let the agent critique its own output
Reflection runs your agent twice — generate, then critique against explicit criteria and feed the fixes back — so a weak first draft becomes a stronger final answer.
Planning: make a plan before acting
Make the agent write an explicit, ordered plan before it acts, execute the steps, and replan when reality breaks the plan.
Multi-agent: split roles, coordinate the work
Break a hard job into specialized agents with narrow roles and separate context windows, then coordinate their work through an orchestrator or a structured exchange.
Memory: what the agent keeps between turns
An agent's memory has two layers — the short-term context window and a long-term store you retrieve from — and the skill is deciding what to keep, summarize, and forget.
Learning & adaptation: improve from feedback
Let the agent improve at runtime by storing scored outcomes and retrieving the wins as few-shot examples and the failures as warnings — no retraining required.
MCP: a standard port for tools and context
MCP is a standard client/server protocol that exposes tools, resources, and prompts to an agent, so you build an integration once and reuse it across every host.
Goal setting & monitoring: track progress to a target
Give the agent an explicit target plus a way to measure progress, so loops terminate on done, stuck, or off-track instead of wandering until they run out of tokens.
RAG: ground answers in retrieved knowledge
RAG fetches the most relevant chunks from your knowledge store and drops them into context, so the agent answers from retrieved facts with citations instead of guessing from training memory.
Inter-agent comms: how agents talk (A2A)
Inter-agent comms lets independent agents hand off work and share results through structured messages, a shared blackboard, or protocols like A2A.
Reasoning techniques: think before you answer
Reasoning techniques trade extra tokens for accuracy on hard problems — chain-of-thought, self-consistency voting, ReAct's think-act loop, and tree search — but only when the failure is reasoning, not facts.
Prioritization: decide what to do next
When an agent faces a pile of possible actions, score and order them by urgency, value, dependencies, and cost instead of just grabbing whatever came in first.
Exploration & discovery: search an open space
Exploration lets an agent attack open-ended problems by generating, testing, and pruning candidate paths, always balancing exploiting the best lead against trying something new.
Operational practices
6 topicsWhat it takes to run an agent in production — the swarm keeps relearning these the hard way.
Evals: gate on recall, not vibes
Make the metric deterministic before you trust any number. Gate releases on recall over a fixed must-handle set; keep the LLM judge off the gate.
Guardrails: hard gates vs soft dials
Validate what comes in, validate what goes out, and give the agent an explicit escalation path. Decide up front which checks block and which only nudge.
Tool design: narrow, described, idempotent
Tool selection is driven by descriptions, not names. Make tools single-purpose, describe them for the model, take structured args, and make writes safe to retry.
Reliability: centralize backoff, don't retry per call
Naive per-call retry makes 429s worse. Put one concurrency limiter in front of the pool, back the whole pool off on a retry-after, and add jitter.
Observability: log selection vs logic
You can't fix what you can't see. Log every tool-call block, separate selection failures from logic failures, and keep structured per-run logs.
Cost control: tier, cache, and cap fan-out
Most agent spend is avoidable. Route easy work to cheap models, cache repeated calls, set token budgets, and cap fan-out concurrency.
From the field
2 readsOutside write-ups, each distilled to one lesson. Links open the source.
Temporary accounts: let AI agents deploy without a signup
CloudflareDesign auth for agents, not humans — a short-lived token the agent mints itself (claimed to a real account later) beats an OAuth flow no background agent can click through.
How we built an internal data analytics agent
GitHubCurated, layered context — not a bigger model — made GitHub's Qubot both more accurate and ~3x faster. The context is the lever you actually control.
Ask the knowledge base
Stuck on evals, guardrails, or reliability? Ask in plain English — you'll get an instant AI answer grounded in the same agent-building topics above.