How langchain-ai/react-agent works
This is a LangGraph ReAct agent template. A user query enters the compiled graph as conversation state; the reasoning node loads and invokes the configured chat model with the system prompt. The model either produces a final answer or requests a tool. Tool routing dispatches search through Tavily, appends observations to state, and loops back to reasoning until completion. Configuration controls the model, prompt, and search limit. The sampled source shows this core path; persistence and additional tools are not present.
Main entry points: graph.py Reasoning Node · tools.py Search Tool · state.py Conversation State · context.py Agent Context
Components 12
Interface and State
- Conversation State
src/react_agent/state.py
Agent Graph
- ReAct Graph
src/react_agent/graph.py - Reasoning Node
src/react_agent/graph.py - Tool Router
src/react_agent/graph.py - Tool Executor
src/react_agent/graph.py - Model Loader
src/react_agent/utils.py
Configuration
- Agent Context
src/react_agent/context.py - System Prompt
src/react_agent/prompts.py
Tools and Integrations
- Chat Model Provider
- Search Tool
src/react_agent/tools.py - Tavily Search
Other components
- User
Connections 21
- User → ReAct Graph: sends query
- ReAct Graph → Conversation State: loads input
- ReAct Graph → Reasoning Node: starts reasoning
- Conversation State → Reasoning Node: provides messages
- Agent Context → Reasoning Node: supplies settings
- System Prompt → Reasoning Node: provides template
- Reasoning Node → Model Loader: loads model
- Model Loader → Chat Model Provider: initializes model
- Reasoning Node → Chat Model Provider: invokes model
- Chat Model Provider → Reasoning Node: returns response
- Reasoning Node → Conversation State: appends response
- Reasoning Node → Tool Router: routes output
- Tool Router → Tool Executor: dispatches calls
- Tool Executor → Search Tool: invokes search
- Agent Context → Search Tool: sets result limit
- Search Tool → Tavily Search: queries web
- Tavily Search → Search Tool: returns results
- Search Tool → Tool Executor: returns observation
- Tool Executor → Conversation State: appends observation
- Tool Executor → Reasoning Node: loops to reasoning
- ReAct Graph → User: returns answer