Free sample lesson · Building LLM Applications: Architecture to Production

Workflows Before Agents

Each agent step can fail. What happens to a ten-step task?

Lesson 1 of the Wondering course Building LLM Applications: Architecture to Production

Ten Steps, One Outcome

Ten steps, each 90% likely to succeed. How often does the whole task finish?

If failures are independent, all ten succeed only about 35%; two steps succeed about 81%. Each extra step multiplies another chance of failure.[[2]](https://applied-llms.org/)

That makes architecture practical: more model-chosen steps can mean lower reliability, plus more cost and latency. Start by asking who truly needs to choose the next action.

Who must choose the next action?

Start With One Call

An invoice arrives. If one model call can extract it into a schema, stop there.

An augmented LLM is one call enhanced with retrieval, tools, or memory. Many applications need only an optimized call with context and examples.[[1]](https://www.anthropic.com/engineering/building-effective-agents)

What augments one call
  • Augmented LLM: One call, enhanced.
  • Retrieval
  • Tools
  • Memory

Call the provider API directly at first, so prompts and responses remain visible while you debug.[[1]](https://www.anthropic.com/engineering/building-effective-agents) Skip components the feature can work without.[[3]](https://huyenchip.com/2024/07/25/genai-platform.html)

Code Controls a Workflow

A support ticket follows a fixed sequence: classify it, retrieve policy text only for billing questions, then draft a reply.

Support ticket workflow
  • Ticket arrives
  • Classify ticket
  • Billing question?: Code, not the model, checks the classification.
  • Retrieve policy text
  • Draft reply
  • Yes
  • No

That is a workflow because application code fixes the path. Tool use does not change the classification; code still decides what happens next.

Workflows use predefined code paths to orchestrate models and tools.[[1]](https://www.anthropic.com/engineering/building-effective-agents) They fit jobs whose sequence you can specify and inspect.

The Model Controls an Agent

A coding assistant opens files, edits them, runs tests, reads failures, and chooses whether to try again.

That is an agent: the model chooses each next action from environmental feedback rather than following a fixed code path.[[1]](https://www.anthropic.com/engineering/building-effective-agents)

Diagram: Human connects by a dashed two-way arrow to an LLM Call box. Arrows labeled Action and Feedback loop between the LLM Call and Environment. A dashed arrow leads down from the LLM Call to Stop.

In an agent, the model picks each action from the environment's feedback until something tells it to stop. · Anthropic, "Building effective agents" (Erik Schluntz and Barry Zhang)

The loop needs a stopping condition, such as a maximum iteration count. Without one, costs and compounding errors can keep growing.[[1]](https://www.anthropic.com/engineering/building-effective-agents)

Failures Multiply Across Steps

At 90% success per step, ten independent steps do not produce 90% task success.

Multiply the probabilities: $$0.9^{10} \approx 0.35$$. The complete chain succeeds about 35%; with two steps, it is about 81%.[[2]](https://applied-llms.org/)

Same step accuracy, different task success
  • Two steps: 0.9 multiplied twice.
  • Ten steps: 0.9 multiplied ten times.

This estimate assumes independent steps. Its design lesson still matters: reduce autonomous steps when possible, because users experience end-to-end success.

Plan Once, Execute in Code

Your model proposes a plan with ten actions. Must it choose again after every action?

Often, no. Put the plan into structured data, then let deterministic code execute the known actions. This reduces model-chosen steps and keeps execution inspectable.[[2]](https://applied-llms.org/)

Evaluate completion of the whole task, not only isolated steps. Add a hard stopping condition wherever feedback can send the model around the loop.[[1]](https://www.anthropic.com/engineering/building-effective-agents)[[2]](https://applied-llms.org/)

Plan once, execute in code
  • Propose plan: The model proposes a plan of actions once.
  • Structure it: Put the plan into structured data.
  • Execute in code: Deterministic code runs the known actions, keeping execution inspectable.
  • Bound loops: Add a hard stopping condition wherever feedback can loop the model.
  • Evaluate whole task: Measure completion of the whole task, not only isolated steps.

Choose the Lowest Level

A feature needs policy text and a drafted answer. Should the model control the entire process?

Choose one augmented call when one call is enough. Use a workflow when code can fix the sequence; use an agent when the path is unpredictable and environmental feedback must guide each attempt.[[1]](https://www.anthropic.com/engineering/building-effective-agents)

Pick the lowest level that works
  • Augmented call
  • Workflow
  • Agent

Move up only when evaluation shows the simpler design cannot work. A basic end-to-end setup looks like this:

  • Write test cases for the whole task. Each case is an input plus an assertion about the final output. For example, a support assistant's case might check that the drafted reply cites the right billing policy.
  • Run the same cases on each design and measure whole-task success, along with cost and latency, not just the accuracy of individual steps.
  • Track the results. Collect metrics along with the versions of your tests and prompts so you can analyze them over time.[[5]](https://hamel.dev/blog/posts/evals/)
  • Log traces, the record of the sequence of steps a request took, so you can see where a failing run broke.[[5]](https://hamel.dev/blog/posts/evals/)

A simpler design "cannot work" when it keeps failing these cases and a more complex one demonstrably improves outcomes. Each added model loop must justify its reliability, cost, and latency tradeoff.[[1]](https://www.anthropic.com/engineering/building-effective-agents)[[4]](https://developers.openai.com/api/docs/guides/latency-optimization.md)

Check yourself

A support-ticket feature always classifies a ticket, retrieves policy text for billing questions, and drafts a reply using application-defined branches. Is this a workflow?

  • Yes, it is a workflow
  • No, it is an agent

Answer: Yes, it is a workflow

Yes. The application code fixes the sequence and branching. Calling a retrieval tool does not make the feature an agent; the key question is who chooses the next step.

For an invoice extractor that needs only one model call with retrieval, use an _____. For a support feature whose sequence is fixed by application code, use a _____. For a coding assistant that selects actions from test feedback, use an _____.

Answer: For an invoice extractor that needs only one model call with retrieval, use an augmented LLM. For a support feature whose sequence is fixed by application code, use a workflow. For a coding assistant that selects actions from test feedback, use an agent.

An augmented LLM enhances one call with retrieval, tools, or memory. A workflow uses a code-defined path. An agent lets the model choose actions from environmental feedback.

Each step in a ten-step task independently succeeds with probability 0.90. What is the approximate probability that the entire task succeeds?

  • 35%
  • 50%
  • 81%
  • 90%

Answer: 35%

Independent steps multiply: $$0.9^{10} \approx 0.35$$. Thus, all ten steps succeed only about 35% of the time, not 90%.

Keep going

This is lesson 1 of 10 in Building LLM Applications: Architecture to Production. Next up:

  1. Five Workflow Patterns
  2. Structured Outputs That Hold
  3. Designing Tools the Model Can Use
  4. Evals Built from Real Failures
  5. Graders and Judges That Hold Up

Start this course free

Wondering turns any topic into short lessons you can read, watch, or listen to, with practice questions and an AI tutor.