AI Agents & Agentic Workflows
An agent is a loop: the model decides an action, the action runs, the result feeds back in, repeat.
state = {"goal": user_goal, "history": []}
while not done(state):
action = model.decide_next_action(state) # a tool call, or "finish"
if action.type == "finish":
return action.result
result = execute(action) # your code runs it -- see Tool Calling
state["history"].append((action, result))
ReAct prompts the model to explicitly alternate between a reasoning step ("Thought: ...") and an action step ("Action: call tool X with args Y"), observing the result before the next thought. Making the reasoning explicit and visible in the transcript, rather than implicit, measurably improves an agent's ability to recover from a tool call that returned something unexpected — the model has a place to notice and reason about the surprise before deciding what to do next.
Thought: I need the current weather before I can recommend clothing.
Action: get_weather(city="Austin")
Observation: {"temp_f": 98, "condition": "sunny"}
Thought: That's hot -- I should recommend light clothing and hydration.
Action: finish("It's 98°F and sunny in Austin — wear light, breathable clothing...")
| Reactive (decide one step at a time) | Plan-then-execute | |
|---|---|---|
| Upfront cost | Lower — no separate planning call | Higher — a dedicated planning step before execution starts |
| Good fit for | Short tasks, or tasks where later steps genuinely depend on earlier results | Longer multi-step tasks where seeing the whole plan upfront catches ordering mistakes early |
| Failure mode | Can wander/loop without a global view of the goal | A plan made with stale information can go wrong if the situation changes mid-execution |
A single agent with a well-scoped tool set and a well-formed prompt handles most tasks; splitting into multiple cooperating agents (e.g. a planner, a researcher, a critic) adds coordination overhead, more places for context to be lost between agents, and more total tokens spent. It tends to genuinely pay off when a task has clearly separable sub-roles that benefit from different tool access, different context, or a distinct "critic" pass reviewing another agent's output — not as a default architecture for tasks a single well-prompted agent could already handle.