Skip to main content

ReAct Agent Pattern Explained with Examples: A Complete Guide for AI Agents

ReAct Agent Pattern Explained with Examples: A Complete Guide for AI Agents The ReAct Agent Pattern is one of the most important concepts in modern AI agent development. As businesses increasingly adopt AI automation, autonomous agents, and Large Language Models (LLMs) , understanding how an AI agent thinks, acts, and responds becomes essential. ReAct provides a simple but powerful approach: an AI agent combines Reasoning + Acting to solve problems step by step. In this guide, you will learn what the ReAct agent pattern is, how it works, its architecture, practical examples, benefits, limitations, and how developers use it to build intelligent AI agents. What Is the ReAct Agent Pattern? ReAct stands for: Re = Reasoning Act = Acting The ReAct agent pattern allows an AI model to alternate between: Understanding a problem Reasoning about what information is needed Taking an action or using a tool Observing the result Repeating the process until t...

How to Build Multi-Agent Systems with ChatGPT in 2026

Complete step-by-step guide · 2026

The 2026 stack is not Custom GPTs, Swarm, or Agent Builder. Those are deprecated or shutting down. Production work now sits on three paths: Workspace Agents, the OpenAI Agents SDK, and native GPT-5.6 Multi-agent.

Updated September 2026. OpenAI’s rule: start with one agent. Split into a team only when a single prompt and tool list starts failing.

Path Who it is for What to use
No-code / team workflows Ops, support, PMs Workspace Agents in ChatGPT
Code / products Engineers OpenAI Agents SDK (Python or JS)
Native parallel subagents Research, reviews, exploration Responses API Multi-agent (gpt-5.6, beta)

Contents

  1. What changed in 2026
  2. Do you need multiple agents?
  3. Pick a pattern
  4. Path A: Workspace Agents
  5. Path B: Agents SDK
  6. Path C: GPT-5.6 Multi-agent
  7. TypeScript
  8. A system you can ship
  9. Mistakes that kill systems
  10. Framework choice
  11. Build order
  12. Official starting points

1. What actually changed in 2026

  • Swarm is dead. Use the Agents SDK.
  • Agent Builder + Evals were deprecated June 3, 2026 and shut down November 30, 2026. Move visual canvas workflows to the Agents SDK (code) or Workspace Agents (no-code).
  • Custom GPTs are being phased out in favor of Workspace Agents.
  • Agents SDK (April 2026) added sandboxes, MCP, skills, AGENTS.md, shell + apply-patch tools, and long-horizon file work.
  • GPT-5.6 Multi-agent lets one model spawn a tree of parallel subagents inside a single Responses API call.

Skip 2025 tutorials that still say “Assistants API” or “Agent Builder.”

2. Decide if you even need multiple agents

OpenAI’s practical guide is explicit: a single well-tooled agent is usually better. Go multi-agent only when at least one of these is true:

  • The prompt is a pile of if/then branches you can’t maintain.
  • Tools overlap and the model keeps picking the wrong one (common around 10 overlapping tools).
  • You need separate evals (research vs draft vs QA).
  • You need parallelism (review a PR for correctness, security, and tests at once).
  • Specialists should own the reply (support triage to refunds vs sales vs outages).

If the job is “answer questions with a knowledge base + 3 APIs,” keep it as one agent.

3. Pick a pattern before you write code

Two patterns cover almost every ChatGPT multi-agent system.

A. Manager (agents as tools)

A manager stays in control. Specialists are called like functions. The manager owns the final answer.

Use when: you must combine several specialists, keep one voice, or put guardrails in one place.

User -> Manager -> [Researcher, Writer, Reviewer as tools] -> Manager answers

B. Handoffs (decentralized)

A triage agent routes. The specialist takes over the turn and talks to the user.

Use when: routing is the workflow (support, tutoring, domain specialists).

User -> Triage -> History Tutor (now owns the conversation)

You can mix them: triage hands off to Support, Support calls a Refund agent as a tool.

There is a third option: orchestrate in code (chain, loop, asyncio.gather). Use that when the graph should be deterministic, not “the LLM decides.”

4. Path A — No-code: Workspace Agents in ChatGPT

