AnyLearn
All lessons
AIintermediate

Agentic AI: from chatbots to tool-using agents

What separates an agent from a plain chatbot, the perceive-think-act loop they all share, and how to design one that doesn't loop forever or burn through your token budget.

Not signed in โ€” your progress and quiz score won't be saved.
Lesson progress1 / 10

What makes an AI "agentic"

A chatbot answers. An agent acts. The line is the ability to call tools (functions, APIs, shells) and then react to whatever those tools returned โ€” usually in a loop, with the model deciding when to stop.

Concretely: an agent is an LLM wrapped in a control flow that lets it (a) read its current state, (b) propose a next action, (c) execute that action, (d) observe the result, and (e) decide whether to go again. Everything else โ€” memory, planning, multiple agents talking โ€” is layered on top of that core loop.

Full lesson text

All 10 steps on one page โ€” for reading, reference, and search.

Show

1. What makes an AI "agentic"

A chatbot answers. An agent acts. The line is the ability to call tools (functions, APIs, shells) and then react to whatever those tools returned โ€” usually in a loop, with the model deciding when to stop.

Concretely: an agent is an LLM wrapped in a control flow that lets it (a) read its current state, (b) propose a next action, (c) execute that action, (d) observe the result, and (e) decide whether to go again. Everything else โ€” memory, planning, multiple agents talking โ€” is layered on top of that core loop.

2. The perceive-think-act loop

Almost every agent framework boils down to the same loop:

  1. Perceive: take the user's request + any prior context.
  2. Think: the LLM emits either a tool call or a final answer.
  3. Act: if it's a tool call, the runtime executes it.
  4. Observe: feed the tool result back into context.
  5. Go to 2.

The LLM is doing all the deciding. The runtime is just a switch: "is this output a tool call or a finished answer?" That's it. Everything fancy (memory, retries, planning) is bolted onto this skeleton.

3. The agent loop, visualised

Each iteration: the model picks a tool or returns. The runtime obediently routes.

flowchart LR
  User["User request"] --> Model["LLM call"]
  Model --> Decide["Tool call or done?"]
  Decide --> Tool["Execute tool"]
  Tool --> Model
  Decide --> Done["Return to user"]

4. Tools are the action surface

An agent can only do what its tools let it do. Pick tools deliberately โ€” each one is a verb in the agent's vocabulary.

  • Read-only tools (search_docs, read_file, query_db) are cheap and safe to expose generously.
  • Write tools (send_email, git_push, charge_card) need careful design: explicit confirmations, dry-run modes, scoped permissions.
  • Compound tools (run_python) are the most powerful and the most dangerous โ€” they essentially hand the model arbitrary code execution.

A common mistake is giving the agent 50 tools "just in case". The LLM's tool-selection accuracy drops as the menu grows. Aim for 5โ€“15 high-signal tools.

5. Memory: short-term vs long-term

Agents have three memory layers:

  • Working memory = the current context window. Free, lossless, capped (e.g. 200K tokens). Resets every turn.
  • Episodic memory = past interactions, stored somewhere external (DB, vector store) and retrieved on demand.
  • Semantic memory = distilled facts the agent has learned, often summarised so they fit cheaply.

The craft is deciding what graduates from working โ†’ episodic โ†’ semantic. "Just stuff everything in the prompt" doesn't scale past a few sessions. "Store everything as an embedding" gets noisy fast.

6. Planning patterns: ReAct vs Plan-and-Execute

Two dominant patterns:

  • ReAct (Reason + Act): the model interleaves a thought, a tool call, and an observation each turn. Simple, fast to implement, and what most frameworks use by default.
  • Plan-and-Execute: the model first emits a multi-step plan, then a separate executor runs each step. Better for long tasks where drift matters; worse when the plan is wrong (which is often).

ReAct is the default for a reason. Reach for Plan-and-Execute when steps are expensive (e.g. each one runs a 30-second SQL query) and you need to commit to a strategy upfront.

7. Multi-agent systems

Sometimes one agent isn't enough โ€” you split the work across specialists. A researcher agent searches the web, a writer agent drafts the report, a critic agent reviews it.

The upside: each agent has a tighter prompt and tool set, so they make fewer mistakes. The downside: coordination is now a problem too. Agents must agree on a shared scratchpad, handoff conditions, and a termination rule.

Rule of thumb: don't split into multiple agents until one agent has clearly hit its ceiling. Two mediocre agents are worse than one good one.

8. Failure modes you'll hit

