When it comes to running your agency, Agency Swarm provides 3 main methods:
- CopilotKit/AG-UI Interface: The most modern and recommended way to get started.
- Get Response: For backend or custom integrations.
- Terminal Version: Best for quick debugging and testing.
Pre-requisites for CopilotKit/AG-UI Demo
To use the CopilotKit/AG-UI demo (copilot_demo()), make sure you have the following installed:
If these requirements are not met, the demo will not start and you will see an error message.
CopilotKit/AG-UI Interface
To open a CopilotKit interface, use the copilot_demo method:
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.
Get Response
To get a response from your agency directly in code, use the async get_response method:
import asyncio
async def main():
result = await agency.get_response("I want you to build me a website")
print(result.final_output)
asyncio.run(main())
With additional parameters:
async def main():
result = await agency.get_response(
message="I want you to build me a website",
additional_instructions="This is an additional instruction for the task.",
recipient_agent=dev # Optional: specify which agent to send to
)
print(result.final_output)
asyncio.run(main())
Synchronous version:
result = agency.get_response_sync(
message="I want you to build me a website",
additional_instructions="This is an additional instruction for the task.",
recipient_agent=dev # Optional: specify which agent to send to
)
print(result.final_output)
Parameters:
message: The message to send to the agency.
additional_instructions (optional): Additional instructions that will be appended at the end of instructions for the recipient agent.
recipient_agent (optional): The agent to which the message should be sent.
Terminal Version
To run the agency directly from your terminal, use the terminal_demo method:
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.