For team workflows that should not become an engineering project.

  1. In ChatGPT (Business / Enterprise), open the agent builder chat.
  2. Describe in plain language: the job, what “done” looks like, and constraints.
  3. Attach approved connectors (Gmail, Slack, Drive, etc.).
  4. Set a trigger: on-demand, or scheduled.
  5. Add action constraints (“only email @yourcompany.com”).
  6. Publish to the workspace.

Good for: daily escalation summaries, CRM cleanup, research briefs, recurring reports.

Not good for: custom products, private APIs, strict evals, or anything that must live in your codebase.

5. Path B — Code: Agents SDK (the real 2026 path)

Python 3.10+ or Node 22+. This is the path OpenAI recommends for anything that should survive Agent Builder’s shutdown.

Step 1 — Install

Python

python -m venv .venv
source .venv/bin/activate
pip install openai-agents
export OPENAI_API_KEY=sk-...

TypeScript

npm install @openai/agents zod

Step 2 — One agent first

import asyncio
from agents import Agent, Runner

agent = Agent(
    name="History Tutor",
    instructions="You answer history questions clearly and concisely.",
)

async def main():
    result = await Runner.run(agent, "When did the Roman Empire fall?")
    print(result.final_output)

asyncio.run(main())

Confirm this works before you add teammates. Most “multi-agent” bugs are actually “the first agent was never good.”

Step 3 — Give it tools

Three kinds of tools:

  1. Data — search, DB, files, RAG
  2. Action — send email, update CRM, refund
  3. Orchestration — other agents, exposed as tools
from agents import Agent, Runner, WebSearchTool, function_tool
import datetime

@function_tool
def save_results(output: str) -> str:
    """Persist a research snippet."""
    return f"Saved at {datetime.datetime.now().isoformat()}"

search_agent = Agent(
    name="Search agent",
    instructions="Search the internet and save results when asked.",
    tools=[WebSearchTool(), save_results],
)

Hosted tools (WebSearchTool, file search, computer use, MCP servers) attach the same way. MCP is the 2026 default for “connect anything.”

Step 4 — Split specialists

Each agent gets one job, a short instruction, and only the tools it needs.

from agents import Agent

researcher = Agent(
    name="Researcher",
    instructions="Gather facts. Cite sources. Do not write the final article. Return bullet findings only.",
    tools=[WebSearchTool()],
)

writer = Agent(
    name="Writer",
    instructions="Turn research bullets into a clear article. Do not invent facts that were not in the research.",
)

reviewer = Agent(
    name="Reviewer",
    instructions="Check accuracy, structure, and unsupported claims. Return either APPROVE or a numbered list of required fixes.",
)

Step 5 — Manager pattern (agents as tools)

from agents import Agent, Runner

manager = Agent(
    name="Editor in Chief",
    instructions="You produce a finished article. 1) Call research for facts. 2) Call write_draft with those facts. 3) Call review_draft. 4) If review is not APPROVE, send fixes back to write_draft. You own the final answer to the user.",
    tools=[
        researcher.as_tool(tool_name="research", tool_description="Collect sourced facts for a topic"),
        writer.as_tool(tool_name="write_draft", tool_description="Draft an article from research bullets"),
        reviewer.as_tool(tool_name="review_draft", tool_description="Approve or request fixes"),
    ],
)

result = await Runner.run(manager, "Write a 600-word explainer on MCP.")
print(result.final_output)

This is the pattern you want for content pipelines, research reports, and anything where one voice should come back.

Step 6 — Handoff pattern (specialist takes over)

from agents import Agent, Runner

history_tutor = Agent(
    name="History Tutor",
    handoff_description="Specialist for historical questions",
    instructions="Answer history questions clearly and concisely.",
)

math_tutor = Agent(
    name="Math Tutor",
    handoff_description="Specialist for math questions",
    instructions="Explain math step by step with worked examples.",
)

triage = Agent(
    name="Triage Agent",
    instructions="Route each homework question to the right specialist.",
    handoffs=[history_tutor, math_tutor],
)

result = await Runner.run(triage, "Who was the first US president?")
print(result.final_output)
print("Answered by:", result.last_agent.name)

Same idea for support: Technical / Sales / Orders.

Step 7 — Orchestrate in code when the graph is known

Don’t make the LLM re-decide a pipeline you already know.

research = await Runner.run(researcher, topic)
draft = await Runner.run(writer, research.final_output)

