Skip to content

Agents FAQ

Short answers, with pointers to the code. New questions are added as they come up.

Basics

What is an agent pattern?

A known, reusable way to make an agent behave well on one specific problem, the same way "retry with backoff" is a pattern for network calls. This topic covers five, one lab each:

Pattern Problem it solves Lab
Plan, then act You want to see and check the steps before they run 02_plan_then_act.py
Self-check The answer has a wrong total or an invented ID 03_self_check.py
Memory "Add 20 helmets to that quote" 04_memory.py
Budgets and recovery Loops, flaky tools, runaway cost 05_budgets_and_recovery.py
Pause and resume A manager must approve the order, hours later 06_pause_and_resume.py

What is an agent, and how is it different from the llm-api loop?

  • The loop is the same: the model calls tools until it can answer (../llm-api/agent.py).
  • The input changes from a question to a goal with several steps the model works out itself.
  • The harness around the loop is new: saved state, a trace, budgets with stop reasons, safe retries, approval as a pause, checks before answering (agent/).
  • Rule of thumb: the model chooses the next step; your code owns everything else.

Didn't the MCP labs already do multi-step work? What's different here?

Yes: run_mcp_agent() in ../mcp-server/host.py was already a minimal agent, and the model chose its own steps there too. mcp-server was about where tools live (a server, a protocol). agents is about how the loop behaves when you leave it running.

