"Agent" has become one of the most stretched words in technology. It gets attached to chatbots, workflow tools, and anything with an LLM inside. That makes it hard to decide when you actually need one.
A useful, practical definition is narrower: an agentic system is one where a language model decides which actions to take, observes the results, and keeps going until the task is done. The model is not only writing text. It is choosing the next step.
The core loop
Strip away the frameworks and every agent looks roughly the same:
- Send the model a task and a list of tools it may use.
- The model either answers, or asks to call one or more tools.
- Your code runs those tools and sends the results back.
- Repeat until the model answers without asking for a tool, or a limit is reached.
The model never runs anything itself. It produces a structured request, such as "call search_docs with this query", and your code stays in charge of execution. That boundary is where most of the safety and reliability work happens.
A minimal loop in Python
Here is the whole idea in a few dozen lines, using the Anthropic Python SDK. The tool is deliberately simple: a lookup in a small in-memory knowledge base.
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
KNOWLEDGE = {
"refund policy": "Refunds are available within 30 days with a receipt.",
"support hours": "Support is available Monday to Friday, 9:00 to 17:00.",
}
tools = [
{
"name": "lookup",
"description": "Look up a topic in the company knowledge base.",
"input_schema": {
"type": "object",
"properties": {"topic": {"type": "string"}},
"required": ["topic"],
},
}
]
def run_tool(name: str, tool_input: dict) -> tuple[str, bool]:
"""Return (result, is_error)."""
if name == "lookup":
topic = tool_input.get("topic", "").lower()
if topic in KNOWLEDGE:
return KNOWLEDGE[topic], False
return f"No entry found for '{topic}'.", True
return f"Unknown tool: {name}", True
question = "When can I get a refund, and when is support open?"
messages = [{"role": "user", "content": question}]
for step in range(10): # hard limit: never loop forever
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=16000,
tools=tools,
messages=messages,
)
if response.stop_reason in ("end_turn", "refusal", "max_tokens"):
break
# Keep the model's full turn, including its tool requests
messages.append({"role": "assistant", "content": response.content})
results = []
for block in response.content:
if block.type == "tool_use":
output, is_error = run_tool(block.name, block.input)
results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": output,
"is_error": is_error,
})
# Return every result in a single user message
messages.append({"role": "user", "content": results})
print(next((b.text for b in response.content if b.type == "text"), ""))A few details in this loop matter more than they look:
- The step limit. Without it, a confused model and a failing tool can loop indefinitely, and every iteration costs money.
- Errors go back to the model. A failed lookup is returned with
is_error, so the model can try a different topic instead of the program crashing. - All results in one message. When the model requests several tools at once, send every result back together.
- Checking why it stopped. A response can end because the task is done, because the model declined, or because it ran out of output tokens. Treat those differently.
Agent, workflow, or single call?
Not every AI feature needs an agent. A helpful way to choose:
| Approach | Who decides the steps | Good for |
|---|---|---|
| Single model call | Nobody: one request, one answer | Summaries, classification, extraction |
| Workflow | Your code, in a fixed order | Repeatable pipelines with known steps |
| Agent | The model, at run time | Open-ended tasks where the path is not known in advance |
If you can write the steps down in advance, a workflow is usually cheaper, faster, and easier to test. Reach for an agent when the task genuinely needs exploration, such as researching a question across several sources or working through a problem whose next step depends on what was just found.
Guardrails worth adding early
Agents fail in different ways from ordinary software, so a few habits pay off from the first prototype:
- Keep tools narrow. A tool that can only read one table is far safer than one that runs arbitrary SQL.
- Require approval for side effects. Let the agent draft the email or the database change, and let a person confirm it.
- Log every step. Store each tool call and result. When something goes wrong, the transcript is how you find out why.
- Set budgets. Limit steps, tokens, and time per task.
- Validate tool inputs. Treat the model's tool arguments like any other untrusted input.
Takeaways
An agent is a loop, not a product category. It earns its place when the steps cannot be known ahead of time, and it needs the same engineering discipline as any other system: clear boundaries, limits, logging, and human checkpoints where actions matter.
Start with the simplest approach that works. If that turns out to be an agent, build the loop small, make every step visible, and expand its tools only as trust is earned.