Function: react()
@providerprotocol/agents / execution / react
Function: react()
Section titled “Function: react()”react(
options):ExecutionStrategy
Defined in: src/execution/react.ts:78
Creates a ReAct (Reason-Act-Observe) execution strategy for agent execution.
The ReAct strategy implements the Reason-Act-Observe pattern from the paper “ReAct: Synergizing Reasoning and Acting in Language Models”. It adds an explicit reasoning phase before each action, which improves the model’s decision-making by encouraging step-by-step thinking.
The execution cycle is:
- Reason: LLM outputs reasoning about what to do next
- Act: LLM selects and executes tool(s) based on reasoning
- Observe: Tool results are formatted as observations
- Repeat: Continue until stop condition, no more actions, or maxSteps
This strategy is ideal for complex tasks requiring careful deliberation and multi-step reasoning.
Parameters
Section titled “Parameters”options
Section titled “options”ReactOptions = {}
Configuration options for the ReAct strategy
Returns
Section titled “Returns”An ExecutionStrategy instance implementing the ReAct pattern
Example
Section titled “Example”import { createAgent, react } from '@providerprotocol/agents';
// Basic ReAct agentconst agent = createAgent({ llm: myLLM, tools: [searchTool, calculatorTool], strategy: react(),});
// With custom reasoning prompt and step limitconst customAgent = createAgent({ llm: myLLM, tools: [searchTool], strategy: react({ maxSteps: 10, reasoningPrompt: 'Analyze the situation and determine the best action.', }),});
// With lifecycle hooks for observabilityconst observableAgent = createAgent({ llm: myLLM, tools: [searchTool], strategy: react({ maxSteps: 5 }), hooks: { onReason: (step, reasoning) => console.log(`Step ${step} reasoning:`, reasoning), onAct: (step, actions) => console.log(`Step ${step} actions:`, actions), },});- https://arxiv.org/abs/2210.03629 - ReAct: Synergizing Reasoning and Acting
- loop for simpler tool-loop execution
- plan for structured multi-step execution