Reasoning Patterns Migration Guide¶
This guide helps you migrate to the new reasoning patterns introduced in AgentiCraft v0.2.0-alpha.
Overview¶
AgentiCraft v0.2.0-alpha introduces three powerful reasoning patterns: - Chain of Thought (CoT) - Step-by-step reasoning - Tree of Thoughts (ToT) - Multi-path exploration - ReAct - Reasoning with tool actions
Migration Steps¶
1. Update Your Imports¶
Before (v0.1.x):
After (v0.2.0-alpha):
2. Update Agent Creation¶
Before:
After:
agent = ReasoningAgent(
name="Assistant",
instructions="Help with tasks",
reasoning_pattern="chain_of_thought" # or "tree_of_thoughts", "react", "auto"
)
3. Access Reasoning Traces¶
The new ReasoningAgent
provides transparent access to the reasoning process:
response = await agent.think_and_act("Solve a complex problem")
# Access reasoning steps
for step in response.reasoning_steps:
print(f"{step.number}. {step.description}")
print(f" Confidence: {step.confidence:.0%}")
if step.alternatives:
print(f" Alternatives considered: {len(step.alternatives)}")
4. Pattern Selection¶
You can let the agent automatically select the best reasoning pattern:
agent = ReasoningAgent(
name="AutoReasoner",
reasoning_pattern="auto" # Automatically selects based on query
)
Pattern-Specific Migration¶
Chain of Thought (CoT)¶
Best for: Mathematical problems, logical deduction, step-by-step analysis
from agenticraft.reasoning.patterns import ChainOfThoughtPattern
# Direct pattern usage
pattern = ChainOfThoughtPattern()
result = await pattern.reason(
query="If a train travels 120 miles in 2 hours...",
context={}
)
Tree of Thoughts (ToT)¶
Best for: Creative solutions, exploring multiple approaches
from agenticraft.reasoning.patterns import TreeOfThoughtsPattern
pattern = TreeOfThoughtsPattern(
max_branches=3,
exploration_depth=3
)
ReAct Pattern¶
Best for: Tasks requiring tool usage with reasoning
from agenticraft.reasoning.patterns import ReactPattern
from agenticraft import tool
@tool
def calculator(expression: str) -> float:
"""Evaluate a mathematical expression"""
return eval(expression)
agent = ReasoningAgent(
name="MathAssistant",
reasoning_pattern="react",
tools=[calculator]
)
Breaking Changes¶
- Response Format: The response now includes a
reasoning_steps
attribute - Async by Default: All reasoning operations are async
- Pattern Configuration: Each pattern has specific configuration options
Backward Compatibility¶
To maintain backward compatibility, you can still use the base Agent
class:
from agenticraft import Agent
# This still works but without reasoning traces
agent = Agent(name="Assistant")
Examples¶
See the reasoning examples for complete working code: - Chain of Thought Demo - Tree of Thoughts Demo - ReAct Pattern Demo
Need Help?¶
- Check the API Reference
- Join our Discord community
- Open an issue on GitHub