Feat: ReAct agent [WIP] #264
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This PR introduces a comprehensive ReAct (Reasoning and Acting) agent implementation that operates independently of LangChain, providing a native Python ReAct pattern for MCP tool integration.
The implementation includes a complete ReAct execution engine, specialized adapters, type definitions, and comprehensive telemetry integration.
Implementation Details
- ReActExecutor: Core execution engine implementing the ReAct loop with structured LLM responses
- MCPReActAgent: Main agent class compatible with MCPAgent interface
- Supports both regular and streaming execution modes
- Integrated conversation memory management with configurable turn limits
- ReActStep: Represents individual reasoning steps with automatic JSON parsing
- ReActResponse: Structured LLM response format using Pydantic validation
- ConversationMemory: Memory management with automatic history trimming
- StepType: Enum for different step types (THOUGHT, ACTION, OBSERVATION, FINAL_ANSWER)
- ReactAdapter: Converts MCP tools/resources/prompts to callable ReactTool instances
- Each tool gets an async execute function that handles MCP protocol communication
- Supports resource-as-tool and prompt-as-tool conversion when enabled
- Maintains connector-to-tool mapping for efficient caching
- Provider-agnostic LLM client using instructor for structured outputs
- Supports OpenAI, Anthropic, and other providers through unified interface
- Automatic async client initialization and model name normalization
- Extended MCP type definitions with server capabilities modeling
- Enhanced client methods for capability discovery and validation
Example Usage (Before)
Example Usage (After)
Documentation Updates
Testing
Backwards Compatibility
These changes are fully backwards compatible. The existing MCPAgent (LangChain-based) remains unchanged and functional. The new MCPReActAgent is an alternative implementation that can be used alongside or instead of the existing agent without affecting current code.
Existing users can: