Write agentic apps once, run with any LLM provider ✨

Multi-Provider Reasoning Engine

Leverage the unique strengths of different LLM providers to solve complex, multi-step problems with higher accuracy and reliability.

Orchestrated Problem Solving

Route each reasoning step to the most capable model

Use Cases

🧮 Mathematical Problems

Complex calculations requiring step-by-step verification

šŸ”¬ Scientific Analysis

Multi-disciplinary problems requiring diverse expertise

šŸ’¼ Business Strategy

Complex decision-making with multiple perspectives

Key Features

  • Model Specialization: Assign specific models to tasks they excel at
  • Chain-of-Thought: Break complex problems into manageable steps
  • Cross-Verification: Use multiple models to verify results
  • Transparent Process: Track reasoning through each step

Reasoning Pipeline

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│   Problem   │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
       │
       ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Step 1: Problem Decomposition      │
│  Model: Claude (Strong at analysis)  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
               │
               ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Step 2: Execute Calculations       │
│  Model: GPT-4 (Strong at math)      │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
               │
               ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Step 3: Verify Solution            │
│  Model: Gemini (Cross-validation)   │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
               │
               ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Step 4: Synthesize Answer          │
│  Model: Claude Opus (Best writing)  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
               │
               ā–¼
        ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
        │ Final Answer │
        ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Implementation

reasoning_engine.py
import aisuite as ai
from typing import List, Dict, Any

class MultiProviderReasoning:
    """Use different models for different reasoning steps"""
    
    def __init__(self):
        self.client = ai.Client()
        # Assign models to specific tasks based on strengths
        self.models = {
            "decomposition": "anthropic:claude-3-sonnet",  # Good at breaking down problems
            "calculation": "openai:gpt-4",                  # Strong at math
            "verification": "google:gemini-pro",            # Double-check results
            "synthesis": "anthropic:claude-3-opus"          # Final answer synthesis
        }
    
    def solve_problem(self, problem: str) -> Dict[str, Any]:
        """Solve complex problem using multiple models"""
        
        steps = {}
        
        # Step 1: Problem decomposition
        print("šŸ” Decomposing problem...")
        decomposition_prompt = f"""Break down this problem into clear steps:
        {problem}
        
        List each step needed to solve this problem."""
        
        steps["decomposition"] = self.client.chat.completions.create(
            model=self.models["decomposition"],
            messages=[{"role": "user", "content": decomposition_prompt}]
        ).choices[0].message.content
        
        # Step 2: Execute calculations/logic
        print("🧮 Executing calculations...")
        calculation_prompt = f"""Given this problem breakdown:
        {steps['decomposition']}
        
        Original problem: {problem}
        
        Please execute each step and show your work."""
        
        steps["calculation"] = self.client.chat.completions.create(
            model=self.models["calculation"],
            messages=[{"role": "user", "content": calculation_prompt}]
        ).choices[0].message.content
        
        # Step 3: Verify the solution
        print("āœ… Verifying solution...")
        verification_prompt = f"""Please verify this solution:
        
        Problem: {problem}
        Solution: {steps['calculation']}
        
        Check for errors and confirm if the solution is correct."""
        
        steps["verification"] = self.client.chat.completions.create(
            model=self.models["verification"],
            messages=[{"role": "user", "content": verification_prompt}]
        ).choices[0].message.content
        
        # Step 4: Synthesize final answer
        print("šŸ“ Synthesizing final answer...")
        synthesis_prompt = f"""Based on the following analysis:
        
        Problem decomposition: {steps['decomposition']}
        Calculations: {steps['calculation']}
        Verification: {steps['verification']}
        
        Provide a clear, concise final answer to: {problem}"""
        
        steps["final_answer"] = self.client.chat.completions.create(
            model=self.models["synthesis"],
            messages=[{"role": "user", "content": synthesis_prompt}]
        ).choices[0].message.content
        
        return steps

# Example usage
reasoner = MultiProviderReasoning()

problem = """A train leaves Station A at 9:00 AM traveling at 60 mph. 
Another train leaves Station B at 10:00 AM traveling at 80 mph toward Station A. 
If the stations are 280 miles apart, when and where will the trains meet?"""

solution = reasoner.solve_problem(problem)

print("\nšŸŽÆ FINAL ANSWER:")
print(solution["final_answer"])

Example Problems to Try

Physics Problem

"A ball is thrown upward with initial velocity 30 m/s. Calculate maximum height, time to reach it, and total time in air."

Logic Puzzle

"Three friends split a bill. Alice pays twice as much as Bob. Charlie pays $10 more than Bob. Total is $85. How much did each pay?"

Extend It

šŸ”„ Add Retry Logic

Automatically retry with different models if verification fails

šŸ“Š Performance Tracking

Log which models perform best for different problem types