| Agent | A system that uses a model to choose actions, call tools and iterate toward a goal. |
| Planner | The component that decomposes a goal into steps and decides the next action. |
| Tool | A typed function the agent can call, with defined inputs, outputs and permissions. |
| Stop condition | The rule that ends the loop: success, budget exhausted, or human hand-off. |
- The task needs several dependent steps and tool calls.
- The path to the answer is not known in advance.
- Work must continue across turns or sessions.
- 01Receive a goal and constraints (budget, allowed tools, success criteria).
- 02Plan the next action using the model and current state.
- 03Execute one tool call and observe the result.
- 04Update state and memory, then re-plan or stop.
Failed-order triage
- Context
- An operations team investigates why customer orders fail to fulfil.
- Problem
- Engineers manually search logs and order records for each incident.
- Approach
- Give an agent lookup and log-reading tools, explicit state, iteration limits and a human hand-off.
- Outcome
- A proposed root cause with a step-by-step audit trail.
Inventory replenishment across sessions
- Context
- A restock agent runs nightly and continues work the next day.
- Problem
- Context from the previous run is lost, so decisions are repeated.
- Approach
- Persist structured state with goals, observations and decisions between runs.
- Outcome
- The agent resumes where it stopped instead of restarting the analysis.
Minimal agent loop (conceptual)
type State = { goal: string; steps: string[]; observations: string[] };
async function runAgent(goal: string, tools: ToolRegistry) {
const state: State = { goal, steps: [], observations: [] };
for (let i = 0; i < MAX_ITERATIONS; i++) {
const action = await planNextAction(state, tools.describe());
if (action.type === "final") return action.answer;
const result = await tools.execute(action.tool, action.input);
state.steps.push(action.tool);
state.observations.push(JSON.stringify(result));
}
return escalateToHuman(state); // budget exhausted
}Keep planning, tool execution and stop/escalation logic separate so each can be tested and observed.
Incident triage agent with budgets
{
"goal": "Find the cause of a failed order and propose a fix",
"allowed_tools": ["lookup_order", "read_logs"],
"max_iterations": 12,
"step_budget": 20,
"stop": ["resolved", "needs_human"],
"state": { "observations": [], "decisions": [] }
}Pass state explicitly between steps and hand off to a human when the budget is exhausted — never guess a root cause.
Single loop
Up: Simple to build and debug
Down: Struggles with long, branching tasks
Hierarchical planner
Up: Handles complex goals
Down: More tokens, more failure modes
Unbounded iterations
Up: Can solve harder problems
Down: Cost and loop risk without strict budgets
| Option | Upside | Cost |
|---|---|---|
| Single loop | Simple to build and debug | Struggles with long, branching tasks |
| Hierarchical planner | Handles complex goals | More tokens, more failure modes |
| Unbounded iterations | Can solve harder problems | Cost and loop risk without strict budgets |
- Give every tool a narrow, typed contract and explicit permission scope.
- Cap iterations, tool calls and spend per run.
- Log each step with input, output and decision reason.
- Define what happens on low confidence: ask a human, not guess.
| Key | Typical value | Note |
|---|---|---|
| max_iterations | 10–30 | Hard stop for the loop. |
| allowed_tools | explicit list | Least privilege by default. |
| step_budget | per task | Prevents runaway cost. |
| Symptom | Cause | Fix |
|---|---|---|
| Agent loops forever | No goal check or iteration cap | Add explicit stop conditions and budgets. |
| Agent calls the wrong tool | Overlapping tool descriptions | Make tool contracts mutually exclusive and specific. |
Is an agent just a prompt in a loop?
The loop is necessary but not sufficient. Reliable agents add typed tools, state, budgets, logging and escalation.
Do agents need long-term memory?
Only if work spans sessions. Start with in-run state and add persistent memory when a real use case demands it.
More in Agents & agentic AI
Agentic patterns: ReAct, plan-and-execute, reflection
Three reusable reasoning patterns and how to choose between them for real workloads.
Multi-agent orchestration patterns
When to split work across agents, how they hand off, and how to avoid coordination overhead.
Agent frameworks compared
LangGraph, CrewAI, AutoGen and MCP-based composition — what each optimises for and where it fits.