Skip to main content
In this cookbook, you’ll learn how to build a ReAct-style agent using OpenAI’s GPT models and trace its reasoning, tool calls, and answers using Maxim’s observability SDK. This approach allows you to visualize the agent’s step-by-step reasoning, tool usage, and final answers in the Maxim dashboard.

Prerequisites

1. Load Environment Variables

2. Set Up Maxim Logger and OpenAI Client

3. Define the ReAct Agent Class

The agent follows the ReAct pattern: it reasons, chooses actions (tool calls), observes results, and iterates until it produces an answer.

4. Define the System Prompt (ReAct Format)

The system prompt instructs the agent to reason, act, pause, observe, and answer, using available tools.

5. Implement Tool Functions

6. Set Up Maxim Session and Trace

7. Run the ReAct Agent with Tracing

The agent will loop, reasoning and calling tools, and each step will be traced as a span in Maxim.

8. Example Usage

9. Visualize in Maxim

Each reasoning step, tool call, and answer is now visible as a trace and spans in your Maxim dashboard.
For more details, see the Maxim Python SDK documentation.

Resources

Cookbook Code

Python Notebook for ReAct Agent & Maxim