Nous.Agents.ReActAgent (nous v0.13.3)
View SourceReAct (Reasoning and Acting) Agent behaviour implementation.
ReAct is a prompting paradigm where AI agents interleave:
- Reasoning: Thinking about what to do next
- Acting: Using tools to gather information or perform actions
- Observing: Processing results to inform the next step
This module implements Nous.Agent.Behaviour with enhanced capabilities:
- Structured planning with facts survey
- Built-in todo list management
- Note-taking for observations
- Loop prevention (warns on duplicate tool calls)
- Mandatory
final_answerfor task completion
Built-in Tools
plan- Create structured plan before taking actionnote- Record observations and insightsadd_todo- Track subtaskscomplete_todo- Mark tasks donelist_todos- View current todosfinal_answer- Complete the task (required)
Example
agent = Agent.new("openai:gpt-4",
behaviour_module: Nous.Agents.ReActAgent,
tools: [&search/2, &calculate/2]
)
{:ok, result} = Agent.run(agent,
"Find the oldest F1 driver and when they won their first championship"
)Based on Research
This implementation draws from:
- "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2023)
- HuggingFace smolagents toolcalling_agent patterns
Summary
Functions
Track tool calls for loop detection.
Build messages with ReAct system prompt.
Extract output from final_answer or last assistant message.
Get all tools including ReAct-specific tools.
Initialize context for ReAct execution.
Process response and check for final_answer.
Functions
Track tool calls for loop detection.
Build messages with ReAct system prompt.
Combines the ReAct system prompt with any user instructions.
Extract output from final_answer or last assistant message.
When output_type is set, parses and validates the answer text.
Get all tools including ReAct-specific tools.
Initialize context for ReAct execution.
Sets up ReAct-specific state:
todos- Task listplans- Planning historynotes- Observationstool_history- Loop detectionfinal_answer- Captured final answer
Process response and check for final_answer.
Updates context and sets needs_response to false when
final_answer tool is called.