mcp-server (run_mcp_agent) agents (agent.run)
Too many steps Returns the string "Stopped: too many steps." Named stop reason; turn, tool, time and repeat budgets
Approval input(): blocks one process Saved pause; approve later, in a new process (06)
Flaky tool One try, error to the model Retries if the tool is safe to repeat (05)
Memory None across questions Typed working memory plus trimmed history (04)
Wrong total or ID Goes to the buyer Checked in code; one fix, else held (03)
Record of the run Printed lines Saved state and trace (01)
Plan None (lab 04's server prompt fixed the steps) Optional JSON plan, reviewed in code (02)

Same tools, same MCP server; the difference is the harness around the loop.

Agent, workflow or chatbot: which do I need?

Who decides the steps Example
Chatbot Nobody: one model call per message FAQ answers from a prompt
Workflow Your code, fixed in advance; the model fills in parts RAG: search, then answer (../rag/04)
Agent The model, at run time, from tool results Quote, check credit, order if allowed (01)

Start with a workflow. Move to an agent only when the steps really depend on what the tools return.

When someone says "I wrote an agent", what have they usually built?

One of four things. Ask: who decides the next step, and what stops it going wrong?

What they built Who decides the steps Agent?
A saved prompt or custom GPT, no tools Nobody: one reply per message No: a configured chatbot
A no-code workflow with an LLM step (Zapier, n8n, Make) The person who drew the flow No: an automation
Instructions plus tools inside ChatGPT, Claude, Copilot Studio The model, inside the vendor's harness Yes, but they configured it; the vendor built the harness
Their own loop with budgets, approval, checks and a trace The model, inside their harness Yes (this folder)

The third is the common case now and is a real agent. The gap is usually the harness: what happens when it loops, a tool fails, or it is about to spend money.

What is ReAct?

"Reason + act": the model decides one step, acts, reads the result, and decides again. It's what run() does by default (01). Its strength is adapting to surprises; its weakness is that you only see the path afterwards. Plan-then-act (02) is the main alternative.

What exactly is the harness? Is it the tests?

No. The harness is the code that runs around every model call, at run time, in production. Tests check the harness; they aren't part of it.

Part Runs when Here
Model Each turn: picks the next tool or answers chat() inside run()
Harness Before and after each model call, every run run() in agent/loop.py and its helpers in agent/
Tests On your laptop or in CI, never in a live run test_agent.py (a fake model plays the model's part)

The model never sees the harness and can't skip it: budgets, loop check, approval gate, safe retries, working memory, the answer check and the trace. Most agent quality and safety lives here, not in the prompt. In LangGraph the harness is the graph plus its checkpointer.

Is a product like DeepSeek Harness or Claude Code the same kind of harness?

Yes, the same idea at product scale: the model plus the code around it that runs the loop. They add a UI, plugins, sandboxes, scheduling and tracing for general work. Our agent/ package is the small core for one domain: budgets, safe retries, approval as a saved pause, working memory and answer checks. Rule of thumb: buy a general harness for general work (coding, documents); build or own the harness where your business rules live (credit, pricing, order approval).

Building

How do I stop an agent from looping or running up cost?

  • Budget in agent/state.py: model turns, tool calls, seconds, and repeats of the same call with the same arguments.
  • Check budgets before running a batch of calls, not after (05, scenario D).
  • Give tools clear errors with a next step ("do not call it again; tell the buyer"). Vague errors cause retries by the model.
  • Every stop gets a named reason in state.stop_reason, and the partial work stays in state.facts.

When should a failed tool call be retried?

Only for transient failures (timeout, connection reset) and only on tools that are safe to repeat: reads, or writes marked idempotent. retry_safe() reads this from the MCP annotations, so create_quote and place_order are never retried (05, scenario C). Business errors ("unknown SKU", "credit exceeded") and a human's "no" are never retried. For writes that must retry, use an idempotency key.

What kinds of memory does an agent have?

Kind Lives in Here
Chat history The message list, trimmed when long state.messages, trim_history()
Working memory Typed state, captured by code from tool results state.facts (latest quote and order), memory_block()
Long-term memory A database keyed by customer, loaded per session Not built; see learn-agents.md

Facts the agent acts on (IDs, totals) belong in working memory, never only in chat history (04).

Why not let the model ask the buyer "shall I place the order?" instead of a gate?

  • The model can be talked into skipping the question; a gate in code can't.
  • The approver is often not the buyer: a sales manager, a credit controller.
  • The gate reads the server's annotations (destructiveHint), so new write tools are covered automatically.
  • Show the approver lines, prices and total, not just a quote ID (describe_call()).

Plan-then-act or ReAct?

ReAct for short tasks with cheap reads. Plan first when steps are many, slow, costly or need sign-off: the plan is JSON you can review, log or show a person before anything runs (review_plan()). Plans go stale, so re-plan when a step fails.

Can an LLM check the answer instead of code?

Yes ("LLM as judge"), but use code first: it's exact, fast, free and testable (check_grounded()). Use a model only for what code can't check: tone, completeness, policy wording. That's the rnr capstone (evals and guardrails).

Frameworks

Do I need LangGraph (or another framework)?

  • Not to learn, and not for a simple loop: agent/ is about 450 lines in 8 small files and you can see everything.
  • A framework helps when you need durable pauses and resumes, branching flows, streaming per step, several agents, or one shared way of building across teams.
  • It does not write your tools, approval rules, budgets or checks (07 reuses call_with_retry()).
  • Rule of thumb: hand-roll the first agent so the team understands the parts, then adopt a framework deliberately.

What does "the harness was open-sourced" mean?

  • The harness code (loop, tool handling, permissions, context management) became public. The model's weights did not: open harness, closed model.
  • The big story was Claude Code in March 2026. Its TypeScript source shipped by mistake in an npm package (a leak, not a deliberate release), and community rewrites such as Claw Code followed.
  • Harnesses that were open source from the start include opencode, OpenHands, deepagents and Pi.
  • What it shows: production harnesses do what agent/ does (loop, budgets, approval, memory, checks), plus sandboxing and context compaction.
  • Rule of thumb: the harness is becoming a commodity. Your edge is your tools, data, approval rules and evals.

LangGraph, CrewAI, OpenAI Agents SDK, Pydantic AI, Claude Agent SDK: how do they differ?

Framework Shape Good fit
LangGraph Explicit graph of nodes and edges, checkpointer Durable, branching flows with human approval
CrewAI Role-based agents ("researcher", "writer") Quick multi-agent prototypes
OpenAI Agents SDK Agents, handoffs, guardrails, tracing OpenAI-centred stacks
Pydantic AI Typed agents, dependency injection Python teams that want type safety
Claude Agent SDK The harness behind Claude Code: tools, MCP, context management Coding and file-heavy agents on Claude

Most of them can use MCP servers, so the tools you built in ../mcp-server carry over.

Was Claude Code's harness open-sourced? Which harnesses can I read?

Not open-sourced: leaked. On 31 March 2026 a source map shipped by mistake in the Claude Code npm package exposed its TypeScript source (about 1,900 files, 512,000 lines). Anthropic called it a packaging error, pulled the version and filed takedowns; the code is still proprietary, so don't copy from it. It held the CLI harness (tools, permissions, memory, feature flags), not model weights or customer data. Harnesses you can legally read and reuse are released under open licences: OpenAI Codex CLI, Google Gemini CLI, OpenHarness (HKUDS, MIT). Map what you read onto agent.py: same parts, at production scale.

What is the catch with LangGraph's interrupt()?

On resume, the node that called interrupt() runs again from the top. Anything before interrupt() runs twice, so never put a side effect there (approve() in lg_agent.py).

Will this work with Claude instead of qwen3:8b?

Yes. Set LLM_MODEL (for example anthropic/claude-haiku-5-5) and the harness calls it through the door; nothing in agent/ changes. A stronger model needs fewer fix attempts and plans better, but the harness rules stay the same.