for _ in range(3):
    critique = await Runner.run(reviewer, draft.final_output)
    if "APPROVE" in critique.final_output:
        break
    draft = await Runner.run(writer, f"{draft.final_output}\n\nFixes:\n{critique.final_output}")

Independent work in parallel:

correctness, security, tests = await asyncio.gather(
    Runner.run(correctness_agent, diff),
    Runner.run(security_agent, diff),
    Runner.run(tests_agent, diff),
)

Step 8 — Guardrails (non-optional in production)

Input/output guardrails run in parallel with the agent and fail fast.

from pydantic import BaseModel
from agents import Agent, Runner, input_guardrail, Guardrail, GuardrailFunctionOutput

class ChurnDetectionOutput(BaseModel):
    is_churn_risk: bool
    reasoning: str

detector = Agent(
    name="Churn Detection",
    instructions="Is this user about to churn?",
    output_type=ChurnDetectionOutput,
)

@input_guardrail
async def churn_tripwire(ctx, agent, input):
    result = await Runner.run(detector, input, context=ctx.context)
    return GuardrailFunctionOutput(
        output_info=result.final_output,
        tripwire_triggered=result.final_output.is_churn_risk,
    )

support = Agent(
    name="Customer Support",
    instructions="Help the customer.",
    input_guardrails=[Guardrail(guardrail_function=churn_tripwire)],
)
  • PII filters
  • topic / jailbreak classifiers
  • tool risk ratings (high-risk tools pause for a human)
  • output brand/policy checks

High-risk actions (refunds, emails, deletes) should pause for approval, not auto-fire.

Step 9 — Memory and sessions

  • SDK Session — SDK keeps history
  • conversation_id / previous_response_id — server-side OpenAI state
  • result.to_input_list() — you own the history

Share memory by a conversation id when a manager calls specialists, so they don’t each start blank.

Step 10 — Sandbox agents (files, code, long jobs)

April 2026 SDK: give an agent a real workspace when it needs to read files, run commands, or edit code. Use SandboxAgent plus a sandbox client (UnixLocalSandboxClient, Modal, E2B, etc.). Regular Agent is for chat/tools. Sandbox is for Codex-style work.

Step 11 — Trace, eval, then shrink models

  1. Prototype on the strongest model you have.
  2. Watch traces in the OpenAI traces dashboard — every tool call, handoff, and guardrail.
  3. Write evals per specialist (research citations, draft faithfulness, review catch-rate).
  4. Once quality holds, drop specialists to cheaper/faster models. Keep the manager on a stronger one.

6. Path C — Native Multi-agent on GPT-5.6

When the task fans out (review a PR three ways, research 8 sources, explore a repo), you don’t have to hand-define specialists.

response = client.beta.responses.create(
    model="gpt-5.6-sol",
    input="Review this diff with three agents: correctness, security, missing tests.",
    multi_agent={"enabled": True, "max_concurrent_subagents": 3},
    betas=["responses_multi_agent=v1"],
)

The root agent (/root) spawns /root/researcher, /root/reviewer, etc. They share the model and tools, keep separate context, and the API handles spawn / message / wait / interrupt.

Use this when work is independent and parallel. Use the Agents SDK when you need named specialists, different tools, guardrails, or a deterministic graph.

7. TypeScript equivalent

import { Agent, run } from "@openai/agents";

const math = new Agent({
  name: "Math Tutor",
  handoffDescription: "Math questions",
  instructions: "Explain math step by step.",
});

const triage = new Agent({
  name: "Triage",
  instructions: "Route homework to the right specialist.",
  handoffs: [math],
});

const result = await run(triage, "What is 17 * 19?");
console.log(result.finalOutput);

Same primitives: Agent, tools, handoffs, asTool(), guardrails, sessions.

8. A complete system you can actually ship

Example: customer support — the canonical 2026 multi-agent app.

  1. Triage agent (handoffs) — classifies intent.
  2. Technical support — knowledge-base search.
  3. Sales — catalog + quote tools.
  4. Orders — tracking + refunds (refunds require human approval).
  5. Input guardrails — jailbreak, PII, churn escalation.
  6. Session — conversation history across turns.
  7. Tracing + evals — routing accuracy, CSAT proxy, refund false-positives.

That is a real architecture. A “crew of 8 agents that debate” is usually a demo.

