diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 164a74ae..260cab31 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -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" diff --git a/docs/swarms/concept/swarm_architectures.md b/docs/swarms/concept/swarm_architectures.md index e2d206fd..20aefb4a 100644 --- a/docs/swarms/concept/swarm_architectures.md +++ b/docs/swarms/concept/swarm_architectures.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 | diff --git a/docs/swarms/examples/multi_agent_router_minimal.md b/docs/swarms/examples/multi_agent_router_minimal.md new file mode 100644 index 00000000..71fc3076 --- /dev/null +++ b/docs/swarms/examples/multi_agent_router_minimal.md @@ -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). \ No newline at end of file diff --git a/docs/swarms/structs/swarm_router.md b/docs/swarms/structs/swarm_router.md index 03de7071..f20fbe3c 100644 --- a/docs/swarms/structs/swarm_router.md +++ b/docs/swarms/structs/swarm_router.md @@ -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. diff --git a/examples/multi_agent/mar/multi_agent_router_minimal.py b/examples/multi_agent/mar/multi_agent_router_minimal.py new file mode 100644 index 00000000..898ccef3 --- /dev/null +++ b/examples/multi_agent/mar/multi_agent_router_minimal.py @@ -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) \ No newline at end of file