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.
First, let's set up a new CrewAI project:
crewai create crew reasoning-committee
cd reasoning-committeeCreate a .env file in your project root:
OPENAI_API_KEY=your_openai_key_here
OPENROUTER_API_KEY=your_openrouter_key_hereModify 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.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.mdModify 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,
)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()# 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- Run Your Reasoning Committee
python -m reasoning_committee.mainHow It Works
-
The system prompts you to enter a problem
-
Each AI model (Claude, GPT, Grok) analyzes the problem using its unique reasoning approach
-
The synthesizer agent reviews all analyses and creates a comprehensive solution that combines the best insights
-
The final solution is saved to output/committee_solution.md
Customization Options
-
Add More Models: Modify
agents.yamlandcrew.pyto include additional AI models available on OpenRouter -
Parallel Processing: Change
process=Process.sequentialtoprocess=Process.parallelfor concurrent reasoning -
Specialized Tasks: Add more specialized tasks like "Find Counter-Arguments" or "Ethical Analysis"