CreateAgent vs CreateReactAgent
LangGraphGo provides two ways to build prebuilt agents: CreateAgent and
CreateReactAgent. While both create ReAct-based agents, they differ in flexibility and
configuration options.
1. CreateReactAgent
Introduction
CreateReactAgent is the most basic builder. It is designed to quickly start a ReAct Agent
with minimal configuration.
Features
- Simple to use: Only requires LLM model and tool list.
- Zero configuration: Does not support custom system prompts or state modification logic.
- Rapid prototyping: Suitable for testing tools or building simple demos.
Code Example
// Only requires model and tools
agent, err := prebuilt.CreateReactAgent(model, tools)
2. CreateAgent
Introduction
CreateAgent is a more advanced and flexible builder. It uses the Option pattern common in
Go, allowing fine-grained control over Agent behavior.
Configuration Options
WithSystemMessage(string): Set the System Prompt to define the Agent's role and guidelines.WithStateModifier(func): Allows custom modification of message history before sending to the model (e.g., filtering out old history or adding specific context).WithCheckpointer(CheckpointStore): Set a checkpointer to enable state persistence and memory.
Use Cases
- Production applications.
- Scenarios requiring specific roles (e.g., "You are a helpful assistant...").
- Scenarios requiring management of long conversation history or persistent state.
Code Example
// Configure using Option pattern
agent, err := prebuilt.CreateAgent(
model,
tools,
prebuilt.WithSystemMessage("You are a professional Golang programming assistant."),
prebuilt.WithCheckpointer(checkpointer),
)
3. Comparison Summary
| Feature | CreateReactAgent | CreateAgent |
|---|---|---|
| Configuration Flexibility | Low | High |
| System Prompt | Not Supported | Supported (WithSystemMessage) |
| State Persistence | Not Supported (Default) | Supported (WithCheckpointer) |
| Recommended Use | Simple Testing, Prototyping | Production, Complex Apps |