Reasoning Strategies¶
Reactive Agents supports multiple reasoning strategies for different task types.
Available Strategies¶
from reactive_agents import ReasoningStrategies
ReasoningStrategies.REACTIVE # Simple prompt-response
ReasoningStrategies.REFLECT_DECIDE_ACT # Reflection-based
ReasoningStrategies.PLAN_EXECUTE_REFLECT # Planning upfront
ReasoningStrategies.ADAPTIVE # Dynamic switching
Strategy Comparison¶
| Strategy | Best For | Iterations | Complexity |
|---|---|---|---|
| REACTIVE | Simple tasks, Q&A | Few | Low |
| REFLECT_DECIDE_ACT | Tasks needing careful thought | Medium | Medium |
| PLAN_EXECUTE_REFLECT | Complex multi-step tasks | Many | High |
| ADAPTIVE | Unknown or varied tasks | Varies | Auto |
REACTIVE Strategy¶
The simplest strategy - direct prompt-response with state tracking.
Best for:
- Simple questions and answers
- Single-step tasks
- Tool-augmented responses
- Quick interactions
How it works:
- Receive task
- Think and optionally call tools
- Provide final answer
Example tasks:
- "What is 2 + 2?"
- "Search for the weather in Paris"
- "Summarize this text"
REFLECT_DECIDE_ACT Strategy¶
Adds explicit reflection before each action.
Best for:
- Tasks requiring careful consideration
- Multi-turn reasoning
- Error-prone operations
- Tasks where mistakes are costly
How it works:
- Reflect - Consider the current state and progress
- Decide - Choose the best next action
- Act - Execute the decision
- Repeat until complete
Example tasks:
- "Debug this code and explain your reasoning"
- "Analyze this data and make recommendations"
- "Research this topic thoroughly"
PLAN_EXECUTE_REFLECT Strategy¶
Creates an explicit plan before execution.
Best for:
- Complex multi-step tasks
- Projects with clear milestones
- Tasks requiring coordination
- When you need visibility into the approach
How it works:
- Plan - Create a detailed step-by-step plan
- Execute - Work through each step
- Reflect - After each step, evaluate progress
- Adapt - Modify the plan if needed
Example tasks:
- "Build a web scraper that extracts product data"
- "Create a report analyzing sales trends"
- "Implement a new feature with tests"
ADAPTIVE Strategy¶
Automatically selects the best strategy based on task analysis.
Best for:
- Varied or unknown task types
- When you don't know the best approach
- Production systems handling diverse requests
How it works:
- Analyzes the task characteristics
- Selects the most appropriate strategy
- Can switch strategies mid-execution if needed
Choosing a Strategy¶
Decision Flowchart¶
Is the task simple and straightforward?
├─ Yes → REACTIVE
└─ No
├─ Do you need careful reasoning at each step?
│ └─ Yes → REFLECT_DECIDE_ACT
├─ Is there a clear sequence of steps?
│ └─ Yes → PLAN_EXECUTE_REFLECT
└─ Unsure? → ADAPTIVE
Task Type Guidelines¶
| Task Type | Recommended Strategy |
|---|---|
| Simple Q&A | REACTIVE |
| Tool usage | REACTIVE |
| Analysis | REFLECT_DECIDE_ACT |
| Debugging | REFLECT_DECIDE_ACT |
| Multi-step projects | PLAN_EXECUTE_REFLECT |
| Research | PLAN_EXECUTE_REFLECT |
| Mixed/Unknown | ADAPTIVE |
Strategy Configuration¶
Disable Dynamic Switching¶
By default, agents may switch strategies. To lock to a specific strategy:
.with_reasoning_strategy(ReasoningStrategies.REACTIVE)
.with_enable_dynamic_strategy_switching(False) # Lock to REACTIVE
Strategy Mode¶
# Static mode - never switch
.with_strategy_mode("static")
.with_static_strategy("reactive")
# Adaptive mode - can switch based on task
.with_strategy_mode("adaptive")
Iteration Settings¶
Each strategy has different iteration needs:
# REACTIVE - usually completes quickly
.with_reasoning_strategy(ReasoningStrategies.REACTIVE)
.with_max_iterations(5)
# REFLECT_DECIDE_ACT - needs more iterations
.with_reasoning_strategy(ReasoningStrategies.REFLECT_DECIDE_ACT)
.with_max_iterations(10)
# PLAN_EXECUTE_REFLECT - may need many iterations
.with_reasoning_strategy(ReasoningStrategies.PLAN_EXECUTE_REFLECT)
.with_max_iterations(20)
Monitoring Strategy Execution¶
Use events to see which strategy is executing:
agent.on_iteration_started(lambda e: print(f"Strategy: {e['strategy']}"))
agent.on_iteration_completed(lambda e: print(f"Iteration {e['iteration']} done"))
Strategy Performance¶
Check which strategy was used after execution:
result = await agent.run("Task")
print(f"Strategy used: {result.strategy_used}")
print(f"Iterations: {result.session.iterations}")
Best Practices¶
- Start simple - Use REACTIVE unless you have a reason not to
- Match complexity - More complex tasks need more sophisticated strategies
- Set appropriate iterations - Under-iteration causes incomplete results
- Use ADAPTIVE when unsure - Let the framework decide
- Monitor and tune - Watch execution to understand strategy behavior