Lesson 1 of 5 Building Agents and Tool Integrations

Understanding Agents and the ReAct Pattern

This lesson explains how agents, in which an FM decides which actions to take using tools and observing results, handle open-ended, multi-step tasks that fixed workflows cannot, at the cost of predictability.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the agent loop.
  • Explain the ReAct pattern and planning.
  • Choose between an agent and a workflow.

The agent loop

An agent combines a model, instructions, tools and memory. Given a goal, the model decides whether it can answer directly or needs a tool. If it needs a tool, it emits a structured tool call; the application runs the tool and returns the result; the model reads the result and decides the next step. The loop continues until the model produces a final answer or a stopping condition ends it. Because the model chooses the steps, the same agent can handle many variations of a task without a predefined workflow.

ReAct and planning

Agents need a way to decide what to do next based on what they have learned so far. The ReAct (reason and act) pattern provides one by interleaving three elements in a loop: a thought, in which the model reasons about what to do next; an action, which is a tool call; and an observation, the tool's result, which informs the next thought. Writing out the reasoning improves tool choice and makes the agent's behaviour traceable when something goes wrong.

Two variants are common. In plan-and-execute, the model first writes a complete plan and then carries out each step, revising the plan when an observation shows it will not work; this suits longer tasks where a coherent strategy matters. In reflection, the agent reviews its result against the task before finishing and corrects mistakes, which improves quality at the cost of extra model calls.

The following diagram shows the thought, action and observation loop.

The ReAct loop. The model writes a thought about what to do next, takes an action by calling a tool, and reads the observation, the tool's result, before the next thought. The loop ends when the model has enough to give a final answer or a stopping condition ends it.
Plan-and-execute writes a plan first and then runs its steps.
Sort into groups

Thought, action or observation?

Exam skills 2.1.2

Label each line from an agent's ReAct trace.

Log in to try this activity Interactive activities are free with an account.

Agents versus workflows

Not every multi-step task needs an agent. A workflow, such as a Step Functions state machine or a Bedrock Flow, follows predefined steps and is predictable, testable and cheap. An agent is flexible but less predictable, uses more tokens, and needs safeguards such as iteration limits, least privilege tools and human approval for sensitive actions. A common design uses workflows for the fixed parts of a process and an agent only where the path depends on the situation. The following table compares them.

Workflow
Who decides the stepsDeveloper, in advance
PredictabilityHigh
Handles novel variationsPoorly
Cost per taskLower and predictable
Safeguards neededStandard error handling
Agent
Who decides the stepsThe model, at run time
PredictabilityLower
Handles novel variationsWell
Cost per taskHigher and variable
Safeguards neededIteration limits, tool permissions, approvals

The following diagram compares the two projects.

Choosing between a workflow and an agent. Onboarding always runs the same steps in the same order and needs auditability, so a Step Functions workflow fits. Employee questions are open-ended and need different tools each time, so an agent with read-only tools fits, with safeguards such as iteration limits.
Many designs use a workflow for the fixed parts and an agent only where the path varies.
Scenario questions

Agent or workflow?

Exam skills 2.1.2 · 2.1.1

Decide whether each process needs an agent or a predefined workflow.

Log in to try this activity Interactive activities are free with an account.
Worked example

Agent or workflow?

An HR team wants to automate onboarding: create accounts, assign a laptop, enrol benefits and send a welcome email, always in that order. A second project should answer employees' free-form questions that may require looking up their leave balance, policies or payslips.

Onboarding has fixed steps and needs auditability, so a Step Functions workflow fits. The employee assistant faces open-ended questions that need different tools, so an agent with read-only tools fits.

Check yourself

What does the ReAct pattern interleave?

Show answer

Thought (reasoning), action (a tool call) and observation (the tool's result), repeated until the task is done.

Exam Tips

Remember for the exam

  • Agent loop: model chooses tool, application runs it, model observes, repeat.
  • ReAct interleaves thought, action and observation.
  • Fixed steps: workflow. Situation-dependent steps: agent.
  • Agents need iteration limits, least privilege tools and approvals.