Overview
The ReAct Agent implements the Reasoning + Acting pattern, enabling agents to think step-by-step and use tools to solve complex tasks. Built on the ractor Actor model, it supports concurrent execution and message passing.Core Types
ReActAgent
The main ReAct agent implementation that orchestrates the thought-action-observation loop.Executes a task using the ReAct loopParameters:
task: The task description (string)
LLMResult<ReActResult> with execution detailsRegisters a tool for the agent to useParameters:
tool: Tool implementation wrapped in Arc
ReActAgentBuilder
Builder pattern for constructing ReAct agents with configuration.Sets the LLM agent for reasoning
Adds a single tool to the agent
Adds multiple tools at once
Sets maximum reasoning iterations
Sets LLM temperature for reasoning
Provides custom system prompt
Enables detailed logging
Builds the agent synchronously (spawns async task for tool registration)
Builds the agent asynchronously (waits for tool registration)
Configuration
ReActConfig
Configuration options for ReAct agent behavior.Maximum number of thought-action-observation cycles
Enable streaming of reasoning steps
LLM temperature for reasoning
Custom system prompt (overrides default)
Show detailed reasoning information
Maximum tokens per reasoning step
Results
ReActResult
Complete execution result from a ReAct agent run.Unique identifier for this execution
Original task description
Final answer to the task
All execution steps (thoughts, actions, observations)
Whether execution completed successfully
Error message if execution failed
Number of reasoning iterations performed
Total execution time in milliseconds
ReActStep
A single step in the reasoning process.Type of step:
Thought, Action, Observation, or FinalAnswerContent of the step
Name of tool used (for Action steps)
Input passed to tool (for Action steps)
Sequential step number
Unix timestamp in milliseconds
Tools
ReActTool Trait
Trait for implementing custom tools.Unique tool identifier
Description for LLM to understand tool purpose
JSON Schema for tool parameters (optional)
Executes the tool with given input
Built-in Tools
MoFA provides several built-in tools:calculator
Evaluates mathematical expressions
string_tool
String manipulation operations (length, upper, lower, reverse, count)
json_tool
JSON parsing and querying (parse, get, keys, stringify)
datetime_tool
Date and time operations (now, timestamp, millis)
echo_tool
Simple echo for testing
Actor Model
ReActActor
Actor-based implementation for concurrent ReAct execution. Message Types:RunTask
Execute a task and return result
RunTaskStreaming
Execute task with streaming step updates
RegisterTool
Register a new tool dynamically
GetStatus
Query current actor status
CancelTask
Cancel currently running task
Stop
Stop the actor
ReActActorRef
Convenient wrapper for interacting with ReAct actors.Execution Patterns
ChainAgent
Sequential execution where each agent’s output becomes the next agent’s input.Adds a ReAct agent to the chain
Adds a simple LLM agent to the chain
Transform function to adapt output for next agent
Whether to continue chain if a step fails
ParallelAgent
Concurrent execution with result aggregation.Strategy for combining results:
Concatenate: Simple concatenationConcatenateWithSeparator(String): Join with separatorFirstSuccess: Return first successful resultCollectAll: Return all as JSON arrayVote: Majority votingLLMSummarize(Arc<LLMAgent>): LLM-based synthesisCustom(Fn): Custom aggregation function
Aggregate even if some agents fail
Timeout for parallel execution
Customize task for specific agent using
{task} placeholderMapReduceAgent
Map-Reduce pattern for decomposing and aggregating tasks.Splits input into sub-tasks
Agent to process each sub-task
Agent to aggregate results
Maximum concurrent workers
AutoAgent
Intelligent agent that automatically selects execution strategy.Examples
Basic ReAct Agent
Chain Execution
Parallel with Summarization
Error Handling
All ReAct operations returnLLMResult<T> which is an alias for Result<T, LLMError>.
Source Reference
- Core implementation:
~/workspace/source/crates/mofa-foundation/src/react/core.rs - Actor model:
~/workspace/source/crates/mofa-foundation/src/react/actor.rs - Patterns:
~/workspace/source/crates/mofa-foundation/src/react/patterns.rs - Tools:
~/workspace/source/crates/mofa-foundation/src/react/tools.rs - Examples:
~/workspace/source/examples/react_agent/src/main.rs