When is an agent the right abstraction?
An agent is a control loop around a model, tools and state. The model proposes a next action; the runtime decides whether that action is valid, executes it and provides the result. Engineering quality comes from making those boundaries explicit.
Start with a deterministic program when the decision rule is known. Add a language-model step when interpretation or generation helps. Use an agent when later steps truly depend on uncertain intermediate results. More autonomy adds more states to test and more ways to fail.
Workflow
The application chooses the sequence. Example: extract → validate → classify → queue. A failed validation has a known branch.
Agent
The system chooses among permitted steps based on observations. Example: investigate an exception using a bounded set of lookups.
Anthropic’s agent guidance emphasizes simple, composable patterns and distinguishes workflows from more dynamic agents. The examples in this course apply that distinction to a small operations system.
Take it with you. Use autonomy to solve a real branching problem, not to replace a straightforward condition.
How do you specify the job?
Write the task contract before the prompt. Define the trigger, accepted inputs, authoritative sources, allowed actions, output shape and stopping conditions. Include what the agent must do when a required value is unknown.
For a case-status assistant, success could be “return the latest verified status of the assigned case, with its source and timestamp.” That is narrower than “help the customer.” It gives both the runtime and the evaluator something to check.
Swipe or scroll the table on small screens.
| Field | Example |
|---|---|
| Scope | One authenticated organization and one assigned case. |
| Inputs | Case reference plus the user’s specific status question. |
| Tools | Read status; read related event history; prepare an internal draft. |
| Output | status, source_reference, observed_at, unresolved_fields. |
| Stop | Evidence is sufficient, permission is denied, or the work budget is reached. |
| Exclusions | No outbound message, account change or cross-organization search. |
A structured response is easier to validate than prose, but valid JSON can still contain wrong facts. Check the meaning as well as the shape. Keep a place for unknown values instead of forcing the model to invent a required field.
Take it with you. A good contract defines both a successful result and an honest incomplete result.
What makes a tool reliable?
A tool is an interface with a contract: arguments, permissions, side effects and result types. Small, specific tools are easier to constrain than a universal “run anything” function. Keep read operations separate from actions that change a system.
The runtime should validate the name and arguments before executing. Derive sensitive scope from the authenticated context rather than trusting a model-supplied organization identifier. Apply the same authorization checks to retrieval, caching and logging.
Trace one tool call
A fictional support agent needs the status of one assigned case. The model proposes; the application enforces.
- 01Propose
- 02Validate
- 03Execute
- 04Observe
- 05Stop
Return enough context for the agent to interpret the result: a source reference, observation time and typed failure reason. Avoid dumping large unrelated records into the prompt. If a tool is unavailable, describe the limitation instead of silently choosing a broader credential.
Take it with you. The tool boundary is where intent becomes an operation. Validate it before every execution.
What belongs in context and memory?
The context window is temporary working material. Persistent state belongs in an application store with access rules and retention. A chat transcript can help explain a run, but it should not be the only record of approvals, completed operations or case ownership.
Use retrieval to select relevant evidence. Attach its source, version and scope so the system can distinguish current policy from an old note. A cached answer must not cross organization or permission boundaries, and changing a source may invalidate a cached decision.
Working context
The current task, trusted instructions, a compact state summary and the evidence needed for this step. Remove irrelevant material deliberately.
Persistent state
Task status, source references, approved payload version, operation identifier, receipts and unresolved questions. Protect and version it.
Keep documents and tool outputs separate from instructions. A web page can contain words that look like a system command; that does not make it authoritative. Never let retrieved text expand the tool allowlist or rewrite the permission policy.
Memory updates also change future behavior. Separate factual notes from proposed operating rules, and review behavioral changes before promoting them into trusted instructions.
Take it with you. Remember evidence and state deliberately; do not promote arbitrary text into authority.
How do you enforce least privilege?
Give each role the smallest practical set of reads and writes for its job. The model’s request is untrusted input to the application, even when it sounds reasonable. A system prompt can explain the rules; it cannot replace authorization checks.
Define a separate release boundary for actions such as sending messages, changing records or moving money. An approval should identify the action, resource, recipient and payload version. Recheck authorization at execution time, because permissions and records can change while a draft waits.
Test the action boundary
A model proposes an outbound message. These checks belong in the application, not just the prompt.
In a real system, approval evidence comes from authenticated workflow state, not user-editable browser checkboxes. Bind the approval to a payload hash or immutable version and expire it when any consequential field changes.
Log the authorization decision and operation identifier. Keep secrets out of prompts and tool results; a model does not need to see a credential to ask a server-side integration to act.
Take it with you. Treat the prompt as guidance and the application as the authority boundary.
How does an agent survive interruption?
Persist progress at boundaries that let a new worker continue safely. Store what was planned, what was attempted and what was confirmed. If a process dies after a request leaves the machine, a replacement worker needs to reconcile that request before repeating it.
An idempotency key identifies one logical operation across retries. It helps only when the receiver or your own durable action ledger enforces it. Generating a new key on every retry defeats the purpose, and a local key alone cannot guarantee exactly-once behavior in a remote system.
Swipe or scroll the table on small screens.
| Outcome | Runtime action |
|---|---|
| Confirmed success | Record the receipt and do not repeat the completed action. |
| Confirmed temporary failure before action | Retry within the policy using the same logical operation identity. |
| Outcome unknown after dispatch | Reconcile with the destination or request human resolution. |
For a concrete treatment of request identity and duplicate side effects, see the Amazon Builders’ Library discussion of idempotent APIs.
Use bounded retries, backoff and an exception queue with an owner. Do not let a successful retry erase the original evidence. Recovery should preserve the history needed to understand why the action happened.
Take it with you. Durability is the ability to resume without losing state or duplicating side effects.
How do you keep an agent from wandering?
Set limits on steps, elapsed time, tool calls and cost before a run starts. Limit each call as well as the whole run. Without both levels, one slow dependency can consume the entire budget or a loop can repeatedly make cheap but useless calls.
Define useful stopping rules: the answer is supported, the task is outside scope, evidence cannot be obtained, or a limit has been reached. An incomplete result should include the remaining question and what was already tried.
Put a ceiling on the loop
More steps and more tools multiply the work. Change both limits.
Parallel tools can reduce elapsed time when they are independent, but they still consume capacity and require permission checks. Do not run dependent writes in parallel just because a framework allows it.
A second agent adds another context, handoff and failure surface. Add specialized workers only when the task benefits from a clear division of work. A reviewer model is useful feedback, not automatic proof that the first model is correct.
Take it with you. Every loop needs a stopping rule, a resource ceiling and a useful incomplete state.
How do you test the whole system?
Evaluate the task outcome and the path taken to reach it. A correct-looking answer produced through an unauthorized lookup is a failed run. A safe refusal can be a successful result when evidence or permission is missing.
Build a versioned set of ordinary and adversarial cases. Include malformed inputs, conflicting documents, prompt injection, permission changes, stale approvals, rate limits, timeouts and duplicate delivery. Define the expected behavior with the domain owner before tuning the agent.
- Unit-check deterministic validation, authorization and state transitions.
- Run end-to-end cases against controlled tool responses and inspect side effects.
- Score factual support, task completion, scope violations, latency and cost separately.
- Hold out examples from prompt tuning; rerun after model, tool or policy changes.
- Keep rollback and monitoring owners named for a limited production release.
NIST’s AI RMF 1.0 core is a voluntary reference for managing risk across a system’s lifecycle. Translate its high-level approach into concrete evidence and release decisions for your own task rather than treating a benchmark score as certification.
Take it with you. Test permissions, recovery and outcomes together. The model response is only one part of the system.
Write the contract for your first agent
Use these six deliverables as an implementation brief. Each should be reviewable before a real integration is enabled.
- One task contract with success, unknown and out-of-scope outcomes.
- An allowlisted tool catalog with schemas, scopes, deadlines and side effects.
- A durable state model with operation identifiers and external receipts.
- An approval policy tied to payload versions and authenticated reviewers.
- A resource budget, exception owner and recovery procedure.
- A representative evaluation set and release/rollback criteria.
Check your understanding
Choose one answer per question. You’ll see the explanation immediately. Use Reset quiz to try again; this is a learning exercise, not a certification.
Quiz answers are saved in this browser only. Labs reset when you reload.