Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from openai import OpenAI
from tools import discover_tools

class OpenRouterAgent:
class GroqAgent:
def __init__(self, config_path="config.yaml", silent=False):
# Load configuration
with open(config_path, 'r') as f:
Expand All @@ -12,27 +12,27 @@ def __init__(self, config_path="config.yaml", silent=False):
# Silent mode for orchestrator (suppresses debug output)
self.silent = silent

# Initialize OpenAI client with OpenRouter
# Initialize OpenAI client with Groq
self.client = OpenAI(
base_url=self.config['openrouter']['base_url'],
api_key=self.config['openrouter']['api_key']
base_url=self.config['groq']['base_url'],
api_key=self.config['groq']['api_key']
)

# Discover tools dynamically
self.discovered_tools = discover_tools(self.config, silent=self.silent)

# Build OpenRouter tools array
# Build Groq tools array
self.tools = [tool.to_openrouter_schema() for tool in self.discovered_tools.values()]

# Build tool mapping
self.tool_mapping = {name: tool.execute for name, tool in self.discovered_tools.items()}


def call_llm(self, messages):
"""Make OpenRouter API call with tools"""
"""Make Groq API call with tools"""
try:
response = self.client.chat.completions.create(
model=self.config['openrouter']['model'],
model=self.config['groq']['model'],
messages=messages,
tools=self.tools
)
Expand Down Expand Up @@ -100,11 +100,13 @@ def run(self, user_input: str):

# Add the response to messages
assistant_message = response.choices[0].message
messages.append({
message_to_append = {
"role": "assistant",
"content": assistant_message.content,
"tool_calls": assistant_message.tool_calls
})
"content": assistant_message.content
}
if assistant_message.tool_calls:
message_to_append['tool_calls'] = assistant_message.tool_calls
messages.append(message_to_append)

# Capture assistant content for full response
if assistant_message.content:
Expand Down
8 changes: 4 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# OpenRouter API settings
openrouter:
# Groq API settings
groq:
api_key: "YOUR KEY"
base_url: "https://openrouter.ai/api/v1"
base_url: "https://api.groq.com/openai/v1"

# IMPORTANT: When selecting a model, ensure it has a high context window (200k+ tokens recommended)
# The orchestrator can generate large amounts of results from multiple agents that need to be
# processed together during synthesis. Low context window models may fail or truncate results.
model: "moonshotai/kimi-k2"
model: "llama3-70b-8192"

# System prompt for the agent
system_prompt: |
Expand Down
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from agent import OpenRouterAgent
from agent import GroqAgent

def main():
"""Main entry point for the OpenRouter agent"""
print("OpenRouter Agent with DuckDuckGo Search")
"""Main entry point for the Groq agent"""
print("Groq Agent with DuckDuckGo Search")
print("Type 'quit', 'exit', or 'bye' to exit")
print("-" * 50)

try:
agent = OpenRouterAgent()
agent = GroqAgent()
print("Agent initialized successfully!")
print(f"Using model: {agent.config['openrouter']['model']}")
print("Note: Make sure to set your OpenRouter API key in config.yaml")
print(f"Using model: {agent.config['groq']['model']}")
print("Note: Make sure to set your Groq API key in config.yaml")
print("-" * 50)
except Exception as e:
print(f"Error initializing agent: {e}")
print("Make sure you have:")
print("1. Set your OpenRouter API key in config.yaml")
print("1. Set your Groq API key in config.yaml")
print("2. Installed all dependencies with: pip install -r requirements.txt")
return

Expand Down
8 changes: 4 additions & 4 deletions orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import threading
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import List, Dict, Any
from agent import OpenRouterAgent
from agent import GroqAgent

class TaskOrchestrator:
def __init__(self, config_path="config.yaml", silent=False):
Expand All @@ -26,7 +26,7 @@ def decompose_task(self, user_input: str, num_agents: int) -> List[str]:
"""Use AI to dynamically generate different questions based on user input"""

# Create question generation agent
question_agent = OpenRouterAgent(silent=True)
question_agent = GroqAgent(silent=True)

# Get question generation prompt from config
prompt_template = self.config['orchestrator']['question_generation_prompt']
Expand Down Expand Up @@ -77,7 +77,7 @@ def run_agent_parallel(self, agent_id: int, subtask: str) -> Dict[str, Any]:
self.update_agent_progress(agent_id, "PROCESSING...")

# Use simple agent like in main.py
agent = OpenRouterAgent(silent=True)
agent = GroqAgent(silent=True)

start_time = time.time()
response = agent.run(subtask)
Expand Down Expand Up @@ -128,7 +128,7 @@ def _aggregate_consensus(self, responses: List[str], _results: List[Dict[str, An
return responses[0]

# Create synthesis agent to combine all responses
synthesis_agent = OpenRouterAgent(silent=True)
synthesis_agent = GroqAgent(silent=True)

# Build agent responses section
agent_responses_text = ""
Expand Down