Skip to content

Instantly share code, notes, and snippets.

@geeknik
Created April 13, 2025 16:17
Show Gist options
  • Save geeknik/df5d12dbc12c012b2a1318d8974415d8 to your computer and use it in GitHub Desktop.
Save geeknik/df5d12dbc12c012b2a1318d8974415d8 to your computer and use it in GitHub Desktop.

Overview

We'll create a crew where each agent represents a different AI model (like ChatGPT, Claude, and Grok), allowing them to collaborate on solving problems through different perspectives and reasoning approaches.

1. Create Your Crew Project

First, let's set up a new CrewAI project:

crewai create crew reasoning-committee
cd reasoning-committee

2. Configure OpenRouter Integration

Create a .env file in your project root:

OPENAI_API_KEY=your_openai_key_here
OPENROUTER_API_KEY=your_openrouter_key_here

3. Configure Your Agents

Modify your agents.yaml to create specialized agents for different models:

# src/reasoning_committee/config/agents.yaml
claude_agent:
  role: >
    Problem-Solving Expert with Claude-style reasoning
  goal: >
    Analyze problems with careful consideration of nuance, ethics, and potential impacts
  backstory: >
    You're an AI assistant specializing in methodical, structured reasoning. Your strength 
    is considering multiple perspectives deeply and weighing trade-offs thoughtfully.

gpt_agent:
  role: >
    Problem-Solving Expert with GPT-style reasoning
  goal: >
    Apply creative, broad-knowledge-based reasoning to solve complex problems
  backstory: >
    You're an AI assistant with vast knowledge across domains. Your strength is
    connecting ideas from different fields and providing creative solutions.

grok_agent:
  role: >
    Problem-Solving Expert with Grok-style reasoning
  goal: >
    Provide unconventional, out-of-the-box thinking for solving problems
  backstory: >
    You're an AI assistant known for your bold, sometimes contrarian perspectives. 
    Your strength is questioning assumptions and offering novel approaches.

synthesizer:
  role: >
    Insight Synthesizer and Solution Architect
  goal: >
    Combine the insights from different AI perspectives into a coherent, comprehensive solution
  backstory: >
    You're an expert at understanding and integrating diverse viewpoints. Your 
    specialty is finding the most valuable insights from different reasoning paths
    and creating unified solutions.

4. Configure Your Tasks

Create your tasks.yaml to define the collaboration flow:

# src/reasoning_committee/config/tasks.yaml
claude_analysis_task:
  description: >
    Analyze the problem: {problem}
    Using a Claude-style approach, provide your reasoning step by step.
    Focus on nuance, ethical considerations, and potential impacts.
    Be thorough in your analysis.
  expected_output: >
    A detailed analysis of the problem with your reasoning steps clearly outlined.
  agent: claude_agent

gpt_analysis_task:
  description: >
    Analyze the problem: {problem}
    Using a GPT-style approach, provide your reasoning step by step.
    Draw from broad knowledge and make creative connections across domains.
  expected_output: >
    A detailed analysis of the problem with your reasoning steps clearly outlined.
  agent: gpt_agent

grok_analysis_task:
  description: >
    Analyze the problem: {problem}
    Using a Grok-style approach, provide your reasoning step by step.
    Challenge conventional thinking and offer bold, unexpected perspectives.
  expected_output: >
    A detailed analysis of the problem with your reasoning steps clearly outlined.
  agent: grok_agent

synthesis_task:
  description: >
    Review the analyses from the Claude, GPT, and Grok perspectives.
    Synthesize the best insights from each approach.
    Create a comprehensive solution that incorporates the strengths of each reasoning path.
    Highlight where the different models agreed and disagreed.
  expected_output: >
    A comprehensive solution document that integrates insights from all three reasoning approaches.
    Include a section on areas of consensus and divergence between the models.
  agent: synthesizer
  context:
    - claude_analysis_task
    - gpt_analysis_task
    - grok_analysis_task
  output_file: committee_solution.md

5. Create Your Crew Class

Modify your crew.py to implement the OpenRouter integration:

# src/reasoning_committee/crew.py
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from crewai_tools import SerperDevTool
import os
from openai import OpenAI

class OpenRouterClient:
    """Custom client for OpenRouter integration"""
    
    def __init__(self, model):
        self.client = OpenAI(
            base_url="https://openrouter.ai/api/v1",
            api_key=os.getenv("OPENROUTER_API_KEY"),
        )
        self.model = model
    
    def complete(self, prompt, **kwargs):
        """Send a completion request to OpenRouter"""
        response = self.client.chat.completions.create(
            model=self.model,
            messages=[{"role": "user", "content": prompt}],
            **kwargs
        )
        return response.choices[0].message.content

@CrewBase
class ReasoningCommitteeCrew():
    """Reasoning Committee crew with multiple AI models"""

    @agent
    def claude_agent(self) -> Agent:
        return Agent(
            config=self.agents_config['claude_agent'],
            verbose=True,
            llm=OpenRouterClient("anthropic/claude-3.7-sonnet")
        )

    @agent
    def gpt_agent(self) -> Agent:
        return Agent(
            config=self.agents_config['gpt_agent'],
            verbose=True,
            llm=OpenRouterClient("openai/gpt-4o")
        )

    @agent
    def grok_agent(self) -> Agent:
        return Agent(
            config=self.agents_config['grok_agent'],
            verbose=True,
            llm=OpenRouterClient("xai/grok-1.5-mini")
        )

    @agent
    def synthesizer(self) -> Agent:
        return Agent(
            config=self.agents_config['synthesizer'],
            verbose=True,
            llm=OpenRouterClient("anthropic/claude-3.7-sonnet")
        )

    @task
    def claude_analysis_task(self) -> Task:
        return Task(
            config=self.tasks_config['claude_analysis_task'],
        )

    @task
    def gpt_analysis_task(self) -> Task:
        return Task(
            config=self.tasks_config['gpt_analysis_task'],
        )

    @task
    def grok_analysis_task(self) -> Task:
        return Task(
            config=self.tasks_config['grok_analysis_task'],
        )

    @task
    def synthesis_task(self) -> Task:
        return Task(
            config=self.tasks_config['synthesis_task'],
            output_file='output/committee_solution.md'
        )

    @crew
    def crew(self) -> Crew:
        """Creates the Reasoning Committee crew"""
        return Crew(
            agents=self.agents,
            tasks=[
                self.claude_analysis_task(),
                self.gpt_analysis_task(),
                self.grok_analysis_task(),
                self.synthesis_task()
            ],
            process=Process.sequential,
            verbose=True,
        )

6. Create Your Main Script

Create a main.py file to run your crew:

#!/usr/bin/env python
# src/reasoning_committee/main.py
import sys
from reasoning_committee.crew import ReasoningCommitteeCrew

def run():
    """
    Run the reasoning committee crew.
    """
    problem = input("Enter the problem for the AI reasoning committee to solve: ")
    
    inputs = {
        'problem': problem
    }
    
    result = ReasoningCommitteeCrew().crew().kickoff(inputs=inputs)
    print("\nReasoning committee has completed their analysis.")
    print("Check output/committee_solution.md for the final synthesized solution.")

if __name__ == "__main__":
    run()

7. Install Dependencies

# Make sure CrewAI is installed
pip install crewai

# Install OpenAI SDK for OpenRouter integration
pip install openai

# Install dotenv for environment variables
pip install python-dotenv
  1. Run Your Reasoning Committee
python -m reasoning_committee.main

How It Works

  1. The system prompts you to enter a problem

  2. Each AI model (Claude, GPT, Grok) analyzes the problem using its unique reasoning approach

  3. The synthesizer agent reviews all analyses and creates a comprehensive solution that combines the best insights

  4. The final solution is saved to output/committee_solution.md

Customization Options

  1. Add More Models: Modify agents.yaml and crew.py to include additional AI models available on OpenRouter

  2. Parallel Processing: Change process=Process.sequential to process=Process.parallel for concurrent reasoning

  3. Specialized Tasks: Add more specialized tasks like "Find Counter-Arguments" or "Ethical Analysis"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment