AI Engineering · Module 07
Agents: models that plan and act
- Lessons
- 15
- Free
- 1
- Reading
- ~5 h
Your progress
0 / 15 lessons done
Sign in to trackLessons
- Agents: models that act until a goal is metFreeMany features sold as agents are a few model calls in a loop that your own code runs. If you know the parts, the stops and the cost, you can build one that ends, stays in budget and leaves consequential actions to a person, and you can tell when a plain workflow is the better build.
- Workflows vs agents: when you need autonomySooner or later someone on your team will propose rebuilding a working feature as an AI agent. You need a way to decide that from the feature’s steps and measured failures, not from what is new.
- ReAct: reasoning, acting and observing in turnsMost AI agents in production run some version of this loop. Knowing what each turn contains, and what the model reads at each step, is how you debug an agent that calls the wrong tool or answers too soon.
- Planning: breaking a goal into stepsAny AI agent that handles requests with several parts will one day drop a part or apply the wrong rule to it. A plan the code can see turns “the model forgot” into a missing step that code catches before a person approves the result.
- Agent memory: short-term context, long-term storesEvery AI agent you ship forgets everything between runs and pays again for everything it saw within one. Getting memory right decides whether users repeat themselves, whether costs grow with run length, and whether one bad note spreads into many wrong answers.
- Context engineering: choosing what the model seesEvery AI agent resends its whole run on every call. What you let into that run decides the bill, the wait and whether the model notices the one fact that matters.
- Multi-agent systems: orchestrators and subagentsWhen one AI agent runs out of context or time, the next idea is usually to add more AI agents. Before you build that, you need to know what it buys, what it costs and which new failures it brings.
- Agent2Agent protocol: agents calling other agentsMore companies are putting an AI agent in front of their own processes, such as claims, bookings and returns. When your software needs one of those done, A2A is a standard way to ask, follow the work for days and get a result back that you can check.
- Human in the loop: approvals and handoffsAny AI agent that can spend money or write to customers needs a person somewhere in its loop. If the request is badly designed, that person stops reading within weeks, and the approval no longer protects anything.
- Agent reliability: loops, limits and budgetsAn AI agent decides how many steps it takes, so without limits a single bad run has no ceiling on cost, time or side effects. The limits, loop checks and idempotency keys in this lesson are what let you put one in production and still know the worst case before it happens.
- Agent frameworks: when to use oneEvery team that ships an AI agent is asked why it doesn’t use a framework, or why it does. If you know what each layer takes over and what it sets for you, you can choose by your agent’s needs instead of by habit, and you’ll know which defaults to check before the first bill.
- Lab: an agent loop from scratch in PythonAgent frameworks wrap this loop in their own classes, but underneath they run the same steps: call the model, run the tools, add the results, check the limits. Writing it once by hand shows where cost builds up, where a person must step in and what each stop reason asks you to do.
- Lab: rebuilding your agent with LangGraphApprovals rarely come back while a program waits at a prompt: a support agent clicks hours later, after deploys and restarts. A framework that saves the run between steps solves that, and rebuilding a loop you already understand shows exactly what you gain and what you can no longer see.
- Case: Swiggy’s text-to-SQL analyst agentMost teams that ship text-to-SQL find that one model call is right for easy questions and wrong for their own business terms. Swiggy published what it added over three versions, so you can see which additions paid off and match them to your own data.
- Design: a research agent that writes reportsA research agent reads pages you don’t control and writes text that people act on. The model can find and read; the engineering is making every sentence traceable to a page it really fetched, at a cost you know before the run starts.
Practise with
Terms this module teaches 66
Open glossaryAgent Card
A JSON document an A2A server publishes to describe its agent: name, provider, version, skills, endpoint and the security schemes callers must use. Usually served at /.well-known/agent-card.json.
Agent framework
A library that runs an AI agent’s loop for you and adds parts long or complex agents need, such as saved state, pause and resume, streaming, tracing and approval steps.
Agent loop
The code around an AI agent that calls the model, runs the tools it asks for, adds the results to the conversation and repeats until a stop condition.
Agent middleware
In LangChain’s create_agent, a plug-in that runs code before or after model and tool calls, for example to cap the number of model calls, turn tool errors into results or pause for a person’s approval.
Agent2Agent protocol (A2A)
An open protocol for one AI agent to ask another, often run by a different organisation, to do a task, follow its progress and receive its results, without either sharing its internal state or tools.
Agentic system
Any system that combines model calls and tools to do a task, whether code or the model decides the steps. Workflows and AI agents are both agentic systems.
AI agent
Software in which a model, given tools and a goal, picks each next step from what the last one returned, in a loop that runs until the goal is met or a limit is reached.
Approval gate
A point in an AI feature where the software stops and waits for a person to approve or decline an action before anything with a consequence happens, such as a refund, a replacement or a message to a customer.
Approval request
What a person sees when software asks to take an action: the action and its cost, the evidence from the tools with links, the checks code ran, and what approving or declining will do.
Artifact (A2A)
An output an A2A task produces, made of one or more parts, separate from the messages exchanged along the way.
Audit log
A record of who did what and when, kept so actions can be checked later. For an AI feature: the user, the input, what the model produced and what ran.
Augmented LLM
One model call that can use retrieval, tools and memory. It is the building block of both workflows and AI agents.
Automation bias
The habit of trusting an automated suggestion instead of checking it, which grows when the system is usually right and the reviewer is busy with other work.
Business metric
A number a company tracks, with a definition specific to that company, such as which orders count and which columns it is computed from.
Checkpoint (AI agent)
A saved copy of an AI agent run’s state, written after a step, so the run can stop and later resume from there, even in another process.
Compaction (context)
Replacing the older turns of a conversation with a summary written by the model, so a long run stays within the context window. It costs an extra model call and can lose exact details.
Compounding errors
The way small chances of failure multiply over many steps: if each of n steps succeeds with probability p, the whole task succeeds with about pⁿ.
Context editing
A Claude API beta feature that clears content, such as old tool results or old thinking, from a request by rule before the model sees it. Your code keeps the full history.
Context engineering
Choosing, on every model call, what goes into the request: system prompt, tool definitions, retrieved text, tool results and history.
Data warehouse
A database built for large analytical queries over a company's history, kept apart from the databases the product runs on.
Environment (of an AI agent)
The systems outside the model that an AI agent’s tools read from or act on, and that answer with facts the model didn’t write.
Evaluator-optimizer
A workflow pattern in which one model call writes, another grades the result against clear criteria, and the feedback goes back for a revision, up to a set number of rounds.
Graph state
The shared data a LangGraph graph passes between its nodes. Each node reads it and returns updates, and each field has a rule for merging updates, such as appending to a messages list.
Hand-back
Ending an AI agent run by giving the task to a person, with the reason it stopped and what it found, instead of an answer.
Hosted agent
An AI agent whose loop, state and tool sandbox run on a provider’s infrastructure; your app starts sessions, sends messages and answers its custom tool calls.
Human in the loop
A design where software proposes an action and a person approves, edits or rejects it before it takes effect.
Human interrupt
A planned pause in an AI agent’s run that waits for a person to approve, edit or reject the next action before it continues.
Interleaved thinking
Thinking that a model does between tool calls, after reading each tool result and before deciding its next step. On Claude models with adaptive thinking it happens automatically.
JSON Web Signature (JWS)
A standard format for a digital signature over JSON content, so a reader can check who signed it and that it hasn’t changed.
LangGraph
An open-source Python library from LangChain that runs an AI agent or workflow as a graph: nodes are functions, edges choose the next node, and a shared state is saved after every step so a run can pause and resume.
Long-term memory (AI agents)
Facts kept in a store outside the model that outlive a run, written by your code and read back into the prompt of a later run.
Loop detection
Code that spots an AI agent repeating itself, such as the same tool with the same input or several turns with no new result, and ends the run early.
Memory tool
An Anthropic-provided tool that lets Claude view, create, edit, rename and delete files under /memories. It runs on the client: your code carries out each command on storage you control.
Mid-conversation system message
A message with role system added inside the messages list, so an app can give new instructions partway through without changing the cached start of the request.
Model adapter
Code in a framework that turns the framework’s generic model calls into one provider’s API requests, and sets its own defaults while doing so.
Multi-agent system
A design that splits one task across several AI agents, each with its own context, usually an orchestrator that hands out parts and subagents that do them.
Observation
What an AI agent sees after an action: the tool result or error added to the conversation before the next model call.
Orchestrator (AI agents)
The AI agent in a multi-agent system that plans the work, writes a task for each subagent and merges what they report.
Orchestrator-workers
A workflow pattern in which one model call splits a task into subtasks it chooses, worker calls handle each, and a final call merges the results.
Parallelization (workflow pattern)
A workflow pattern that runs independent model calls at the same time and merges their results in code, either by splitting the task into parts or by asking the same question several times and voting.
Part (A2A)
One piece of content in an A2A message or artifact: exactly one of text, raw bytes, a URL or structured data, with an optional media type and file name.
Plan-and-execute
An AI agent pattern where one model call writes the whole list of steps before any tool runs, and code or a loop then runs the steps and tracks each one’s status.
Prompt chaining
A workflow pattern in which each model call works on the output of the one before, in an order fixed in code, often with a code check between steps.
Push notification (A2A)
A webhook call an A2A server makes to a URL the client registered for a task, whenever the task changes, so the client doesn’t have to keep asking.
ReAct
A pattern for AI agents, from a 2022 paper, that interleaves a thought, an action and the observation the action returns, repeating until the task is done. On current Claude models the thought happens in thinking blocks and the action is a tool call.
Recursion limit
LangGraph’s cap on the number of graph steps in one call to the graph. Reaching it raises GraphRecursionError. It counts steps, not model calls, and starts again on every call, including a resume.
Replanning
Asking the planner for a corrected plan when a step fails after its retries or a result contradicts what later steps assumed, keeping the steps already done.
Routing (workflow pattern)
A workflow pattern in which one model call labels the input and code sends it to the handler for that label.
Run limit
A hard cap that code checks on every turn of an AI agent run, such as model calls, tokens, wall-clock time or money; the first one reached stops the run.
Short-term memory (AI agents)
Everything an AI agent has seen in the current run, kept as the messages list and sent again on every model call. It disappears when the run ends.
Spot check
Checking a small random sample of a result’s evidence by hand or with a second model call, to catch errors that format checks miss.
SQL-to-text
Asking a model to read an existing SQL query and write the plain-language question it answers, so past queries can become question-and-SQL examples.
Stop condition
A rule that ends an AI agent’s loop: the goal is met, a limit on calls or cost is reached, or the case needs a person.
Subagent
An AI agent started by an orchestrator to do one narrow part of a task in a fresh context, returning a short structured report.
Task (A2A)
A unit of work in A2A with a server-made id and a state, from submitted and working, through input-required or auth-required, to completed, failed, canceled or rejected.
Thinking block
A content block of type thinking in a model’s reply. Its text is a summary of the model’s reasoning, or empty, and its signature carries the full reasoning, encrypted. In a tool-use loop it must be sent back unchanged.
Thread (in LangGraph)
One run’s saved history in a checkpointer, named by a thread id in the run’s config. Calling the graph again with the same thread id continues that run.
Time to resolution
The time from a customer’s request arriving to the problem being solved, including every wait for a person, not only the time the software spends working.
Tool result clearing
Replacing old tool results in a conversation with a short note so later calls carry fewer tokens. It invalidates the prompt cache from the cleared point.
Tool search
Loading tool definitions only when the model searches for them, so rarely used tools don’t take up context on every call.
Usage metadata
LangChain’s provider-neutral record of the tokens one model call used, attached to the reply message: input, output and total tokens, with details such as cache reads and reasoning (thinking) tokens.
Vendor lock-in
The cost of leaving a product or library once your code and data depend on its formats, interfaces or hosting.
Web fetch tool
A server tool on the Claude API that downloads a web page or PDF whose URL already appeared in the conversation and adds its text to the model’s context as a document, with the time it was retrieved.
Web search tool
A server tool on the Claude API that runs web searches inside a request and adds the results to the model’s context, with citations to the result pages. Each search is billed per use, and the results are billed as input tokens.
Workflow (AI)
An AI feature whose code runs model calls and tools in steps fixed in advance, the same order every time.
Zero data retention
An arrangement in which a provider does not store the content of your requests and responses after it has processed them.