The agent implementations in llamaindex/agent are deprecated. Use @llamaindex/workflow for building agentic workflows.
Migration Guide
Instead of using ReActAgent, migrate to workflow-based agents:
Before (Deprecated)
import { ReActAgent } from "llamaindex/agent";
import { OpenAI } from "@llamaindex/openai";
const agent = new ReActAgent({
llm: new OpenAI({ model: "gpt-4" }),
tools: [weatherTool, calculatorTool]
});
const response = await agent.chat({ message: "What's the weather?" });
After (Recommended)
import { Workflow, StartEvent, StopEvent } from "@llamaindex/workflow";
import { OpenAI } from "@llamaindex/openai";
class AgentWorkflow extends Workflow {
async run(ctx: Context, ev: StartEvent) {
const llm = new OpenAI({ model: "gpt-4" });
const response = await llm.chat({
messages: [{ role: "user", content: ev.message }],
tools: [weatherTool, calculatorTool]
});
return new StopEvent({ result: response });
}
}
const workflow = new AgentWorkflow();
const result = await workflow.run({ message: "What's the weather?" });
Legacy Documentation
ReActAgent
Reasoning and Acting agent that uses tools to solve problems.
import { ReActAgent } from "llamaindex/agent";
import { tool } from "@llamaindex/core/tools";
import { z } from "zod";
const weatherTool = tool({
name: "get_weather",
description: "Get weather for a location",
parameters: z.object({
location: z.string()
}),
execute: async ({ location }) => {
return `Weather in ${location}: 72°F`;
}
});
const agent = new ReActAgent({
tools: [weatherTool],
verbose: true
});
Constructor Options
Language model (defaults to Settings.llm)
Array of tools the agent can use
Whether to log reasoning steps
Maximum reasoning iterations
Methods
Chat with the agentchat(params: { message: string }): Promise<AgentChatResponse>
Why Migrate?
- More Flexible: Workflows provide fine-grained control over agent behavior
- Better Streaming: Built-in support for streaming events
- Composable: Easily combine multiple workflows
- State Management: Explicit state handling with Context
- Active Development: Workflows are actively maintained
See Also