FOUNDATIONS · 5 MIN READ
What actually makes an AI agent an agent?
Start with the loop: observe, decide, act, and check what happened.
Jump to a section 10 sections
EXAMPLE USE CASE
Answer an order question using evidence
A support assistant must look up an order before answering, rather than guess from the question.
- Input
- Customer asks for A104. A read-only fixture contains A104 = packed.
- Expected output
- One lookup observation, followed by an answer containing packed.
- Success check: The answer is produced only after the lookup; the loop stops within three turns.
- Try a failure: Change A104 to A999. The result must be not_found, with no invented delivery date.
Example scope: A runnable local control-loop lab. The decision is deterministic; the linked SDK example replaces it with a model.
Identify the goal, authenticated user, and evidence already available.
goalTo 02 · DecideThe decision produces an answer or a request for one allowed tool.
tool callTo 03 · AuthorizeApplication code checks the tool name, argument schema, identity, and resource scope.
allowedTo 04 · ActFor A104, read the authoritative order status and return a structured observation.
observationTo 05 · CheckConfirm that the lookup succeeded. Missing data and timeouts require different next steps.
evidenceTo 06 · Answer or continueAnswer from the returned status, or take another bounded step if evidence is incomplete.
if incompleteBack to 02 · Decide
The decision produces an answer or a request for one allowed tool.
A model inside a loop
- An agent receives a goal, observes the available information, chooses an action, and uses the result to decide what to do next.
- A language model can help choose the action.
- Your application supplies the tools, permissions, state, and stopping rules.
- Imagine a support assistant asked to check an order.
- It may identify the order number, call a lookup tool, inspect the returned status, and then answer.
- The action produces new evidence that changes the next step.
Start with a clear boundary
- Define what the agent can read, what it can change, and when a person must review the result.
- A tool description tells the model how a capability works.
- Server-side code decides whether a requested operation is allowed.
Pick a task you can measure
- Choose one task with observable success: returning the correct order status, identifying a missing field, or producing a grounded summary.
- Collect representative examples and check the result against the source data.
- A useful first system has a small tool inventory, a turn limit, explicit error handling, and a result that someone can inspect.
Set up the lab
- Use a new working directory for this example.
python3 -m venv .venv
source .venv/bin/activateImplement the example
Save as loop.py
orders = {"A104": "packed"}
observations = []
for turn in range(3):
# This deterministic decision function makes the loop visible.
# A model can later replace this decision, within the same boundary.
if not observations:
action = {"tool": "lookup_order", "order_id": "A104"}
assert action["tool"] == "lookup_order"
observations.append(orders.get(action["order_id"], "not_found"))
print("TOOL", action, "RESULT", observations[-1])
else:
print("ANSWER", observations[-1])
break
else:
raise RuntimeError("Turn budget exhausted")Run and verify
python loop.py- One lookup runs before the answer; the answer is
packed. - Change A104 to an unknown order: the answer must become
not_found, without an invented delivery date.
Troubleshooting and failure tests
- An answer before the lookup has no tool evidence. Preserve the observation in state.
- An agent that keeps searching needs a turn budget and an explicit stop condition.
Before production
- Replace the decision function with one SDK tutorial, retaining the tool allowlist.
- Authenticate the user before the lookup and record the authoritative result, latency, and stop reason.