What Are AI Agents? How LLM Agents Plan, Use Tools and Act
AI agents explained: the agent loop, tools, memory, planning, and how agents differ from chatbots and fixed workflows, with a minimal code example.
Published December 1, 2026
An AI agent is a system where a language model decides what to do next, takes actions through tools, observes the results, and repeats until a goal is met. A chatbot answers; an agent acts. That one difference, letting the model drive a loop, is behind coding agents, research assistants, support bots that resolve tickets and much of what people mean by "agentic AI".
The concept
The core is a loop. The application sends the model the goal, the conversation so far and a list of available tools with descriptions and input schemas. The model either answers or requests a tool call. The application executes the tool, appends the result to the conversation, and calls the model again. The loop ends when the model produces a final answer, hits a step limit, or needs a human.
Around that loop sit supporting pieces: tools (functions, APIs, MCP servers), memory (the conversation, plus longer-term stores such as notes or a vector database), and guardrails (permissions, validation, budgets, human approval). Anthropic's widely cited guidance distinguishes workflows, where code orchestrates LLM calls along predefined paths, from agents, where the model dynamically directs its own process. Use the simplest one that solves the problem.
How an agent works
- Send goal + context + tool definitions to the model
- Model returns either a final answer or tool calls
- Application executes tool calls (with permission checks)
- Append results to the conversation
- Repeat until done, out of budget, or a human is needed
Chatbot vs workflow vs agent
| Chatbot | Workflow | Agent | |
|---|---|---|---|
| Who decides next step | User | Your code | The model |
| Uses tools | Rarely | At fixed points | Dynamically |
| Predictability | High | High | Lower |
| Good for | Q&A | Known multi-step processes | Open-ended tasks with feedback |
| Example | FAQ assistant | Summarise → classify → route ticket | Fix a failing test suite |
A single agent turn
Practical examples
A minimal agent loop (Python, provider-agnostic sketch)
The structure is the same with any tool-calling model API.
def run_agent(goal: str, tools: dict, max_steps: int = 10) -> str:
messages = [{"role": "user", "content": goal}]
for _ in range(max_steps):
reply = llm.chat(messages=messages, tools=[t.schema for t in tools.values()])
messages.append(reply.message)
if not reply.tool_calls:
return reply.text # final answer
for call in reply.tool_calls:
result = tools[call.name].run(**call.arguments)
messages.append({"role": "tool", "tool_call_id": call.id, "content": str(result)})
return "Stopped: step limit reached"A good tool definition
Clear name, precise description and typed inputs make tool choice reliable.
{
"name": "search_orders",
"description": "Search customer orders by email or order ID. Returns at most 20 orders, newest first.",
"input_schema": {
"type": "object",
"properties": {
"email": {"type": "string", "description": "Customer email (exact match)"},
"order_id": {"type": "string"}
}
}
}Budget and safety limits
Agents need hard stops.
LIMITS = {"max_steps": 15, "max_tokens": 200_000, "max_cost_usd": 2.00, "wall_clock_s": 300}
REQUIRE_APPROVAL = {"send_email", "issue_refund", "delete_record"}Common mistakes
- Building an agent when a deterministic workflow would do.
- No step, token or cost limits, letting loops run away.
- Vague tool descriptions and overlapping tools.
- Letting agents take irreversible actions without approval.
Key takeaways
- An agent is a model driving a loop of tool calls toward a goal.
- Tools, memory and guardrails surround the loop.
- Prefer workflows for predictable processes; agents for open-ended ones.
- Always set budgets and approval gates.
FAQ
Do I need a framework to build agents?
No. A loop around a tool-calling API is enough to start. Frameworks help with tracing, memory and multi-agent orchestration later.
Why do agents fail?
Most failures come from missing context, poor tool design, no way to verify results, or tasks that are too vague.
How do agents relate to MCP?
MCP is a standard way to give agents tools. The agent loop calls tools; MCP is one way those tools are discovered and connected.