Skip to main content
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?" });
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

llm
LLM
Language model (defaults to Settings.llm)
tools
BaseTool[]
required
Array of tools the agent can use
verbose
boolean
default:false
Whether to log reasoning steps
maxIterations
number
default:10
Maximum reasoning iterations

Methods

chat
method
Chat with the agent
chat(params: { message: string }): Promise<AgentChatResponse>
reset
method
Reset agent memory
reset(): void

Why Migrate?

  1. More Flexible: Workflows provide fine-grained control over agent behavior
  2. Better Streaming: Built-in support for streaming events
  3. Composable: Easily combine multiple workflows
  4. State Management: Explicit state handling with Context
  5. Active Development: Workflows are actively maintained

See Also

Build docs developers (and LLMs) love