Skip to module content
Module 01 ยท ~8 min

The Agentic Build Pattern

An agent is a control loop, not a personality.

Reading progress
0/5 ยท 0%

The big idea

๐Ÿ’กKey idea
Strip away the hype and every agent is five lines: plan โ†’ decide โ†’ call tool โ†’ observe โ†’ stop. Reviewing one means reviewing those five moves โ€” specifically tool contracts, idempotency, budgets, and what gets folded back into context. Frameworks, multi-agent topologies, 'planners' โ€” all of it is elaboration on those five lines.
Quick check
1 question ยท instant feedback
0/1
  1. You're reviewing a mutating tool call inside an agent loop. What's the non-negotiable?

Deep dive

3/3 open

Every agent, no matter how it's dressed up, runs some version of this:

``` state = plan(goal) while not done(state) and within_budget(state): action = decide(state) result = call_tool(action) state = observe(state, result) stop(reason = goal_met | budget_hit | timeout | error_floor) ```

That's it. When you read about frameworks, orchestrators, or planner-worker splits, you're reading about scaffolding built on top of this shape.

The practical implication: if your framework hides these five moves behind abstraction, your review surface hides with them. Know which line of your codebase maps to each step.

When you audit an agent, you're really checking four things โ€” everything else is noise.

**1. Tool contracts.** Each tool is a typed function: name, input schema, output schema, error modes, and whether it has side-effects. Your MCP server is exactly this contract layer. If the contract is ambiguous, the model will fill the gap with a guess.

**2. Idempotency of side-effects.** Every mutating tool needs an idempotency key (a client-generated request ID the server deduplicates on) or a check-then-act guard. Read-only tools get a pass. Anything that spends money does not.

**3. Budgets.** Hard ceilings on steps, tokens, wall-clock time, and dollar spend โ€” enforced in code, not in prompts. 'Please stop after 10 steps' is a suggestion. `if steps > 10: halt` is a control.

**4. The observe step.** What actually gets folded back into context is a designed artifact. Raw API dumps bury the signal. Over-summarised results hide the error the model needed to see. Neither end of that spectrum is safe by default.

Framework debates eat a lot of oxygen. Here's what the choice actually buys you:

**Graph-style (LangGraph-archetype)** works well for explicit state machines and human-approval interrupts. You get their state model and debugging surface โ€” and you take on their mental model too.

**Typed-agent (Pydantic AI-archetype)** suits a review-everything discipline: contracts as types, validation at the boundary, minimal magic. Good fit when you want to explain every moving part to a client.

**Crew/role frameworks** optimise for multi-agent role-play. Skip until you have a proven multi-agent need โ€” which is rarer than the marketing implies.

**SDK-direct** is roughly 150 lines you fully own. Often the right v1 for a consultant whose pitch is 'I can explain every line.'

One decision that does matter: all serious frameworks now speak MCP natively. Build your tools once and you can swap the loop harness freely. The dangerous decisions live in the tool surface, not the framework dropdown.

Quick check
1 question ยท instant feedback
0/1
  1. A client wants an agent to 'pull yesterday's spend and post to Slack every morning.' Best shape?

In the field

๐Ÿ”ฌWorked example
Task: 'Audit this ad account and propose (don't execute) budget reallocations.' Spec the loop before code โ€” Tool surface: get_campaigns, get_ad_performance(range), get_audience_breakdown (all read-only). propose_change(doc) writes to a proposals table, not the ads API โ€” the loop physically cannot spend money. Budgets: max 15 tool calls, 60s wall-clock, $0.50 model spend; on breach halt with budget_exhausted. Observe step: performance responses reduced to (campaign, spend, conversions, CPL, ฮ” vs prior period) before re-entering context; raw JSON stays in the trace. Stop condition: model calls finish(report) โ€” finishing is itself a tool call, so it appears in the trace and can be evaluated. The dangerous decision โ€” what the loop can do โ€” was made in code before the model saw a single token.
๐ŸšซWhen not to reach for it
If the workflow is enumerable in advance, it's a pipeline, not an agent. n8n will do it deterministically at a fraction of the cost with none of the review burden. The most common over-engineering failure in current client work is shipping an agent where a three-node workflow was the honest answer. A useful middle shape: a workflow with one agentic node โ€” deterministic everywhere determinism is available, one bounded LLM step where it isn't. Default to single-agent; multi-agent only for (a) context sharding when one window can't hold what's needed, or (b) genuinely different tool permissions per role (analyst vs executor as a security design, not an architecture fashion).
Quick check
1 question ยท instant feedback
0/1
  1. When is a second agent genuinely warranted?

Pitfalls & takeaways

Failure modes

  • Prompt-enforced safety. 'Never modify live campaigns' in the system prompt with a mutating tool still exposed. The tool surface is the security boundary; the prompt is a preference.
  • Non-idempotent retries. Timeout โ†’ framework retries โ†’ duplicate side-effect. Symptom: 'it created two of them, sometimes.'
  • Context flooding. Raw responses appended verbatim; by step 8 the model can't find its own plan. Symptom: quality degrades with loop length.
  • Silent budget absence. Works in the 3-step demo, spirals in production when a pathological account produces 200 steps.
  • Un-observable finishes. The loop 'just stops' with no reason code โ€” you can't tell goal-met from give-up in the logs.

Durable takeaways

  • Tool surface is the security boundary; prompts are preferences.
  • Mutating tools require idempotency keys or check-then-act guards.
  • Budgets live in code as four ceilings: steps, tokens, wall-clock, spend.
  • Every finish is a tool call so you can evaluate it in the trace.
Quick check
1 question ยท instant feedback
0/1
  1. The observe step in a loop is best thought of asโ€ฆ

Do the work

๐Ÿ‹๏ธProve you learned it

Write a one-page loop spec for an agent over your MCP โ€” without writing the loop: tool surface (read/write + idempotency notes per tool), observe-step reduction rules, all four budgets, stop conditions with reason codes. Then have an AI generate the loop from your spec and review the diff against the spec, line by line.

0 chars
๐Ÿ“ฆArtifact to produce
Agent-loop spec template (tool surface, observe rules, four budgets, stop conditions with reason codes)
Quick check
1 question ยท instant feedback
0/1
  1. You need to prevent the loop from ever mutating live ad campaigns. Best guarantee?