Learn & Build Agents

    ↑ ↓ to choose · Enter to open · Esc to close

    02 Building the agentLesson 2 of 811 minBeginnerHelps to have seen:Tools and the loop

    Workflow or agent

    Calls to the LLM—
    Who decides the path—
    Solved everything?—
    • + customer
    • + message with two requests
    Customerin the store chat"4821 never arrived""and I want my money back"
    LLMcodedataperson

    Step 1 of 9: A customer wants two things in one sentence

    You will learn
    • The difference between a workflow and an agent
    • Where the fixed path fails silently
    • What the agent solves, and what it costs
    • How to combine the two
    • Why the rule that matters lives in code
    In the lab

    Workflow vs agent: correct resolution and calls per conversation, across the store's 50 test conversations

    Coming soon: I will measure this on the example agent and publish the number with the report.

    The whole lesson as textEvery step, to read at once, search or print.
    1. A customer wants two things in one sentence

      This arrives in the store chat: "My order 4821 never arrived and I want my money back." It is one of the 50 test messages.

      Answering takes looking at the order, checking the policy and, maybe, creating a refund. In the previous lesson, the loop did that. The question now: did it need an agent, or would a fixed path do?

      Before choosing the architecture, look at the messages: how many topics, and whether you can know the order of the steps in advance.

    2. Who decides the path

      In a , the path is written in code. The may show up in some steps, but does not choose the next one.

      In an , the LLM decides on its own what to do, which to call and when to stop. It is the loop from the previous lesson, let loose.

      The right question is who decides the path: your code or the model.

    3. Option 1: classify and send to a path

      An LLM classifies the message into a box: tracking, exchange or other. The router, which is code, sends each box to a fixed path.

      It is cheap and predictable. But the message has two requests and the classifier picks only one: the customer gets the tracking, and the refund disappears without a word.

      A workflow is great when each message fits in a box. When it does not, it fails silently.

    4. Option 2: an LLM with tools, in a loop

      The agent receives the message and chooses the order: it looks up the order, reads the policy and, since the delay is past 5 days, creates the refund. Then it answers both parts.

      Nobody wrote that path in advance. It emerges mid-conversation, from what each tool returns.

      The agent handles mixed requests because it decides the order on the spot.

    5. Freedom costs calls

      Each agent turn is a call to the model with the whole conversation (lesson Tokens, context and cost). For order 4821 it took four; the workflow did one. And the path can change from one run to the next (lesson Why the answer varies).

      Anthropic sums up the trade-off: agentic systems often trade latency and cost for better task performance. It is worth it when the extra performance shows up.

      Start with the simplest thing and move up to an agent only where the simple thing fails.

    6. Both together: fixed path first

      In practice, it is not one or the other. The classifier gets a new box, "more than one topic", and the router sends that box to the agent. The rest stays on the fixed paths.

      The OpenAI guide points to where an agent tends to be worth it: complex decisions, rules that are hard to maintain in code and a lot of free text to interpret.

      Fixed path where the order is known; an agent only where it is not.

    7. The mistake that compounds along the way

      Another test message: "4838 is late and so is 4850. I want to cancel both." 4838 is 7 days late; 4850 is 5, still within tolerance.

      The agent reads "late", reads the policy and refunds both. One wrong step at the start becomes money going out at the end. The freer the path, the more room for the mistake to add up.

      Let the agent run the conversation, and keep the rule that costs money in code.

    8. Customer support is a good case, and a hard one

      Anthropic cites customer support as a good case for agents: the conversation is open, the actions have tools and success is measured in resolution. Some vendors only charge for resolved conversations.

      And it is hard: on τ-bench, a retail customer support test with tools and policy, the best agents of 2024, like gpt-4o, solved less than half of the tasks.

      An agent pays off where the conversation is open, and only if you measure resolution.

    9. Fixed path first, agent for the rest

      Workflow: the code decides the path, with few calls and always the same. Agent: the model decides the steps and handles what does not fit in a box, with more calls.

      How to check in your case: run both builds on the same and compare correct resolution, calls per conversation and times a person was called.

      Who decides the path is the choice. The eval shows whether it was worth it.

    Questions in this lesson

    What is the core difference between a workflow and an agent?
    Who decides the next step: the code or the model. Both can use the same model. What changes is who chooses the path.
    "Where is 4805?" Which build spends less?
    Workflow: one call and a fixed path. A known path calls for a workflow. The agent gets it right too, with more calls.
    The agent refunded an order still within tolerance. Where does the fix that holds live?
    In the refund tool, checking the rule before paying. The model's decision can be wrong. The rule that costs money lives in code.