Field guide · Agents
Agents: write down what it may and may not do
You ask an agent to “handle the ticket”. It looks up the order, changes the address and sends an email. In a demo that looks smart. In production the questions arrive: who allowed the address change, who owns the mistake, and can we replay it? Write the task, permissions, state and stop conditions before talking about multi-agent systems.
- An agent is model + tools + state + loop + permissions. Miss one and it is not one.
- Start with one job, one owner and one definition of done.
- Being able to call a tool is not permission to call it. Grant each tool separately.
The full guide starts below. Use the tables for reference; you do not need to memorise them.
Take one concrete job: pull 20 tickets a day, decide whether to refund, draft a reply, but require a human click before sending. The flow must stop, be auditable and replayable.
1 · Five parts: model, tools, state, loop, permissions
The model proposes the next step, tools change the outside world, state remembers what happened, the control loop decides whether to continue or stop, and permissions decide which actions are forbidden. Remove one and the agent collapses into a chatbot that calls functions.
Permissions are the most overlooked part. A model may think about anything, but the system may only let it do explicitly authorised actions. Writing permissions in a prompt is not permission; they must be enforced by runtime code, an identity system or an approval flow.
| Part | Question | Common failure |
|---|---|---|
| Model | What next | Talks but does not stop |
| Tools | How to change the outside world | Wrong arguments, excessive permission, untrusted returns |
| State | What happened before | Stale state or no state at all |
| Loop | When to continue, retry or stop | Infinite loops, duplicate writes, runaway cost |
| Permissions | Which actions are forbidden | Prompt-level constraints bypassed |
2 · Task boundary: one job, one owner, one definition of done
A shippable agent should have a task describable in one sentence: what it reads, what it does, what it produces and when it stops. The broader the task, the harder it is to know whether it is done and to limit side effects.
Every task needs a human owner. The owner is not the person you call after something breaks; they define done criteria in advance, approve irreversible actions and decide when to stop. An agent without an owner produces blame, not accountability.
List irreversible actions separately: sending externally, paying, deleting, publishing, changing permissions, touching production data. By default these require human confirmation. If they must be automated, they need limits, allowlists, rollback and audit.
3 · Tools and permissions: can call does not mean should call
The vaguer the tool definition, the more likely the model fills in wrong arguments. Each tool should state what it does, its input, its output, its failure return, whether it is idempotent and whether it has side effects. Tools should reject invalid arguments instead of guessing and continuing.
Grant permissions by identity × action × object × scope. For the same agent, reading a knowledge base and sending external email are different permissions; reading one project and reading all projects are different too. Narrow tool permissions is far more effective than writing “do not misbehave” in a prompt.
MCP servers, plugins and third-party tools are also supply chain. Pin versions, verify sources, limit network and file access, keep an inventory — it is no different from adding a dependency. More tools mean more attack surface. Connect one tool you truly need before ten you might need later.
4 · State and memory: replay first, long-term memory later
State is not stuffing the whole chat history into context. Separate at least: temporary state for this task, long-term memory across tasks, and the real state of external systems. Mix them and the agent treats old conclusions as current and guesses as facts.
Build replay first: record each step’s input, model output, tool call, tool return, approval and final result. Replay is not for “looking at logs”; it is for identifying which step failed and whether the same input reproduces. Without replay, evaluation and audit are impossible.
Long-term memory needs write rules, expiry rules and deletion rules. Decide what is worth remembering, for how long, who can read it and how to correct it before writing. Permanently vectorising every conversation is expensive and freezes mistakes.
5 · Control loop: continuing, retrying and stopping all need limits
A healthy loop has at least four gates: maximum steps, maximum duration, maximum cost and maximum retries. Without limits, a loop keeps retrying when a tool fails repeatedly, or burns budget while the model “checks once more”.
Distinguish retryable from non-retryable failures. Network timeouts can be retried; invalid arguments, permission denials and missing objects usually should not. Write actions must be idempotent: repeating the same action must not create two emails, two payments or two records.
Stop conditions must be explicit: task done, limit reached, human approval needed, safety violation, or insufficient evidence. The most dangerous state is not “cannot do it” but “does not know it should stop”.
6 · Evaluation: task, trajectory, tools and safety, not just the final sentence
Agent evaluation cannot look only at the final answer. Record at least: whether the task was completed, whether the steps were reasonable, whether tool calls were correct, whether permissions were exceeded, the cost, and whether it exited safely on failure. An agent with a plausible answer that read data it should not have read has not passed.
Start with a fixed task set: same tasks, same tools, same environment, same budget, repeated. Include normal, edge, failure and adversarial inputs. Testing only happy paths guarantees trouble on abnormal inputs after launch.
Run in shadow mode before launch: let the agent process real inputs without side effects and record what it would do. Compare with human results across four buckets — would do right, would do wrong, would exceed permission, would get stuck — then decide how much authority to grant.
7 · Failure branches: make the system able to stop
Agent failures are often not a wrong sentence but a wrong action. Grade failure branches by side effect: read-only can retry, writes need check-then-compensate, irreversible actions need a human.
| Failure | First action | Do not |
|---|---|---|
| Tool error | Classify: retryable / not | Retry blindly to the limit |
| Repeated loop | Stop, record the trace, return to the previous step | Add more prompt text to make it “smarter” |
| Partial write | Check real state, compensate or roll back | Assume the first write failed |
| Prompt injection | Separate content from instructions, reduce privilege, review | Treat web content as system instructions |
| Runaway cost | Trigger the budget gate, stop and report | Finish first and count later |
8 · A minimum path to deployment
Start with one read-only, single-task, replayable process. After it is stable, add tools, write permissions and automation one at a time. Every added capability must rerun the same task set.
- Write the task, input, output, done criteria and irreversible actions.
- Connect one necessary tool; define arguments, returns, failures and idempotency.
- Enforce permissions in the runtime, not in the prompt.
- Record every step; make replay possible first.
- Add four gates: steps, duration, cost, retries.
- Test normal, edge, failure and adversarial inputs on a fixed task set.
- Run in shadow mode; compare with human results and permission-violation rate.
- Grant authority gradually; keep human approval and a stop button.
Sources and further reading
These links are for checking facts, licences and official scope. External pages may change; cite the original text and check date.
- Tools · Service agent playbookSteps for a service agent from task boundary to launch.
- Tools · GuardrailsLayers of input, output, tool and runtime guardrails.
- Tools · Agent memoryBoundaries between short-term state, long-term memory and retrieval.
- Tools · OrchestrationChoosing single-agent, workflow or multi-agent.
- Tools · Failure libraryCommon failure modes and triage order.
- Models · Agent evaluationTask, trajectory, tool and safety evaluation.
- OSS · Agent frameworksAgent framework repositories and licences.
- Learn · Workflow orchestrationConcept page on orchestration, state and recovery.
Next
If you get stuck while following it, go back to the matching route instead of rereading the whole guide.