0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09A chatbot vs an agent: the returns example
A customer writes: "Where's order B-4127? Also, the mug in it arrived cracked. Can I return it?" A chat-only assistant can explain the returns policy, but it can't look up the order or start the return. The customer still has to wait for a person. Now give the assistant tools. It looks up the order: delivered yesterday. It checks return eligibility for a damaged item: eligible. It asks the customer to confirm. Then it creates the return and sends a label. Problem solved, in one conversation. A model that can take actions through tools, step by step, towards a goal, is called an agent.
Today: how tools and planning work, and why every step an agent takes adds both power and risk.
1:03Where this fits in the course
Season Five, Module Eighteen, stop three: agents, tools and planning.
1:11What is an AI agent?
You met agents in Season One: something that perceives an environment and takes actions towards a goal. An AI agent is a language model at the centre, with tools as its hands, working inside an environment, here Brightcart's order system, policy library and email, in a loop that continues until the goal is reached. There's a spectrum. In the prompt chains of episode sixty-two, the developer decided every step in advance. In an agent, the model decides which tool to use next, in what order, and when it's finished. That flexibility is what makes agents powerful, and harder to control.
1:53The three families of tools
Tools come in three families. Knowledge tools fetch information: searching policies, looking up a product, retrieving an order. Capability tools do things models are bad at: a calculator for exact arithmetic, code execution for analysing data, database queries. And write actions change the world: creating a return, issuing a refund, sending an email. Knowledge and capability tools turn "I think" into "I checked", reducing guesswork. Write actions are where the real value, and the real risk, lies. We'll treat them with special care.
2:33How function calling works
How does a model actually use a tool? Through function calling. The developer describes each tool: its name, a clear description of what it does, and the parameters it needs, as a small schema. The model reads the conversation and the list of tools, and when it decides a tool would help, it outputs a structured request: call "get order" with order number B-4127. Here's the crucial part: the model doesn't run anything itself. Your system receives that request, checks it's allowed, for example that this order belongs to the logged-in customer, runs the tool, and adds the result to the conversation: delivered yesterday, containing a mug and a kettle.
The model reads the result and decides what to do next: call another tool, or answer. The model proposes; your code executes. That separation is where safety lives.
3:30Planning: think, act, observe (ReAct) vs plan-first
How does an agent decide what to do? A popular pattern interleaves reasoning and acting: think about what's needed, take an action, observe the result, and think again. "I need the order status first." Look it up: delivered yesterday. "The mug is damaged, so check return eligibility." Eligible, with free return shipping. "Creating a return changes things, so I should ask the customer first." Another approach is to plan first, then execute: write out all the steps, run them, and re-plan if something fails. Interleaving adapts better to surprises; an upfront plan is easier to review, approve and speed up.
Many real agents mix the two.
4:16Control flow, reflection and error correction
Agents need control flow, just like programs. Steps can run in sequence, or in parallel, like looking up two orders at once. They can branch: if the item is eligible, offer a return, otherwise offer to escalate. And they can loop: retry with corrected input, or process each item in turn. Good agents also reflect. After each observation, they check: did the tool return an error? Does my planned answer match the policy and the tool results? If "order not found" comes back, a good agent notices the customer may have mistyped the number and asks, instead of guessing or giving up.
And every agent needs stopping rules: the goal is reached, a maximum number of steps or a cost limit is hit, or it's time to hand over to a person.
5:09How to design and choose tools
Tool design makes or breaks an agent. Models choose tools by reading their names and descriptions, so make them clear and distinct. Fewer, well-scoped tools beat a cluttered toolbox of near-duplicates. Use strict parameter schemas, and return helpful error messages the model can act on. And apply everything from episode sixty-three. Give each tool the least power it needs: the order lookup is read-only, and only for the logged-in customer's orders. Gate every write action: the customer confirms, a person approves refunds above a limit, and the system makes sure the same refund can't happen twice.
Treat tool results as data, since they may contain text planted by an attacker. Then evaluate tool use directly: did the agent pick the right tool, with the right arguments?
6:04Why long agent tasks fail: 0.95 to the power of n
Here's the sobering maths of agents. Suppose each step succeeds ninety-five percent of the time, which sounds good. Pause and predict: what's the chance of getting a ten-step task completely right? About sixty percent. Five steps: seventy-seven percent. Twenty steps: just thirty-six percent. Errors compound, because every step must succeed. Even at ninety-nine percent per step, a fifty-step task succeeds only about sixty percent of the time. So keep agent tasks as short as possible, make every step highly reliable, with good tools and validation, build in checkpoints and human hand-offs, and design agents to recover from errors rather than simply fail.
That's why Brightcart's first agent handles only order lookups and returns, not everything at once.
7:01Try it yourself: trace one agent run
Let's trace an agent run. The customer asks where their lamp is, and whether they can change the address. Step one: the agent looks up the order and learns the lamp is packed but not shipped. Step two: since it hasn't shipped, it calls the tool to update the address, and gets "success". Before step three, pause: why might it look the order up again?
To confirm with real data. A "success" message from one tool is good; reading the saved address back is better. Only then does it reply: the lamp hasn't shipped, the address is updated, and it's due to be dispatched tomorrow. Every claim in that reply is backed by an observation in the trace.
7:48What an agent run really costs
A single answer uses one call with about three thousand four hundred input tokens. An agent run takes six calls, and its context grows by about three hundred tokens at every step, as tool results and reasoning pile up. How many input tokens in total? Pause.
About twenty-four thousand nine hundred, over seven times a single call. Agents are powerful but expensive. So keep tool results compact, returning only the fields the agent needs, cap the number of steps, summarise long histories, and reuse the stable start of the prompt from cache.
8:32Parallel tool calls
Many models can request several tool calls at once. Suppose the agent needs the order, the warranty terms and the courier tracking, each taking three tenths of a second. One after another, that's almost a second. In parallel, it's three tenths. But only independent calls can run together: updating the address must wait until the lookup confirms the order hasn't shipped. Knowing which steps depend on which is part of good agent design.
9:03Writing a tool description the model can use
A tool description is a prompt too. A tool called "do thing", described as "handles orders", with one vague text parameter, invites mistakes. Compare: "create return: start a return for one item in one of the current customer's orders; use only after confirming the item and reason with the customer; returns the return ID." With a strict order-number format and a short list of allowed reasons. Clear names, clear purposes, clear limits, and the model chooses and fills in tools far more reliably.
9:39Plan first, or think as you go?
Agents can think as they go, deciding each step after seeing the last result, or plan first: write the whole plan, then execute it, and re-plan only if something fails. Thinking as you go is flexible when results are unpredictable. Planning first is easier to review: a plan can be checked against business rules before anything happens. Brightcart uses plans for anything that changes data, like returns and address changes, and the flexible loop for open-ended questions.
10:14Which tools need a human to approve?
Which tools can an agent use freely, and which need a confirmation? Looking up orders, searching policies, tracking parcels, updating an address, creating a return, issuing a large refund, closing an account. Pause and sort them.
The read-only tools can run automatically. Updating the address or creating a return should happen only after the customer confirms the details. A refund over fifty dollars or closing an account needs a person to approve it. The more irreversible the action, the more confirmation it needs.
10:53Stopping rules for agents
Agents need stopping rules. Without them, an agent can get stuck, calling the tracking tool over and over, getting "in transit" each time, and burning money. So set a maximum number of steps, a token or cost budget, a time limit, and a check for repeated identical calls. When a limit is reached, the agent shouldn't just crash: it should summarise what it found and hand over gracefully to a person.
11:23Do you even need an agent?
Finally, ask whether you need an agent at all. "Where's my order?" is a fixed workflow: look up the order, and have the model write a reply from the result. No loop, no planning, cheaper, faster and easier to test. "My kettle arrived broken, I've moved house, and I'd like a different colour instead" involves several dependent decisions: that's where an agent earns its cost. Use the simplest design that handles the task, and save agents for the problems that truly need them.
11:58Let code do the maths: calculator tools
Some tools don't fetch information; they extend what the model can do reliably. Remember the order total from episode forty-two: three mugs at twelve dollars and a kettle at forty-five with ten percent off the kettle. A model usually gets it right, but not always. An agent with a calculator tool sends the expression, gets back seventy-six point five, and writes "seventy-six dollars fifty" with complete confidence. The same goes for date arithmetic, like thirty days after the second of May. Let code do what code does perfectly.
12:34Myth vs Fact: more tools, more autonomy?
Myth: the best agents have as many tools and as much freedom as possible. Fact: every extra tool and every extra step is another way to fail, and another risk. Start with a narrow job and a few tools, measure carefully, and expand autonomy only as reliability is proven, the same "suggest, approve, act" path from episode fifty-three.
13:01One-minute recap
Let's recap. An agent is a model that works in a loop, using tools to perceive and act on an environment. Tools fetch knowledge, extend capabilities, or take write actions. With function calling, the model proposes a structured tool call, the system checks and executes it, and the result returns to the model. Agents interleave reasoning and acting, or plan first, using branches, loops, reflection and stopping rules. And because reliability compounds over steps, keep tasks short, tools well designed, and write actions gated.
One sentence to remember: the model proposes, the system disposes, and every step must earn its place.
13:47Next: why agents fail
Mission complete. Brightcart's first agent can look up orders, check eligibility and create returns, with confirmation and approval gates, a step limit, and a hand-off to Sana's team. But Dev has seen it go wrong in testing: stuck repeating the same tool call, and once, almost issuing a refund twice. Next: the ways agents fail, and how to evaluate them before they reach customers. See you on the map.