Merge pull request #896 from ascender1729/feat/examples-batched-tasks-dual-model-init

[docs][example][routing][bounty-eligible] Create minimal MultiAgentRouter example
pull/904/head
Kye Gomez 2 weeks ago committed by GitHub
commit f2a2eb4e35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -344,6 +344,7 @@ nav:
- Group Chat Example: "swarms/examples/groupchat_example.md"
- Sequential Workflow Example: "swarms/examples/sequential_example.md"
- SwarmRouter Example: "swarms/examples/swarm_router.md"
- MultiAgentRouter Minimal Example: "swarms/examples/multi_agent_router_minimal.md"
- ConcurrentWorkflow Example: "swarms/examples/concurrent_workflow.md"
- MixtureOfAgents Example: "swarms/examples/mixture_of_agents.md"
- Unique Swarms: "swarms/examples/unique_swarms.md"

@ -34,6 +34,7 @@ Swarm architectures leverage these communication patterns to ensure that agents
| Spreadsheet Swarm | Manages tasks at scale, tracking agent outputs in a structured format like CSV files. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/spreadsheet_swarm/) | Large-scale marketing analytics, financial audits |
| Forest Swarm | A swarm structure that organizes agents in a tree-like hierarchy for complex decision-making processes. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/forest_swarm/) | Multi-stage workflows, hierarchical reinforcement learning |
| Swarm Router | Routes and chooses the swarm architecture based on the task requirements and available agents. | [Code Link](https://docs.swarms.world/en/latest/swarms/structs/swarm_router/) | Dynamic task routing, adaptive swarm architecture selection, optimized agent allocation |
| MultiAgentRouter | Boss agent selects the best agent for each task. | [Minimal Example](https://github.com/kyegomez/swarms/blob/master/examples/multi_agent/mar/multi_agent_router_minimal.py) | Task-specific agent routing |

@ -0,0 +1,33 @@
# MultiAgentRouter Minimal Example
This example shows how to route a task to the most suitable agent using `SwarmRouter` with `swarm_type="MultiAgentRouter"`.
```python
from swarms import Agent
from swarms.structs.swarm_router import SwarmRouter
agents = [
Agent(
agent_name="Researcher",
system_prompt="Answer questions briefly.",
model_name="gpt-4o-mini",
),
Agent(
agent_name="Coder",
system_prompt="Write small Python functions.",
model_name="gpt-4o-mini",
),
]
router = SwarmRouter(
name="multi-agent-router-demo",
description="Routes tasks to the most suitable agent",
agents=agents,
swarm_type="MultiAgentRouter"
)
result = router.run("Write a function that adds two numbers")
print(result)
```
View the source on [GitHub](https://github.com/kyegomez/swarms/blob/master/examples/multi_agent/mar/multi_agent_router_minimal.py).

@ -419,6 +419,8 @@ multi_agent_router = SwarmRouter(
result = multi_agent_router.run("Analyze the competitive landscape for our new product")
```
See [MultiAgentRouter Minimal Example](../examples/multi_agent_router_minimal.md) for a lightweight demonstration.
### HierarchicalSwarm
Use Case: Creating a hierarchical structure of agents with a director.

@ -0,0 +1,25 @@
from swarms import Agent
from swarms.structs.swarm_router import SwarmRouter
agents = [
Agent(
agent_name="Researcher",
system_prompt="Answer questions briefly.",
model_name="gpt-4o-mini",
),
Agent(
agent_name="Coder",
system_prompt="Write small Python functions.",
model_name="gpt-4o-mini",
),
]
router = SwarmRouter(
name="multi-agent-router-demo",
description="Routes tasks to the most suitable agent",
agents=agents,
swarm_type="MultiAgentRouter"
)
result = router.run("Write a function that adds two numbers")
print(result)
Loading…
Cancel
Save