Definition
An agent perceives an environment and selects actions in it. A simple agent can use fixed rules. An LLM-based assistant can use a language model to choose an allowed tool, observe its result and decide what to do next. Its designer defines permissions, a stopping condition and what requires human approval.
In simple words
A chatbot answers. An agent gets things done. Ask a chatbot about flights and it describes them. Ask an agent to book the cheapest flight on Friday and it searches, compares, checks your calendar and books, deciding each step as it goes.
Overview
- An AI agent is a system that uses an LLM to decide on actions, take them with tools and repeat until a goal is reached.
- The core loop is: think, act (call a tool), observe the result, and decide what to do next.
- Tools can be web search, code execution, databases, calendars or other APIs.
- ReAct (Yao et al., 2022) popularised interleaving reasoning and actions.
- Agents can complete multi-step tasks but can also make compounding errors.
- Good agents have limited permissions, step limits, logging and human approval for risky actions.
Why it matters
Agents let LLMs do real work: writing and running code, handling support tickets, researching and filing reports. They also add risk, because a mistake becomes an action. A wrong sentence is annoying, while a wrong payment is a real loss. So safety and limits matter here more than anywhere.
Key terms
- AI agent
- A system that pursues a goal by choosing actions and using tools in a loop.
- Tool
- A function the model can call, such as search, a calculator or sending an email.
- Function calling
- The model outputting a structured request to run a tool with specific arguments.
- Agent loop
- Observe, think, act, observe the result, repeat until done.
- Memory
- Information the agent keeps across steps or sessions.
- Human in the loop
- Requiring a person's approval before risky actions.
Types
AI agents come in several types, from simple tool users to teams of agents.
1. Tool-using (single-step) agents
An LLM that can call one or a few tools to answer a request.
- How it works: The model decides whether a tool is needed, calls it with arguments and uses the result in its reply.
- Example: A chatbot calling a weather API before answering "Will it rain in Kolkata tomorrow?".
- When to use it: Use them when answers need live data or a calculation; they are the easiest agents to build safely.
2. ReAct (reason-and-act) agents
Agents that alternate between reasoning steps and tool calls in a loop.
- How it works: At each step the model writes its thinking, chooses an action, reads the observation and continues until it can answer or hits a step limit.
- Example: Researching a question by searching, reading a page, searching again and then summarising.
- When to use it: Use them for open-ended tasks with an unknown number of steps.
3. Planning (plan-and-execute) agents
Agents that first write a plan and then carry out the steps.
- How it works: A planner breaks the goal into sub-tasks; an executor completes each; the plan is revised when a step fails.
- Example: Organising a trip: find trains, compare hotels within budget, then draft an itinerary.
- When to use it: Use them for long tasks where order matters and progress must be tracked.
4. Coding and computer-use agents
Agents that write and run code or operate software interfaces.
- How it works: They read files, edit code, run tests and fix errors; computer-use agents click and type in applications using screenshots.
- Example: An agent fixing a failing unit test by reading the error, editing a function and rerunning tests.
- When to use it: Use them in sandboxes with review, because they can change files and systems.
5. Multi-agent systems
Several agents with different roles working together.
- How it works: A manager agent assigns tasks to specialists such as a researcher, writer and reviewer, and combines their outputs.
- Example: One agent drafts a report, another checks facts, a third edits for tone.
- When to use it: Use them for complex workflows, watching for higher cost and harder debugging.
Explained in detail
From answering to acting
A chatbot answers a question and stops. An agent is given a goal, such as "find three affordable flights to Goa next Friday and draft an email to my team with the options", and works out the steps itself. It might search flight sites, compare prices, check the team calendar and write the draft, deciding after each step what to do next based on what it found. Classical AI has studied agents for decades, as systems that perceive an environment and act to achieve goals. What is new is using a large language model as the decision-maker, with tools giving it access to the world.
The agent loop
| Step | What happens | Example |
|---|---|---|
| Goal | The user states what they want | "Summarise this week's sales and email the summary to Priya" |
| Think | The model plans the next action | "First I need the sales data" |
| Act | It calls a tool with arguments | query_database("sales", week=46) |
| Observe | The tool's result is added to its context | A table of 120 sales rows |
| Repeat | It decides the next step | Compute totals, then call send_email |
| Finish | It reports back when the goal is met | "Sent. Total sales were ₹4.2 lakh." |
Risks and safeguards
- Errors compound: a small mistake in step two can derail every step after it, so long tasks fail more often.
- Real actions have real consequences: deleting files, sending emails or spending money cannot always be undone.
- Prompt injection: text on a web page or in a document can contain hidden instructions that try to hijack the agent.
- Safeguards include giving agents only the permissions they need, requiring human approval for risky actions, logging every step and setting limits on time and cost.
Agents are useful when a task needs several steps, information from several places and decisions along the way. For a simple, single question, a plain LLM call or a fixed workflow is cheaper and more predictable. As with every AI tool, the right question is not "can an agent do this?" but "should it, with what limits, and who checks the result?"
How it works
The agent loop
- Think: given the goal and what has happened so far, what's next?
- Act: call a tool, such as search or a calculator.
- Observe: read what the tool returned.
- Repeat until finished, or until a limit is reached.
| Chatbot | Workflow | Agent | |
|---|---|---|---|
| Who decides the steps? | No steps, only a reply | A developer, in advance | The model, while running |
| Takes actions? | No | Yes, fixed ones | Yes, chosen by it |
| Predictable? | Fairly | Very | Least |
In code
The loop without a real LLM: a stand-in "model" chooses tools. A real agent gets each decision from an LLM, but the loop looks like this.
def calculator(expression):
return eval(expression, {"__builtins__": {}}) # never do this with untrusted input
def get_price(item):
return {"pen": 10, "notebook": 40}[item]
TOOLS = {"calculator": calculator, "get_price": get_price}
def fake_model(history):
if len(history) == 0:
return ("get_price", "pen")
if len(history) == 1:
return ("get_price", "notebook")
if len(history) == 2:
return ("calculator", f"2 * {history[0]} + 3 * {history[1]}")
return ("finish", f"The bill is Rs {history[2]}")
history = []
for step in range(5): # always limit the steps
action, argument = fake_model(history)
if action == "finish":
print(argument)
break
result = TOOLS[action](argument)
print(f"Step {step + 1}: {action}({argument!r}) -> {result}")
history.append(result)Output
Step 1: get_price('pen') -> 10
Step 2: get_price('notebook') -> 40
Step 3: calculator('2 * 10 + 3 * 40') -> 140
The bill is Rs 140Common mistakes
- Giving an agent more access than it needs, such as write access to production.
- Letting it loop forever. Always set limits on steps and spending.
- Skipping tests because it worked in a demo. Agents fail in surprising ways.
Check yourself
Summary
- An agent pursues a goal in a loop: think, act, observe.
- Use a fixed workflow when you can, and an agent when you must.
- Limit its permissions and steps, and require approval for risky actions.
Finished reading?
Sources: Poole and Mackworth, Agent Architectures and Hierarchical Control