# `Nous.Agents.ReActAgent`
[🔗](https://github.com/nyo16/nous/blob/v0.17.1/lib/nous/agents/react_agent.ex#L1)

ReAct (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_answer` for task completion

## Built-in Tools

- `plan` - Create structured plan before taking action
- `note` - Record observations and insights
- `add_todo` - Track subtasks
- `complete_todo` - Mark tasks done
- `list_todos` - View current todos
- `final_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

# `after_tool`

Track tool calls for loop detection.

# `build_messages`

Build messages with ReAct system prompt.

Combines the ReAct system prompt with any user instructions.

# `extract_output`

Extract output from final_answer or last assistant message.

When `output_type` is set, parses and validates the answer text.

# `get_tools`

Get all tools including ReAct-specific tools.

# `init_context`

Initialize context for ReAct execution.

Sets up ReAct-specific state:
- `todos` - Task list
- `plans` - Planning history
- `notes` - Observations
- `tool_history` - Loop detection
- `final_answer` - Captured final answer

# `process_response`

Process response and check for final_answer.

Updates context and sets `needs_response` to false when
final_answer tool is called.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