9. Mistakes that still kill these systems in 2026

  1. Too many agents too soon. One agent + tools until it fails.
  2. Overlapping tools/roles. If two agents can both “search” and “write,” they thrash.
  3. Handoffs when you needed a manager. User sees the specialist’s raw voice; the manager never synthesizes.
  4. No stop condition. Critique loops without APPROVE or a max-iteration cap.
  5. No human gate on irreversible actions.
  6. Shared mutable state across parallel subagents. Native multi-agent is the wrong fit there.
  7. Building on Agent Builder / Assistants API in late 2026.

10. Framework choice if you’re not all-in on OpenAI

If the models must be mix-and-match, or you need a durable state machine:

Need Reach for
OpenAI-native, fastest to a working team Agents SDK
Explicit graph, checkpoints, HITL, audit LangGraph
Role-based “crew” prototype CrewAI
Azure / .NET Microsoft Agent Framework
Claude-only harness Claude Agent SDK

For “multi-agent with ChatGPT,” the Agents SDK is the default. LangGraph wins when the workflow is a state machine you must control.

11. Build order (do this, in this order)

  1. Write the job as a single agent. Measure it.
  2. List tools: data, action, none extra.
  3. Split only the roles that actually conflict.
  4. Choose manager vs handoff vs code chain.
  5. Add guardrails on the user-facing agent first.
  6. Turn on tracing. Write 20 golden tasks.
  7. Add HITL for high-risk tools.
  8. Only then: sessions, sandboxes, MCP, parallelism.

Official starting points

Comments

Popular posts from this blog

AI Automation Slack Bots: The Ultimate Guide to Boost Workplace Productivity

AI Automation Slack Bots: The Ultimate Guide to Boost Workplace Productivity Welcome to the ultimate guide on AI Automation Slack Bots — your one-stop resource to transform how your team communicates, collaborates, and automates repetitive tasks inside Slack. In today’s fast-moving digital workplace, leveraging automation through Slack bots powered by artificial intelligence can dramatically streamline workflows and increase efficiency. What Are AI Automation Slack Bots? AI Automation Slack Bots are intelligent programs integrated into the Slack communication platform that perform tasks, answer queries, and automate workflows using artificial intelligence and APIs. They connect with external tools such as Google Workspace, Trello, Notion, Make.com, or Zapier to perform automated actions without leaving the Slack interface. Example Functionality of Slack Bots Automatically respond to repetitive team queries (e.g., HR policies, contact listings, meeting schedules). Se...

AI Automation Examples for Supply Chain Excel: Save 20+ Hours Weekly in 2026

AI Automation Examples for Supply Chain Excel: Save 20+ Hours Weekly in 2026 Struggling with manual inventory tracking, demand forecasting, and supplier reports in Excel? AI automation examples for supply chain Excel transform these tedious tasks into automated workflows using free tools like ChatGPT, Power Automate, and Copilot—no coding required. Supply chain pros using AI in Excel report 30% faster operations and 15% lower inventory costs, making it essential for 2026 efficiency. [web:81] [web:77] This ultimate guide delivers 15+ real-world examples tailored for procurement managers handling SAP data exports and Kaizen improvements. Why AI Automation Revolutionizes Supply Chain Excel Workflows Excel remains the go-to for 70% of supply chain teams due to its flexibility, but manual formulas waste hours on stock-ins/outs and reorder alerts. AI automation examples for supply chain Excel leverage LLMs like Gemini and DeepSeek to generate VBA scripts, predict shortages, and integr...

The Definitive Guide to Budget-Friendly AI Automation Platforms for Startups in 2026

The Definitive Guide to Budget-Friendly AI Automation Platforms for Startups in 2026 Mastering Workday Prism, Extend, and AI Gateways: A Zero-to-Hero Architecture Deep-Dive Welcome to the 2026 frontier of business operations. If you are a startup founder, an operations lead, or a curious technologist, you have arrived at the definitive manual for scaling your company without scaling your headcount. In the past, "Enterprise-grade automation" was a luxury reserved for the Fortune 500. Today, the "Great Compression" of technology has made the most powerful tools—like Workday Prism and AI Gateways—accessible to lean, budget-conscious startups. In this guide, we aren't just looking at tools; we are building a digital nervous system . We will explore how to orchestrate data, build custom apps, and govern AI models with surgical precision. Let’s dive into the architecture of the future. §01 · The 2026 Automation Landscape: Why Startups Must Pivot By 2026, the ga...