running-agency.mdx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ---
  2. title: "Running an Agency"
  3. description: "How to run an Agency."
  4. icon: "rocket"
  5. ---
  6. When it comes to running your agency, Agency Swarm provides 3 main methods:
  7. 1. **CopilotKit/AG-UI Interface**: The most modern and recommended way to get started.
  8. 2. **Get Response**: For backend or custom integrations.
  9. 3. **Terminal Version**: Best for quick debugging and testing.
  10. ## Pre-requisites for CopilotKit/AG-UI Demo
  11. To use the CopilotKit/AG-UI demo (`copilot_demo()`), make sure you have the following installed:
  12. - **Node.js** (v18 or newer recommended): [Download Node.js](https://nodejs.org/)
  13. - **npm** (comes with Node.js)
  14. If these requirements are not met, the demo will not start and you will see an error message.
  15. ## CopilotKit/AG-UI Interface
  16. To open a CopilotKit interface, use the `copilot_demo` method:
  17. ```python
  18. agency.copilot_demo()
  19. ```
  20. This will launch both the backend and a Next.js frontend. Simply follow the `localhost` link from the terminal to start using your agency in a chat-based UI.
  21. ## Get Response
  22. To get a response from your agency directly in code, use the async `get_response` method:
  23. ```python
  24. import asyncio
  25. async def main():
  26. result = await agency.get_response("I want you to build me a website")
  27. print(result.final_output)
  28. asyncio.run(main())
  29. ```
  30. **With additional parameters:**
  31. ```python
  32. async def main():
  33. result = await agency.get_response(
  34. message="I want you to build me a website",
  35. additional_instructions="This is an additional instruction for the task.",
  36. recipient_agent=dev # Optional: specify which agent to send to
  37. )
  38. print(result.final_output)
  39. asyncio.run(main())
  40. ```
  41. **Synchronous version:**
  42. ```python
  43. result = agency.get_response_sync(
  44. message="I want you to build me a website",
  45. additional_instructions="This is an additional instruction for the task.",
  46. recipient_agent=dev # Optional: specify which agent to send to
  47. )
  48. print(result.final_output)
  49. ```
  50. **Parameters**:
  51. - `message`: The message to send to the agency.
  52. - `additional_instructions` (optional): Additional instructions that will be appended at the end of instructions for the recipient agent.
  53. - `recipient_agent` (optional): The agent to which the message should be sent.
  54. ## Track Usage and Cost
  55. <Tip>
  56. Use the `/cost` command in the TUI to see the current session usage and cost.
  57. </Tip>
  58. ![TUI `/cost` output showing session usage and cost](/images/cost.png)
  59. To understand what's inside the `usage` object, see [Observability](/additional-features/observability#usage-payload).
  60. If you're running your agency as an HTTP API, see [Serving Agencies as APIs](/additional-features/fastapi-integration).
  61. ## Terminal UI
  62. The recommended terminal launch path is:
  63. ```bash
  64. npx @vrsen/agentswarm
  65. ```
  66. Run it from your project root when you want the launcher to handle first-run setup and open the terminal UI for you.
  67. This path lets the launcher detect the agency from your project and open the TUI connected to it. Use it when you want the easiest setup path.
  68. For the full launch flow, first-run auth, and the optional terminal launch paths, see [Agent Swarm TUI](/core-framework/agencies/agent-swarm-cli).
  69. <Note>
  70. If you already launch from Python, `agency.tui()` is still supported:
  71. ```python
  72. agency.tui()
  73. ```
  74. Use `agency.tui(reload=False)` if you want to turn off hot reload on file changes.
  75. This Python path stays bound to the `Agency` instance you launch from code by starting the local bridge automatically.
  76. </Note>
  77. <Tip>
  78. When using the terminal to run the agency, you can send messages directly to any top-level agent by using the "mentions" feature. To do this, start your message with the agent's name preceded by an @ symbol (for example, `@Developer I want you to build me a website`). This directs your message to the specified agent instead of the CEO. You can also press the tab key to autocomplete the agent's name.
  79. </Tip>
  80. `tui(show_reasoning=False)` is not supported in the new TUI yet.