-
-
Notifications
You must be signed in to change notification settings - Fork 425
/
multi_agent_router_example.py
42 lines (37 loc) · 1.67 KB
/
multi_agent_router_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from swarms import Agent, MultiAgentRouter
# Example usage:
if __name__ == "__main__":
# Define some example agents
agents = [
Agent(
agent_name="ResearchAgent",
description="Specializes in researching topics and providing detailed, factual information",
system_prompt="You are a research specialist. Provide detailed, well-researched information about any topic, citing sources when possible.",
model_name="openai/gpt-4o",
),
Agent(
agent_name="CodeExpertAgent",
description="Expert in writing, reviewing, and explaining code across multiple programming languages",
system_prompt="You are a coding expert. Write, review, and explain code with a focus on best practices and clean code principles.",
model_name="openai/gpt-4o",
),
Agent(
agent_name="WritingAgent",
description="Skilled in creative and technical writing, content creation, and editing",
system_prompt="You are a writing specialist. Create, edit, and improve written content while maintaining appropriate tone and style.",
model_name="openai/gpt-4o",
),
]
# Initialize routers with different configurations
router_execute = MultiAgentRouter(
agents=agents, execute_task=True
)
# Example task
task = "Write a Python function to calculate fibonacci numbers"
try:
# Process the task with execution
print("\nWith task execution:")
result_execute = router_execute.route_task(task)
print(result_execute)
except Exception as e:
print(f"Error occurred: {str(e)}")