Agent
A model in a loop: it picks a tool, reads the result, decides the next move, and keeps going until the goal is met or the budget runs out.
See it
What it is
An agent is a model in a while loop. Give it a goal, a set of tools, and a transcript of what has happened so far; it picks a tool, reads the result, decides the next move, and repeats until the goal is met or a budget runs out. The classic shape is ReAct (reason, then act, then observe), and coding agents like Claude Code are the same loop with a shell, a file editor, and a search tool bolted on.
The dividing line worth holding: a workflow is control flow you wrote, an agent is control flow the model decides at runtime. If you can draw the flowchart, build the workflow instead. It is cheaper, faster, testable, and it fails in ways you can read. Agents earn their cost only when the number and order of steps genuinely cannot be known in advance, like debugging or open-ended research.
Gotcha: errors compound and context grows. Twenty steps at 95 percent per-step reliability lands near 36 percent end to end, and every step re-sends the whole transcript, so token cost climbs quadratically while the useful signal gets buried. Cap the iterations, summarize or prune old steps, hand long side quests to a subagent with its own context, and require human approval before anything irreversible.
Ask AI for it
Build an agent loop for this task instead of a single model call. Structure it as: a system prompt stating the goal and the stopping condition, a tool set of search, read_file, and write_file, and a loop that calls the model, executes any tool calls, appends the results to the transcript, and calls again until the model returns a final answer. Add hard limits: max 15 iterations, plus a transcript ceiling derived from the selected model's context window rather than a fixed number, and a summarize step that compacts older turns once usage passes half that window. Log what is actually observable so a run can be replayed: the model's response text, every tool call with its arguments, the tool result, the stop reason, and any summary the model wrote itself. Do not require raw private reasoning, since providers usually do not return it. Require an explicit user confirmation before any write or delete, and return a clear failure with the partial work when a limit is hit rather than looping again.