Agent Patterns, Cost, and Context

The basic loop stays the same, but agents can organise it in different ways.

The design choice is how far ahead the model plans and how much context each new step must carry.

Intuition

An agent appears to remember a run, but the model itself is normally stateless. On every step, the application sends the goal, available tools, and relevant history again.

At step eight, the prompt may contain steps one through seven. The system pays for old information repeatedly.

Why cost grows quickly

Step 1 sends: goal + tools
Step 2 sends: goal + tools + step 1
Step 3 sends: goal + tools + steps 1–2
...
Step 8 sends: goal + tools + steps 1–7

Each step pays for much of the earlier run again. Doubling the step budget can more than double the token bill.

Verbose tool output is often the real limit. A flight API returning 500 options or a retrieval tool returning complete documents can fill the context window before the agent reaches its step limit.

Context controls

Three shapes of the same loop

1. ReAct: decide one step at a time

ReAct interleaves reasoning and action:

flowchart LR T1[Think] --> A1[Act] A1 --> O1[Observe] O1 --> T2[Think again] T2 --> A2[Act again]

Paris example:

THINK  Need the policy first
ACT    retrieve_policy()
OBS    Economy; book at least 7 days ahead
THINK  Now search allowed fares
ACT    search_flights(15 Aug)
OBS    Departure is only 5 days away
THINK  Shift the dates

Strengths

Weakness

Use it for the Paris loop and other tasks where each result strongly determines the next step.

2. Plan-and-execute: plan first, then run

The model drafts the larger plan before executing it:

flowchart LR P[Plan steps 1–7] --> E[Execute steps] E --> C{Failure?} C -->|No| D[Done] C -->|Yes| R[Replan affected steps] R --> E

Paris example:

PLAN  1 policy · 2 flights · 3 hotels · 4 budget · 5 compliance
EXEC  Run the plan
FAIL  Compliance is two days short
PLAN  Replan the flight and later steps
EXEC  Run the changed tail

Strengths

Weakness

Use it for deep research or work where several planned searches can happen together.

3. Reflection: critique and revise the output

Reflection loops on a draft rather than on the whole task:

flowchart LR D[Draft] --> C[Critique] C --> Q{Good enough?} Q -->|No| R[Revise] R --> C Q -->|Yes| F[Final output]

Paris example:

DRAFT     Four-day itinerary
CRITIQUE  Departure is in 5 days; policy needs 7
REVISE    Move departure to 22 Aug
CRITIQUE  New fare ₹34,900; compliant
DONE      Present the itinerary

Strength

Weakness

Use it when final output quality matters enough to pay for another pass.

Choosing a pattern

Need Good starting pattern
Short task, next action depends on latest result ReAct
Long task with parallel or predictable substeps Plan-and-execute
Improve a draft, report, itinerary, or code change Reflection
High-stakes work Any pattern plus deterministic checks and human approval

Patterns can be combined. A plan-and-execute agent may use ReAct inside one difficult step and reflection for the final report.

What goes wrong

One-line summary

ReAct decides one step at a time, plan-and-execute prepares a route, reflection revises a draft, and all three need disciplined context management.

Key terms