Things that break in real agents, ranked by how often they bite:

  1. Infinite loops โ€” the model retries the same failing tool call. Fix with a hard step limit (max_iterations=20) and a same-call detector.
  2. Context exhaustion โ€” the conversation grows past the window. Fix with compaction or sliding summaries.
  3. Hallucinated tool calls โ€” model invents a tool that doesn't exist. Fix with strict schema validation + a polite error message back into context.
  4. Confident wrong answers โ€” model declares done with the wrong result. Fix by adding a verification step or LLM-as-judge.
  5. Cost runaway โ€” each turn is one full model call. Set a token budget per session, not just per call.

9. When NOT to use an agent

Agents are slow and expensive. Each turn is a full model call, and tasks routinely take 5โ€“30 turns. If your task can be solved by:

  • a single prompt with a structured output schema, don't use an agent
  • a deterministic script with one LLM step, don't use an agent
  • a RAG pipeline that retrieves once then answers, don't use an agent

Use an agent when the path is genuinely uncertain: the model needs to look something up, decide what to do based on the result, and possibly try again. "Browse the docs and answer this specific question" is agent-shaped. "Summarise this PDF" is not.

10. Minimal agent in 15 lines

Here's the entire pattern in Python with the Anthropic SDK. Real frameworks add error handling, parallel tool calls, and observability โ€” but the skeleton is this small.

import anthropic
client = anthropic.Anthropic()
messages = [{"role": "user", "content": "..."}]
while True:
    r = client.messages.create(model="claude-opus-4-7", tools=TOOLS, messages=messages, max_tokens=4096)
    messages.append({"role": "assistant", "content": r.content})
    if r.stop_reason == "end_turn":
        break
    tool_results = [run_tool(b) for b in r.content if b.type == "tool_use"]
    messages.append({"role": "user", "content": tool_results})

Everything else is decoration.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. What is the single capability that most clearly separates an agent from a regular chatbot?
    • Larger context window
    • Ability to call tools and react to their results in a loop
    • Better quality on creative writing
    • Use of a vector database for memory
  2. You give your agent 47 tools "just in case it needs them". What is the most likely consequence?
    • The agent runs faster because it has more options
    • Tool-selection accuracy drops because the menu is too long
    • Memory usage explodes
    • The model refuses to respond
  3. Which task is the *worst* fit for an agent?
    • Debug a failing CI run by reading logs and proposing fixes
    • Answer a factual question whose answer is in the model's training data
    • Browse documentation across several pages to compare two APIs
    • Triage a customer ticket by checking the user's account state
  4. Your agent keeps re-calling the same tool with the same arguments after it failed once. What's the canonical fix?
    • Switch to a more capable model
    • Raise the temperature so it tries new things
    • Add a step limit and detect repeated identical calls
    • Disable the failing tool
  5. In a Plan-and-Execute setup, what's the main risk compared to ReAct?
    • Higher latency per turn
    • Tools become harder to call
    • Committing early to a wrong plan and not adapting mid-execution
    • The model can no longer use memory

Related lessons

AI
beginner

Loop engineering basics: the agent control loop

How LLM agents actually run: the iterative prompt-action-observation loop, the ReAct shape, the smallest tool-calling loop in twelve lines, why you always stack three termination layers, what the model sees on iteration N, and when a single prompt is the better answer.

8 stepsยท~12 min
AI
advanced

Loop engineering: verification, orchestration, and anti-patterns

Make loops trustworthy. Adversarial verification panels, sub-agent orchestration, loop-until-dry for unbounded discovery, loop-until-budget for paid depth, multi-modal sweeps with diverse prompts, eval-driven cap selection, and the five anti-patterns โ€” silent caps, infinite plans, drift, premature termination, thrashing โ€” that ship to prod more than they should.

9 stepsยท~14 min
AI
intermediate

Loop engineering in production: state, errors, and budgets

Once an agent loop runs past a few iterations the failure surface shifts: state bloats, tool calls fail in three distinct ways, retries multiply if you stack them wrong, and unbounded budgets rack up four-figure bills overnight. The state, errors, and budgets you need to make the loop survive contact with reality.

8 stepsยท~12 min
AI
intermediate

LLM Observability with OpenTelemetry: GenAI Semantic Conventions

Master the OTel GenAI semantic conventions โ€” gen_ai.* attributes, span structure for prompts/completions/tools, sampling strategies, and cost attribution โ€” and understand why standardizing across LangSmith, Phoenix, Datadog, and Grafana matters for production AI systems.

13 stepsยท~20 minยทaudio