
Welcome to the world of AI agents. Over this course, you'll learn what autonomous AI systems actually are, why they matter right now, and how to build and explain them by the end. Let's start with the basics.
What is an AI agent? At its core, an AI agent is a system that perceives its environment, decides on a course of action, and then acts — often across multiple steps — to accomplish a goal, without a human typing out every single instruction along the way. Unlike a simple program that follows a fixed script, an agent can choose which action to take next based on what it observes. It might call a tool, search the web, write code, or ask a follow-up question — all in service of finishing a task you gave it in plain language.
That behavior follows a repeating pattern: the agent loop — observe, think, act, repeat. First the agent observes — it takes in the current state of the world, like a user request or the result of its last action. Then it thinks — reasoning about what needs to happen next given its goal. Then it acts — calling a tool, sending a message, updating a file. And then it repeats the cycle, observing the new result and deciding what to do next, until the goal is reached. This loop is what separates an agent from a single, one-shot response.
Which brings us to chatbot versus agent. A traditional chatbot takes your message and generates a reply — one input, one output, done. It has no memory of taking real-world action, no ability to check its own work, and no loop. An agent, by contrast, can take a goal like book me the cheapest flight to Chicago next Friday,' break it into steps, search flights, compare prices, check your calendar, and confirm — looping through observe-think-act until the job is actually finished, not just described.
Let's walk through a simple agent in action. Imagine a travel-booking agent built with a framework like LangChain. You give it the goal: find and book a flight. It observes your request, thinks about what tool it needs — a flight search API — acts by calling that tool, observes the results, thinks about which option fits your calendar, acts again by checking your calendar, and finally acts one more time to complete the booking. Each step is a decision made by the model itself, not a script you wrote in advance.
Agents are already at work outside the classroom. Companies are using them for customer support that resolves tickets end-to-end, coding assistants that write and test their own code, and research assistants that gather and summarize information across dozens of sources — all without a human clicking through every single step.
So why is everyone talking about agents right now? Because for the first time, language models are reliable enough to make multi-step decisions, choose their own tools, and course-correct along the way — turning AI from something that just talks to something that actually does. That shift, from generating text to taking action, is the whole reason this course exists.
You've already met an AI agent. Maybe you didn't call it that, but if you've used a navigation app that reroutes you around traffic, a coding assistant that fixes its own bugs, or a customer service chat that actually resolves your problem instead of just answering questions, you've interacted with autonomous AI in action. This lecture is about naming that experience and understanding the pattern underneath it.
So what makes these agents, not just software? A normal app waits for you to tell it exactly what to do, step by step. An agent is different: it perceives what's happening around it, it reasons about what to do next, it takes action on its own, and it adjusts when things change — all with minimal moment-to-moment supervision from a human. That combination of perception, decision-making, and independent action is the line between a tool and an agent.
Let's walk through the agent loop in action using a navigation app as our example. First, observe: the app continuously reads your GPS location and live traffic data. Second, think: it evaluates whether your current route is still the fastest option, weighing new information against your goal of arriving on time. Third, act: if a highway suddenly backs up, it recalculates and redirects you onto a new road — without asking your permission first. Fourth, repeat: it keeps observing, thinking, and acting in a continuous cycle for the entire trip. Observe, think, act, repeat — that four-step loop is the heartbeat of every AI agent you'll study in this course.
Now let's look at coding agents that write and fix code. Tools like GitHub Copilot's agent mode and Cursor don't just autocomplete a single line anymore. Give them a task — add a login feature — and they'll read across your codebase, write new files, run the test suite, notice when a test fails, and rewrite the broken code themselves before showing you the result. That's the same loop: observe the code and test output, think through what's wrong, act by editing files, repeat until it works.
Agents are also showing up in customer service and support. Klarna, the payments company, built an AI assistant that handles full customer conversations end to end — refunds, cancellations, order questions — resolving issues on its own rather than just routing you to a human. It observes your request, decides which action to take in the company's systems, actually performs that action, like issuing a refund, and only escalates when it hits a case it can't resolve.
This raises a natural question: chatbot versus agent — what's the difference? A chatbot answers questions using conversation alone; it might tell you how to cancel a subscription, but you still have to go do it. An agent goes further: it can actually access the account, take the cancellation action itself, and confirm it's done. Chatbots talk. Agents act.
So, three examples, one pattern. Your maps app rerouting around traffic, a coding agent fixing its own bugs, and a support assistant resolving your refund — three completely different products, but every one of them runs the same observe, think, act, repeat loop with real autonomy. Once you can spot that pattern, you'll start noticing agents everywhere. And by the end of this course, you won't just recognize them — you'll know how to build one.
Welcome back. In the last lesson we talked about why AI agents matter right now. In this lesson, I want to give you the roadmap — the full architecture of an AI agent, laid out piece by piece, so you know exactly what you'll be able to build and explain by the time this course ends.
Let's start with the big picture: your roadmap. This course isn't just theory. By the end, you will be able to describe every major component of an AI agent, explain how those components talk to each other, and build a working agent yourself using real, industry-standard tools.
At the center of everything is the agent loop you'll master: Observe, Think, Act, Repeat. This four-step loop is the spine of the entire course. An agent observes its environment — a user message, a database result, a sensor reading. It thinks, reasoning about what that observation means and what to do next. It acts, usually by calling a tool or an API. Then it repeats the loop, observing the result of its action and deciding what comes next. Every agent you'll encounter, no matter how sophisticated, is running some version of this loop.
But what actually powers each step of that loop? That brings us to the building blocks inside every agent. First, the reasoning brain — typically a large language model — which interprets observations and decides what to do. Second, memory, which lets the agent remember earlier steps, user preferences, or long-running context instead of starting fresh every time. Third, tools and function calling, which give the agent hands — the ability to search the web, query a database, send an email, or run code. And fourth, planning and orchestration, the layer that breaks a big goal into smaller steps and sequences them correctly. You'll learn each of these as its own module, then watch them snap together into a working system.
Here's a quick scenario to make this concrete. Imagine an agent tasked with booking a customer a flight. It observes the request, thinks through what information it's missing — dates, budget — asks a clarifying question, then plans a sequence: search flights, compare prices, check the customer's calendar, and finally book the ticket using a tool call. Each of those steps draws on the brain, the memory, the tools, and the planner working together.
You won't just learn this conceptually — you'll use real frameworks that teams are using in production right now. LangGraph models agents as a graph of nodes with shared state, which makes it well suited for stateful, multi-step workflows. CrewAI takes a role-based approach, letting you assemble teams of agents that collaborate on a task. And you'll learn about the Model Context Protocol, or MCP, which is becoming a common open standard for connecting agents to external tools and data sources. These aren't toy examples — they're the same building blocks companies use to ship real agent systems today.
And this matters beyond the classroom. Agents like these already show up across real industries — automating customer support conversations, assisting developers inside coding tools, and orchestrating multi-step business workflows that used to require a human at every handoff. Understanding the architecture isn't academic; it's the skill set behind a fast-growing category of software.
So here's the promise of this course: by the end, you will design, build, and explain a complete, working AI agent — from the reasoning core, to memory, to tools, to the orchestration that ties it all together. Every lesson from here forward fills in one piece of the map we just drew. Let's get started.
Welcome to this section on the anatomy of an AI agent. By the end of these lectures, you'll be able to break an agent down into its core building blocks: the reasoning engine, memory, tools, and goals. But before we open up each piece, we need to understand the engine that ties them all together — a cycle that runs underneath everything an agent does.
That brings us to the core loop: perceive, think, act. Every autonomous agent, no matter how sophisticated, is built on this same three-step cycle, repeated over and over. First the agent perceives — it takes in information from its environment. Then it thinks — it reasons about what it perceived and decides what to do next. Then it acts — it actually does something, usually by calling a tool or taking an action in the world. And then the cycle repeats, using the results of that action as new perception. This loop is what separates an agent from a simple program that runs once and stops.
To see why this matters, compare one-shot answers versus the agent loop. A standard chatbot receives a message, generates a single response, and is done — it never checks whether its answer actually solved your problem. An agent, by contrast, keeps cycling: it perceives the outcome of its own actions, thinks about whether the goal is met, and acts again if it isn't. This looping behavior is what allows agents to handle multi-step, open-ended tasks instead of single-turn questions.
Let's walk through each stage. First, perceive: gathering information. An agent perceives through whatever channels are available to it — a user's typed request, a document, an API response, a database query result, or sensor data if it's operating in the physical world. This perception step defines what the agent actually knows at this moment, and everything downstream depends on it being accurate and current.
Next comes think: reasoning and planning. This is where the agent's reasoning engine, typically a large language model, interprets what it perceived and decides on a plan. Imagine an agent tasked with booking a business trip. It perceives the request — dates, destination, budget — and then it reasons: it needs to check flight availability, compare prices, and confirm the itinerary fits the traveler's calendar. Frameworks like LangGraph are built specifically to structure this thinking step, letting the agent break a goal into smaller reasoning steps before committing to an action.
Then: act, taking action in the world. Having decided what to do, the agent executes — often by calling a tool or API. For our travel-booking agent, that might mean issuing a structured function call to a flights API with specific arguments, receiving flight options back, and passing them into the next round of perception.
We see this loop in practice constantly in real workplaces today — customer support agents that read a ticket, reason about the right resolution, and take action in a helpdesk system, only to reassess once the customer replies.
And that's the key idea to close on: the loop never stops. An agent keeps perceiving, thinking, and acting — cycling again and again — until its goal is satisfied or it determines the task can't be completed. That continuous cycle, not any single clever response, is what makes an AI system genuinely agentic.
Every AI agent needs something that decides what to do next — and in modern agents, that role is filled by a large language model acting as the reasoning engine. Think of the LLM as the brain of the agent: it doesn't move the arms and legs itself, but it decides which action the body should take. In this lecture, we'll unpack exactly how an LLM performs this reasoning and decision-making role.
Traditionally, we think of an LLM as a text predictor — you give it a prompt, and it generates a plausible continuation. But inside an agent, that same next-token prediction machinery is repurposed to do something much more powerful: interpret a goal, weigh options, and choose an action. The model reads the current state — the user's request, prior steps, tool results — and outputs a decision about what should happen next, in a structured way the surrounding software can execute.
One of the techniques that made this possible is chain-of-thought prompting. Researchers found that when a large language model is prompted to articulate intermediate reasoning steps rather than jumping straight to an answer, it solves complex, multi-step problems far more reliably. Instead of guessing an answer outright, the model essentially thinks out loud,' breaking a problem into smaller logical steps before committing to a conclusion. This step-by-step reasoning is the foundation agents rely on: rather than a single leap from question to final answer, the model produces a trace of intermediate thoughts.
Agent frameworks took this idea further with an approach called ReAct — short for Reasoning and Acting. In a ReAct-style loop, the model alternates between generating a thought, choosing an action such as calling a tool, and then observing the result before reasoning again. This interleaving of thinking and doing is what turns a passive text generator into an active decision-maker. Many early agent frameworks, including LangChain, implemented ReAct-style prompting to let LLMs plan multi-step tasks. More recently, native function-calling capabilities built directly into models like GPT, Gemini, and Claude have taken over much of this role, letting the model output a structured function call — reasoning is implied, and the action comes out as clean, parseable data the runtime can execute directly.
Let's walk through a concrete scenario. Imagine an agent tasked with answering, What's the weather in Boston, and should I bring an umbrella tomorrow?' The LLM first reasons: this requires current weather data I don't have memorized. It decides to call a weather tool. The runtime executes that tool call, returns results such as tomorrow's forecast, and feeds that observation back into the model's context. The LLM then reasons again over this new information, and finally generates a natural-language answer combining the forecast with a recommendation. At every one of those junctures — deciding to call a tool, interpreting its output, and deciding when to stop — the LLM's reasoning was in the driver's seat.
This is the essential shift: the LLM isn't just answering questions anymore. It's continuously making judgment calls — what to do next, which tool fits, whether the goal has been reached, or whether another step is needed. That decision loop, powered entirely by the model's learned reasoning ability, is what lets us call it the brain of the agent. In the next lecture, we'll look at how agents give that brain something reasoning alone can't provide: memory.
Every AI agent needs a starting point — a definition of what it's supposed to do, and what it should never do. That starting point is usually a system prompt: a block of text set before the conversation begins that shapes the agent's goals, tone, and boundaries for every interaction that follows.
Let's start with why goals and instructions matter so much. Without a clear goal, a reasoning engine — even a powerful one — has no direction. It might respond fluently, but it won't reliably solve the problem you actually built it for. A vague instruction like be helpful leaves too much room for interpretation: helpful in a medical context looks nothing like helpful in a coding context. Instructions also set guardrails — what the agent must avoid, like giving financial advice or leaking private data. And they establish consistency, so the agent behaves the same way in message one and message one hundred. Goals, guardrails, and consistency — that's why the system prompt is often the single most important piece of an agent's design.
So what actually goes into one? Think of the three ingredients of a system prompt, written in sequence. First, define the goal — a plain statement of the outcome the agent is working toward, like help users troubleshoot their software issue.' Second, set constraints — rules it must never break, such as never sharing internal pricing or never impersonating a human. Third, establish persona and tone — is this agent formal, casual, terse, encouraging? Writing a system prompt is really just walking through these three steps deliberately, instead of leaving them implicit.
Here's the anatomy of a system prompt in practice. Imagine we're building a customer support agent for a software company. A basic prompt might read: You are a support agent for Acme Cloud. Your goal is to resolve billing and login issues quickly. Never share internal account data with anyone other than the verified account owner. Keep responses under 100 words, in a friendly, professional tone.' Notice how compact that is — one line for goal, one for constraint, one for tone — yet it gives the reasoning engine everything it needs to behave predictably.
This pattern shows up in system prompts in real frameworks everywhere. Anthropic's Claude and OpenAI's GPT-based assistants are both configured through system-level instructions before any user message arrives — defining scope, refusal behavior, and voice. Frameworks like LangChain and CrewAI expose this same idea as an agent role or system message parameter you set when initializing an agent. Whether you're chatting with a consumer product or scripting a multi-agent pipeline, a written instruction block anchors everything downstream.
Now, not all system prompts are equally effective — let's compare vague versus well-defined prompts. A vague prompt, You are a helpful assistant,' leaves the agent guessing at scope, so it might overreach or behave inconsistently across sessions. A well-defined prompt — You are a scheduling assistant. Your goal is to book meetings within business hours. Never schedule outside the user's calendar availability, and always confirm the time zone — gives explicit goals and explicit limits, so behavior stays predictable even as conversations get complex.
This isn't just an academic exercise. Prompt engineering in practice means teams spend real time testing system prompts against edge cases, tightening wording after an agent misbehaves, and iterating the same way you'd debug code.
So here's the takeaway: write prompts agents can actually follow. A great agent starts with a great system prompt, because you cannot expect precise behavior from imprecise instructions. When you write goals, constraints, and tone clearly, you give the reasoning engine a reliable foundation to build every decision on.
Every AI agent that has to act over multiple steps needs a way to remember what just happened and what it's still trying to achieve. In this section, Memory and Context: How Agents Remember, we'll explore how agents juggle short-term and long-term memory to stay coherent across a task. Let's start with the most immediate kind of memory an agent has: its context window.
So, what is a context window? Put simply, it's the entire chunk of text — the system instructions, the conversation so far, any documents or tool results — that a language model can actually see at the moment it generates its next response. Think of it as the agent's working memory. Anything inside that window shapes the next decision. Anything outside it might as well not exist, because the model literally cannot read it. The context window has a fixed size, measured in tokens — small chunks of text — and once that budget is used up, something has to give.
That brings us to how the context window fills up in practice. Imagine an agent handling a long customer support conversation. Each new message from the user is appended to the context. Then, before generating a reply, the model reads the entire window — instructions, history, and all — top to bottom. If the conversation keeps growing, eventually the window hits its limit, and the oldest messages get trimmed to make room for new ones. This append, read, and trim cycle repeats every single turn, which is why we call it a sliding window: it constantly shifts forward, quietly dropping the earliest content behind it.
Now let's peek at where that limit actually bites. Engineers typically count tokens before sending anything to the model, so they know exactly how much room is left. A simplified version might count the tokens in the system prompt, the conversation history, and the new user message, then check whether the total exceeds the model's maximum. If it does, older turns get dropped or summarized before the request goes out. This token accounting is invisible to the end user, but it's happening constantly behind the scenes in any production agent.
This matters because short context versus long context produces very different behavior. With a short context window, an agent tends to forget earlier instructions, repeats questions it already asked, and loses track of multi-step plans halfway through. With a longer context window, the same agent can hold onto much more conversation history, follow a complex multi-step plan without losing the thread, and reference something the user said many turns earlier. The tradeoff is that longer contexts cost more to process and can slow the agent down, so bigger isn't automatically better — it's a balance.
You can see context limits in the real world constantly. Picture a support agent handling a long, technical troubleshooting session: if the context window is too small, the agent might ask the customer to repeat their account details for the third time, frustrating everyone involved. Well-designed systems work hard to avoid exactly this failure.
Which brings us to context windows in practice. Anthropic's Claude models and OpenAI's GPT-4 family are both built with increasingly large context windows specifically to reduce this kind of memory loss over long tasks. And frameworks like LangChain include conversation buffer memory components that manage exactly this problem — deciding what to keep, what to summarize, and what to quietly let go of as the conversation grows. Understanding the context window is the foundation for understanding agent memory — next, we'll build on this to see how agents extend beyond it with long-term memory.
Why do agents need long-term memory? Every large language model works inside a context window — a fixed amount of text it can see at once. Once that window fills up, older messages get pushed out and forgotten. For a simple chatbot answering one question, that's fine. But an agent working on a project over days, remembering a user's preferences, or recalling a decision made hundreds of steps ago needs something more durable. Long-term memory is a way for an agent to store information outside its context window and pull it back in exactly when it's relevant.
Think of short-term context versus long-term memory this way: short-term memory is the agent's working desk — everything currently in view, held directly in the prompt. It's fast but tiny and temporary. Long-term memory is more like a filing cabinet: essentially unlimited in size and persistent across sessions, but not automatically visible. The agent has to actively retrieve what it needs. That retrieval, rather than sheer memorization, is what makes long-term memory workable at scale.
Here's the retrieval pipeline, from text to memory, step by step. First, a piece of information — a past conversation, a document, a user preference — is converted into an embedding: a list of numbers capturing its meaning. That embedding is stored in a vector database alongside the original text. Later, when the agent needs to recall something, it embeds its current query the same way, and the database finds stored embeddings that are mathematically closest — meaning semantically similar. Those matches are retrieved and injected back into the prompt.
Let's make storing and searching embeddings concrete. A developer building an agent might use a library like LlamaIndex or LangChain together with a vector store such as Chroma or pgvector. Text gets embedded through a model, the vector is saved with metadata, and later a similarity search returns the closest matches — say the top three or five — which get pasted into the prompt before the model reasons over them. No exact keyword matching is required; the search works on meaning, so cancel my order can retrieve a memory about refund request even without sharing a single word.
This pattern shows up across the industry as vector databases in practice. Tools like Pinecone, Weaviate, and Chroma are purpose-built for exactly this job. Postgres users often add the pgvector extension to get similarity search inside a database they already run. Frameworks like MemGPT push this further, treating an agent's memory like an operating system manages RAM and disk — swapping information in and out of context automatically. The underlying idea stays the same: turn meaning into numbers, store the numbers, and search by closeness.
This is memory infrastructure at work, not just theory. Engineering teams run these vector systems in production — indexing millions of support tickets, conversation logs, or product documents so an agent can search years of history in a fraction of a second and pull only what's relevant to the current task.
So the takeaway is retrieval by similarity, not recency. An agent doesn't remember everything, and it doesn't just recall the most recent thing said. It searches its stored memory for what's most similar in meaning to what it needs right now, retrieves a handful of the closest matches, and reasons with that context. That single mechanism — embed, store, search, retrieve — is what gives agents memory that persists far beyond any single context window.
Let's talk about the memory problem: why agents can't remember everything. Picture an AI customer support agent that's been chatting with users all day. Every message, every tool call, every clarifying question — if the agent tried to hold onto all of it forever, two things would break. First, most language models have a limited context window, a hard ceiling on how much text they can consider at once. Second, even when space exists, stuffing in irrelevant history wastes compute, slows responses, and actually distracts the model from what matters right now. So a well-designed agent can't just accumulate — it has to actively manage its memory.
That brings us to three questions every agent must answer about every piece of information it encounters: should I keep it, should I summarize it, or should I discard it? Keeping is for facts still directly relevant — a user's name, an unresolved bug, a stated preference. Summarizing is for episodes that matter in outline but not in verbatim detail — the user tried three troubleshooting steps before this one worked.' Discarding is for anything transient and no longer useful — small talk, resolved side-issues, redundant repeats of the same fact.
How does this actually happen inside a running agent? Think of it as a loop: the memory management loop. First, the agent captures new information as it observes and acts — a user message, a tool result, an internal thought. Next, it scores that information for relevance and importance, asking how likely this is to matter later. Then it compresses and stores what's worth keeping, often folding several turns into a compact summary rather than raw text. Finally, it evicts or forgets what's gone stale, freeing space for what's next. This loop repeats continuously as the conversation or task unfolds.
Let's look at strategy one: recency and relevance scoring. Researchers behind the Stanford Generative Agents project — simulated characters living in a small virtual town — gave each agent a memory stream where every entry gets scored on three factors: how recent it is, how important it seems, and how relevant it is to the current situation. High-scoring memories get pulled back into context; low-scoring ones fade into the background. Frameworks like MemGPT apply a similar idea in production agents, treating memory like an operating system manages RAM versus disk — hot, relevant facts stay close at hand, while older material gets paged out to longer-term storage and retrieved only when needed.
Strategy two is summarization and compression. Instead of keeping twenty-four raw conversational turns, an agent can compress them into a short structured record — a summary plus a handful of key facts — and discard the verbatim exchange. This is exactly what lets an agent stay coherent across a long support ticket without hitting context limits.
Strategy three is forgetting — letting go of the stale. This isn't a failure state; it's deliberate design. A raw transcript full of every retry and repeated question is noisy and expensive to reprocess. A pruned, compressed memory keeps only the salient facts an agent actually needs to act correctly going forward. Good forgetting is what keeps an agent fast, focused, and affordable to run.
Finally, memory management in practice. In real deployments — customer support platforms, coding assistants, research copilots — engineering teams constantly tune these thresholds: how aggressively to summarize, how long to retain facts, when to evict old context entirely. Getting this balance right is often the difference between an agent that stays sharp over a long session and one that either forgets what matters or drowns in what doesn't.
This section is all about how AI agents move beyond chatting and start acting in the real world — using tools, APIs, and function calls to actually do things. Let's start with the foundational piece that makes all of that possible: Function Calling: Giving Agents Hands.
Here's the core problem. A large language model, on its own, only knows how to do one thing: predict the next chunk of text. It can write a beautifully worded answer about the weather in Tokyo, but it has no thermometer, no live feed, no way to actually know. It's brilliant at language, but blind to the world. Function calling is the mechanism that fixes this. Instead of forcing the model to just generate prose, we let it generate something more useful when needed: a structured, machine-readable request naming a specific function and the arguments to pass it. The model doesn't execute anything itself — it simply says, in effect, call get_weather with city equals Tokyo,' and hands that request back to your application.
So let's walk through How a Function Call Works, step by step. First, the model looks at the user's request and decides a tool is actually needed — this is a judgment call the model makes based on the conversation. Second, instead of replying in plain English, it emits a structured call: a function name plus a JSON object of arguments. Third, your application — not the model — actually executes that function, hitting a real API, database, or service. Fourth, the result gets sent back into the model's context, and now the model can weave that real, live data into its final answer. This loop can repeat multiple times in a single turn if the task needs several tools.
To make this concrete, let's look at Defining a Function for the Model. Before any of this works, developers describe each available tool using a JSON schema — a name, a description, and the parameters it accepts, like a city name and unit of measurement for a weather lookup. This schema is the contract the model uses to know exactly what it's allowed to ask for and how to format the request correctly.
This pattern shows up everywhere in Function Calling in Practice. OpenAI's Responses API lets developers pass a list of tool definitions, and the model returns structured tool calls your code then executes. Anthropic's Claude uses a very similar tool-use pattern, and both companies now support the Model Context Protocol, or MCP, an open standard that lets a model discover and call tools from external servers without custom glue code for every single integration. Different vendors, same underlying idea: structured requests standing in for plain text.
Zooming out to From API Docs to Real Actions — this is genuinely how production agents work. A support agent calls a ticketing API. A scheduling agent calls a calendar API. A shopping agent calls a payments API. Every documented API endpoint becomes a potential hand the agent can use, as long as it's described as a callable tool.
It helps to see this side by side: Text Generation vs Function Calling. Without function calling, an LLM asked for today's weather can only guess, hedge, or admit it doesn't know — it's stuck with whatever was in its training data. With function calling, that same question triggers a real call to a live weather API, and the answer comes back accurate and current.
Which brings us to the takeaway: function calls give agents hands. They're the bridge between a model's reasoning and the outside world's actions — the mechanism every tool-using agent depends on, and the foundation for everything else we'll cover in this section.
Let's talk about Tool Selection: How Agents Choose the Right Action. An AI agent rarely has just one tool. It might have access to a web search function, a calculator, a database query, a calendar API, and a code execution sandbox — all at once. So when a task comes in, how does the agent decide which one to actually use? That decision process is what we're unpacking today.
First, we need to understand what the agent sees: the tool registry. Before the agent can choose anything, every available tool is described to the underlying model in a structured way — a name, a plain-language description of what it does, the parameters it expects, and often notes on when it should or shouldn't be used. Think of it like a menu handed to a very capable chef: the chef doesn't invent dishes from nothing, it picks from what's listed, using the descriptions to understand each option's purpose.
Now imagine a concrete task: a personal assistant agent is asked, Book me a flight to Boston and tell me if it will rain when I land.' This triggers the selection process: from task to tool call. Step one, the agent parses the request into sub-goals — booking a flight, and checking weather. Step two, it matches capabilities: which of its available tools can plausibly handle each sub-goal? A flight-booking API matches the first; a weather or search tool matches the second. Step three, it ranks candidates — if there are two weather tools, it might prefer the one with fresher data or lower cost. Step four, it selects and calls the tool, passing in the right arguments.
Under the hood, this looks like a tool schema — real structured data the model reasons over. Picture two tool definitions: one called websearch, described as look up current facts,' and one called calculator, described as evaluate math expressions.' If a user asks what's 482 times 17,' the model compares the request against both descriptions and returns a function call naming calculator, with the expression as an argument — not websearch, because the description simply doesn't match the intent.
This isn't theoretical — it's exactly how production systems work today. OpenAI's function calling API and LangChain's AgentExecutor both operate this way: the developer registers a list of tools with schemas, and the model's job at each step is to output which function to call and with what arguments. In our flight-and-weather example, the agent might first call a flight-booking tool, then chain into a weather-lookup tool once it knows the arrival city and date — selecting each tool in sequence as new information becomes available.
But selection can go wrong, and that's worth seeing directly: choosing well versus choosing poorly. Imagine the agent picks the calculator for a live weather question. It has no real data to work with, so it guesses — producing a confident-sounding but entirely fabricated answer. Now compare that to the agent correctly matching the same question to a live search or weather API tool. It retrieves real, current data and returns a grounded, accurate response. The difference between those two outcomes is entirely about matching intent to capability — the core skill of tool selection.
Finally, let's ground this in tool selection in the wild. Customer support copilots juggle ticketing systems, knowledge bases, and refund APIs. Coding assistants juggle file search, code execution, and documentation lookup. In every case, the agent is running this same loop behind the scenes — parsing the request, matching it against available capabilities, ranking the best fit, and calling the tool — dozens of times a day, call by call, to turn a plain-language instruction into the right real-world action.
So far we've talked about agents calling a single tool to answer a single question. But most real tasks aren't that simple. Booking a trip, resolving a support ticket, or generating a report all require several actions performed in the right order, each one building on the last. That's what we mean by chaining actions: multi-step task execution.
Here's the core idea. When an agent receives a complex goal, it doesn't try to solve everything in one leap. Instead, it breaks the goal into a chain of steps. First, the agent looks at the goal and decides what smaller, tool-sized actions would move it forward. Then it executes one step using a tool — maybe a search API, a database query, or a calculation. It observes the result that tool returns. And based on that observation, it decides the next step, repeating this cycle until the goal is fully satisfied. This reasoning-act-observe cycle is often called the ReAct pattern, and it's the same reasoning-act loop you've seen before — just applied repeatedly, with each action's output feeding directly into the next decision.
Let's walk through a worked example: booking a trip. Imagine a user tells an agent, Book me a flight from Boston to Denver next Tuesday.' The agent can't do this in a single tool call. Instead it chains several: first it calls a flight-search tool and gets back a list of available flights. Then, using that result, it selects one and calls a second tool to check the seat price and availability. Once confirmed, it calls a third tool to actually make the booking, passing along the flight ID it received earlier. Finally, it calls a fourth tool to send a confirmation email. Frameworks like LangGraph are built specifically to manage this kind of stateful, multi-step chaining — tracking what's happened so far and deciding what tool runs next based on it.
What makes this work technically is passing results between tool calls. The output of one action becomes the input to the next. If the flight-search tool returns a flight ID, that exact ID gets threaded into the arguments of the booking tool call. The agent's job is to keep track of this growing context — what's been done, what was learned, and what's still needed — across every step of the chain.
It helps to see this next to a single call. In a single call, the agent fires off one tool, gets one result, and answers. There's no memory carried forward, no multi-step plan — it's one-shot. In chained execution, the agent maintains state across many tool calls, uses each result to inform the next decision, and only stops once the entire goal — not just one sub-task — has been completed. This is what separates a simple assistant from something that can genuinely complete a real-world workflow.
You can see chaining in the real world across many industries already — customer support agents that verify an account, check a policy, and then issue a refund; logistics systems that check inventory, reserve stock, and generate a shipping label, all as one continuous chain of tool calls triggered by a single user request.
The key takeaway: complex goals get decomposed into smaller tool-based steps, and the agent threads results from each action into the next — that's chaining, and it's what lets agents actually finish real, multi-step jobs instead of just answering questions.
Welcome to a new section: Autonomy, Planning, and the Future of Agents. By the end of it, you'll be able to explain how agents plan multi-step strategies, self-correct through feedback, and weigh the risks of giving AI systems real independence. Today we start with the foundation underneath all of that: Planning and Task Decomposition — how an agent turns one big, fuzzy goal into a sequence of concrete steps it can actually execute.
Let's start with Task Decomposition: Breaking Goals into Subtasks. Think about the difference between a chatbot and an agent. A chatbot told to plan a weekend trip to Chicago just writes a paragraph of suggestions. An agent has to actually do it — check dates, search flights, compare hotels, and confirm a booking. It can't do that in one leap. It has to decompose the goal into smaller, ordered subtasks it or its tools can carry out. Without this step, an agent is just a text generator with opinions. With it, the agent can act.
One of the most influential techniques for doing this is The ReAct Pattern: Thought → Action → Observation. Instead of planning everything upfront, the agent loops through three phases. Thought: it reasons in natural language about what to do next. Action: it takes a concrete step, like calling a search tool. Observation: it looks at what came back and folds that into its next thought. Then it loops again. This matters because plans rarely survive contact with reality — a flight might be sold out, an API might error — and ReAct lets the agent adjust instead of blindly following a rigid script.
ReAct builds on an earlier idea: Chain-of-Thought Reasoning in Practice. Researchers found that simply prompting a model to think step by step before answering dramatically improved performance on multi-step problems, because it made the intermediate reasoning explicit and inspectable. Frameworks like LangChain and AutoGPT popularized wiring this chain-of-thought reasoning directly into tool-using loops, so thinking out loud becomes the mechanism an agent uses to decide its next subtask.
Here's What a Planning Trace Looks Like under the hood. The agent writes a thought, issues an action as a function call with arguments, receives an observation back from that tool, and writes a new thought incorporating it — repeating until the goal is satisfied. This is exactly the pattern used inside modern agent frameworks when they call search APIs, databases, or calendars.
Now picture Planning in the Real World. Imagine a support agent handling a complicated refund request that spans a shipping delay and a damaged item. Instead of guessing, it decomposes the case: check the order status, check the shipping carrier's tracking log, check refund policy rules, then decide. Each subtask is a tool call, and each observation can change the next step — exactly the ReAct loop in action, on a real workflow a human agent might otherwise have had to piece together by hand.
Finally, let's contrast the two approaches directly: Single-Step Prompting vs Multi-Step Planning. A single-shot prompt asks for a final answer immediately, with no chance to check facts or recover from a wrong guess. Multi-step planning breaks the goal into ordered subtasks, checks real information at each step, and revises course when something doesn't match expectations. That difference — decomposition plus feedback — is what lets agents tackle goals no single prompt could reliably solve, and it sets up everything we'll cover next about self-correction and feedback loops.
Even great agents make mistakes. A language model can misread a request, write buggy code, or draft an email that misses the point entirely. What separates a fragile agent from a reliable one isn't perfection on the first try — it's whether the agent can notice its own errors and fix them before handing back a result. That's the idea behind self-correction and feedback loops, and it's one of the most important capabilities in modern agent design.
Here's how it works in practice: The Self-Correction Loop. First, the agent generates an initial attempt — a draft, a plan, a piece of code, an answer. Second, it evaluates that attempt, either by critiquing itself in natural language, running automated tests, or checking the result against the original goal. Third, if problems are found, the agent revises — it rewrites the draft, patches the code, or adjusts the plan. Then it repeats this generate-evaluate-revise cycle until the output is good enough or it hits a limit on how many attempts it's allowed. This loop turns a one-shot guess into an iterative refinement process, much like a human editor rereading their own work before submitting it.
Let's walk through a concrete example. Imagine an agent tasked with writing a summary of a technical document. It produces a first draft. Instead of stopping there, it re-reads its own summary and asks itself: did I miss any key numbers? Did I introduce anything not in the source? It might flag that it dropped an important caveat. So it revises the summary to include that caveat, checks again, and only then delivers the final version to the user.
This pattern has a name in research: Reflexion. Reflexion is a real framework where agents don't just retry blindly — they generate a verbal self-reflection on what went wrong in a failed attempt, store that reflection in memory, and use it to guide the next attempt. Instead of repeating the same mistake, the agent effectively learns within the task, without any weights being updated. Frameworks like LangGraph implement similar ideas using dedicated reflection nodes that sit between an agent's action and its next planning step.
What does a self-critique step actually look like under the hood? Often it's just another prompt to the model, asking it to act as its own reviewer: check the previous output against a rubric, list problems, and suggest fixes. The agent's runtime then feeds that critique back in as context for a revision pass, and the cycle continues.
This isn't just an academic idea — it shows up constantly in real workplace tools. Coding assistants run generated code against test suites and rewrite functions that fail. Writing copilots reread drafts for tone and factual consistency before presenting them. Customer support agents check whether their proposed answer actually resolves the customer's stated issue before sending it. Self-correction in the real world is the quiet layer of quality control behind agents that feel trustworthy.
It's worth contrasting the two approaches directly. Without a feedback loop, an agent produces one output and stops — errors go straight to the user, and any mistake in reasoning becomes a mistake in the final answer. With a feedback loop, the agent checks its own work, catches inconsistencies, and only surfaces a result once it passes its own review. The difference in reliability can be dramatic, especially on multi-step tasks where small early errors would otherwise compound.
But self-correction has real limits. Each additional review-and-revise pass costs more time and more compute, so there's a tradeoff between quality and efficiency. An agent can also be confidently wrong about its own critique — self-review isn't a guarantee of correctness. And without a clear stopping condition, agents can loop indefinitely, endlessly improving a good-enough answer or oscillating between two flawed versions. That's why well-designed systems cap the number of iterations and define concrete success criteria, rather than trusting the agent to know when it's truly done.
Let's talk about why autonomous agents still fail. After sections on planning and self-correction, it's tempting to think agents are nearly ready to run our lives unsupervised. They're not — and understanding their limitations is essential before we hand them real responsibility. That's our focus today: risks, limitations, and what's next for agents.
Start with where agents break down. First, hallucination — agents can state incorrect information with total confidence, because the underlying language model is predicting plausible text, not verifying truth. Second, brittle tool use — an agent might call an API with malformed arguments, misread a tool's response, or keep retrying a broken action. Third, limited memory and context — long-running tasks can drift once earlier details fall out of the agent's working context. And fourth, compounding errors — small mistakes early in a plan don't stay small.
Let's walk through that last one, because it's the most dangerous. Imagine an agent tasked with researching a competitor and drafting a strategy report. In step one, it misreads a single data point — say, a revenue figure pulled from a webpage. In step two, it builds its market analysis on top of that wrong number, because it trusts its own prior output without re-checking the source. In step three, it generates a recommendation based on that flawed analysis. By step four, it delivers a polished, confident report — and every sentence downstream of that first misread number is wrong. This is how small errors compound: each step in a plan inherits and amplifies the mistakes of the step before it, and the agent has no built-in reason to doubt itself.
That leads to serious safety concerns — call it losing the loop. An unsupervised agent with access to real tools — email, payment systems, code execution — can take actions faster than any human can review them. Without checkpoints, one bad decision can cascade into real-world consequences: wrong charges, leaked data, broken production systems. Compare that to a supervised agent, where key actions pause for human approval, sensitive tools are sandboxed, and outputs are logged for review. The difference isn't intelligence — it's oversight design.
This isn't just theoretical. Teams building and deploying agents deal with this daily — reviewing logs, setting permission boundaries, and deciding which actions are safe to automate versus which require a human in the loop. Oversight in practice looks like dashboards, approval gates, and audit trails sitting alongside the agent's own reasoning.
We've actually seen these limitations play out publicly. Lessons from AutoGPT are instructive here: when this early autonomous agent project launched in 2023, users found it could get stuck in repetitive loops, invent tasks that didn't serve the original goal, and burn through resources without ever reaching a useful conclusion. It was a clear, real-world demonstration that giving a model autonomy and tools isn't the same as giving it good judgment.
So, what's next for agents? The field is moving toward better evaluation benchmarks that test multi-step reliability, not just single answers. It's moving toward sandboxed tool execution, so a mistake can't touch production systems. It's moving toward built-in human-in-the-loop checkpoints for consequential actions. And it's moving toward interpretability — understanding why an agent chose a plan, not just what it produced. None of this makes agents perfect. But it's how we get from clever demos to systems we can actually trust with real responsibility.
This course contains the use of artificial intelligence.
AI agents are everywhere in the headlines — but what are they actually, and how do they really work? This course pulls back the curtain on autonomous AI systems, breaking down the exact architecture that lets AI go beyond simple chat responses and take real, independent action.
You'll start with the fundamentals: what makes something an 'agent' versus a chatbot, and where you've likely already encountered agents in products you use daily. From there, you'll dive into the core perceive-think-act loop, learn how large language models function as an agent's reasoning brain, and understand how goals and system prompts shape behavior.
Next, you'll explore how agents remember — from short-term context windows to long-term memory using vector databases — and how they decide what information to keep or discard. You'll then learn how agents interact with the world through function calling and tool selection, and how they chain multiple actions together to complete complex, multi-step tasks.
Finally, you'll examine advanced concepts like planning, task decomposition, and self-correction, along with a clear-eyed look at the real limitations, risks, and safety concerns surrounding today's agentic AI systems.
By the end, you won't just understand the buzzwords — you'll be able to explain, evaluate, and reason about AI agents with genuine technical clarity, whether you're a curious learner, a builder, or a decision-maker navigating this fast-moving space.