Custom Reasoning
Control how agents think through problems with customizable reasoning patterns.
Transparent Thinking
AA Kit provides fine-grained control over how agents reason through problems. Choose from built-in patterns or create custom reasoning strategies that match your domain.
Built-in Reasoning Patterns
Simple
Direct responses without explicit reasoning
Best for:
Quick answers, simple queries
Q: Capital of France? A: Paris
Chain of Thought
Step-by-step reasoning process
Best for:
Math problems, logical puzzles, complex analysis
Let me think step by step...
ReAct
Reasoning + Acting with tools
Best for:
Research tasks, tool-heavy workflows
Thought → Action → Observation → ...
Tree of Thoughts
Explore multiple reasoning paths
Best for:
Creative problems, strategy planning
Option A... Option B... Best path: A
Implementation Examples
Simple Reasoning (Default)
from aakit import Agent
# Default: Direct response without explicit reasoning
agent = Agent(
name="simple_agent",
instruction="You provide direct answers",
model="gpt-4",
reasoning="simple" # Default
)
response = await agent.chat("What is 2+2?")
# Response: "4"Chain of Thought (CoT)
from aakit import Agent
# Enable step-by-step reasoning
agent = Agent(
name="cot_agent",
instruction="You solve problems step by step",
model="gpt-4",
reasoning="chain_of_thought"
)
response = await agent.chat(
"If a train travels 120 miles in 2 hours, what's its speed?"
)
# Response includes thinking process:
# "Let me solve this step by step:
# 1. Distance = 120 miles
# 2. Time = 2 hours
# 3. Speed = Distance / Time
# 4. Speed = 120 / 2 = 60 mph
# The train's speed is 60 miles per hour."ReAct Pattern
from aakit import Agent
# Reasoning + Acting: Think before using tools
agent = Agent(
name="react_agent",
instruction="You research and analyze information",
model="gpt-4",
reasoning="react",
tools=[search_web, calculate, analyze_data]
)
response = await agent.chat(
"What's the current inflation rate and its impact on savings?"
)
# Agent's process:
# Thought: I need to find current inflation data
# Action: search_web("current inflation rate 2024")
# Observation: Current inflation is 3.2%
# Thought: I should calculate impact on savings
# Action: calculate(savings_value_after_inflation)
# Final Answer: With 3.2% inflation...Custom Reasoning Pattern
from aakit import Agent, ReasoningPattern
# Define custom reasoning pattern
class ScientificMethod(ReasoningPattern):
steps = [
"Observation: What do we see?",
"Hypothesis: What might explain this?",
"Prediction: What would happen if...?",
"Testing: Let's verify with data",
"Conclusion: Based on evidence..."
]
def format_response(self, thoughts, conclusion):
return f"**Scientific Analysis**\n{thoughts}\n\n**Conclusion:** {conclusion}"
# Use custom pattern
agent = Agent(
name="scientist",
instruction="You apply scientific method",
model="gpt-4",
reasoning=ScientificMethod()
)
response = await agent.chat("Why is the sky blue?")Multi-Step Reasoning
from aakit import Agent
# Configure multi-step reasoning
agent = Agent(
name="planner",
instruction="You break down complex tasks",
model="gpt-4",
reasoning="multi_step",
reasoning_config={
"max_steps": 10,
"step_delimiter": "→",
"show_progress": True,
"allow_revision": True # Can revise previous steps
}
)
response = await agent.chat(
"Plan a cross-country road trip from NYC to LA"
)
# Response shows clear steps:
# Step 1 → Define route priorities (scenic vs fast)
# Step 2 → Calculate total distance (2,800 miles)
# Step 3 → Plan daily segments (350-400 miles/day)
# Step 4 → Identify key stops and attractions
# ...Reasoning with Confidence
from aakit import Agent
# Include confidence scores in reasoning
agent = Agent(
name="analyst",
instruction="You provide analysis with confidence levels",
model="gpt-4",
reasoning="confidence_based",
reasoning_config={
"show_confidence": True,
"min_confidence": 0.7,
"request_clarification": True
}
)
response = await agent.chat(
"Will the stock market go up tomorrow?"
)
# Response:
# "Based on my analysis:
# - Technical indicators: Bullish (confidence: 0.65)
# - Market sentiment: Mixed (confidence: 0.45)
# - Economic data: Positive (confidence: 0.75)
#
# Overall prediction: Slight upward trend
# Confidence: 0.62 (Low - many uncertainties)
#
# Note: This confidence is below my threshold.
# Would you like me to gather more data?"Advanced Reasoning Features
Goal-Oriented Reasoning
Define specific goals for the reasoning process:
reasoning_config={
"goal": "minimize_cost",
"constraints": ["time < 1h", "accuracy > 0.95"],
"optimization": "pareto_optimal"
}Self-Reflection
Enable agents to critique and improve their own reasoning:
reasoning="self_reflective"
reasoning_config={
"reflection_rounds": 2,
"improvement_threshold": 0.8
}Creating Custom Patterns
from aakit import ReasoningPattern
class DebuggerReasoning(ReasoningPattern):
"""Custom reasoning for debugging code"""
def __init__(self):
self.steps = [
"Identify the error or unexpected behavior",
"Locate the relevant code section",
"Form hypothesis about the cause",
"Test the hypothesis",
"Implement and verify the fix"
]
async def reason(self, query, context):
thoughts = []
for step in self.steps:
thought = await self.think_step(step, query, context)
thoughts.append(thought)
# Early exit if solution found
if "fixed" in thought.lower():
break
return self.format_debug_response(thoughts)
def format_debug_response(self, thoughts):
return {
"diagnosis": thoughts[0:3],
"solution": thoughts[3:],
"confidence": self.calculate_confidence(thoughts)
}
# Use custom reasoning
agent = Agent(
name="debugger",
instruction="You debug code systematically",
model="gpt-4",
reasoning=DebuggerReasoning()
)Reasoning Configuration
| Parameter | Type | Description |
|---|---|---|
| max_thinking_time | int | Maximum seconds for reasoning |
| show_thinking | bool | Include reasoning in response |
| thinking_format | str | "markdown", "json", "xml" |
| parallel_thoughts | int | Number of parallel reasoning paths |
| thought_temperature | float | Creativity in reasoning (0-1) |
Reasoning Strategies by Use Case
Analysis Tasks
- • Chain of Thought
- • Multi-perspective
- • Evidence-based
Creative Tasks
- • Tree of Thoughts
- • Brainstorming
- • Lateral thinking
Problem Solving
- • ReAct pattern
- • Hypothesis testing
- • Iterative refinement
Reasoning Visualization
Reasoning Flow Example
Next Steps
Explore the comprehensive API reference for all AA Kit features.
Continue to API Reference →