overview.mdx 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ---
  2. title: "Overview"
  3. description: "Understanding agencies in Agency Swarm."
  4. icon: "globe"
  5. ---
  6. Agency in Agency Swarm is a collection of agents that can collaborate with one another.
  7. ## Benefits of Using an Agency
  8. Utilizing an Agency consisting of multiple agents offers several benefits:
  9. <CardGroup cols={3}>
  10. <Card title="Fewer Hallucinations" icon="bug" iconType="solid">
  11. Agents within an agency can supervise each other, reducing mistakes and handling unexpected scenarios more effectively.
  12. </Card>
  13. <Card title="Complex Tasks" icon="diagram-project" iconType="solid">
  14. Adding more agents allows for longer sequences of actions, enabling the completion of more complex tasks before delivering results to the user.
  15. </Card>
  16. <Card title="Scalability" icon="arrow-up-right-dots" iconType="solid">
  17. Agencies allow you to scale your solutions seamlessly by adding more agents, as the complexity of your system grows.
  18. </Card>
  19. </CardGroup>
  20. <Tip>
  21. Start with a minimal number of agents. Fine-tune them to ensure they function correctly before adding more.
  22. Introducing too many agents initially can make debugging and understanding interactions challenging.
  23. </Tip>
  24. In the latest version, the Agency class orchestrates a collection of `Agent` instances based on a defined structure. It provides enhanced thread management, persistence hooks, and improved communication patterns between agents.
  25. ## Agency Parameters
  26. Overview of parameters in the new `Agency` class:
  27. | Name | Parameter | Description |
  28. |------|-----------|-------------|
  29. | Entry Points | `*entry_points_args` | Positional arguments representing Agent instances that serve as entry points for external interaction. These agents can be directly messaged by users. |
  30. | Communication Flows *(optional)* | `communication_flows` | List of (sender, receiver) tuples defining allowed agent-to-agent message paths. Example: `[(ceo, dev), (ceo, va)]`. Default: `None` |
  31. | Name *(optional)* | `name` | A name for the agency instance. Default: `None` |
  32. | Shared Instructions *(optional)* | `shared_instructions` | Instructions prepended to all agents' system prompts in a string format or a path to markdown file. Default: `None` |
  33. | Shared Tools *(optional)* | `shared_tools` | List of tool instances or BaseTool classes to add to all agents. Default: `None` |
  34. | Shared Tools Folder *(optional)* | `shared_tools_folder` | Path to a folder containing tool files to load and share with all agents. Default: `None` |
  35. | Shared Files Folder *(optional)* | `shared_files_folder` | Path to a folder of files to upload and share with all agents via a common vector store. Default: `None` |
  36. | Shared MCP Servers *(optional)* | `shared_mcp_servers` | List of MCP server instances to attach to all agents. Default: `None` |
  37. | Send Message Tool Class *(optional)* | `send_message_tool_class` | Fallback SendMessage tool class when a `communication_flows` entry does not specify its own tool. Prefer configuring SendMessage variants directly through `communication_flows`. Default: `None` |
  38. | Load Threads Callback *(optional)* | `load_threads_callback` | A callable to load conversation threads for persistence. Default: `None` |
  39. | Save Threads Callback *(optional)* | `save_threads_callback` | A callable to save conversation threads for persistence. Default: `None` |
  40. | User Context *(optional)* | `user_context` | Initial shared context accessible to all agents during runs. Default: `None` |
  41. ## Example
  42. Quick example of how to create an agency with 3 agents using the new structure:
  43. ```python
  44. from datetime import datetime
  45. from agency_swarm import Agency, function_tool
  46. from .ceo import CEO
  47. from .developer import Developer
  48. from .virtual_assistant import VirtualAssistant
  49. ceo = CEO()
  50. dev = Developer()
  51. va = VirtualAssistant()
  52. @function_tool
  53. def get_current_time() -> str:
  54. """Get the current time."""
  55. return datetime.now().isoformat()
  56. # New structure: entry points as positional args, communication flows as keyword arg
  57. agency = Agency(
  58. ceo, dev, # Entry points - these agents can interact with users
  59. communication_flows=[
  60. (ceo, dev), # CEO can initiate communication with Developer
  61. (ceo, va), # CEO can initiate communication with Virtual Assistant
  62. (dev, va) # Developer can initiate communication with Virtual Assistant
  63. ],
  64. shared_instructions="./shared_instructions.md",
  65. shared_tools=[get_current_time], # Available to all agents
  66. user_context={"project_type": "web_application"}
  67. )
  68. ```
  69. ## Next Steps
  70. Make sure to learn more about [Communication Flows](/core-framework/agencies/communication-flows) and [Running an Agency](/core-framework/agencies/running-agency).