Running Teams
Execute team runs with streaming and non-streaming responses
Create a Python file
import asyncio
import os
from agno.client import AgentOSClient
from agno.run.team import RunCompletedEvent, RunContentEvent
HEADERS = {"Authorization": f"Bearer {os.environ['OS_SECURITY_KEY']}"}
async def run_team_non_streaming():
"""Execute a non-streaming team run."""
print("=" * 60)
print("Non-Streaming Team Run")
print("=" * 60)
client = AgentOSClient(base_url="http://localhost:7778")
# Get available teams
config = await client.aget_config(headers=HEADERS)
if not config.teams:
print("No teams available")
return
team_id = config.teams[0].id
print(f"Running team: {team_id}")
# Execute the team
result = await client.run_team(
team_id=team_id,
message="What is the capital of France and what is 15 * 7?",
headers=HEADERS,
)
print(f"\nRun ID: {result.run_id}")
print(f"Content: {result.content}")
async def run_team_streaming():
"""Execute a streaming team run."""
print("\n" + "=" * 60)
print("Streaming Team Run")
print("=" * 60)
client = AgentOSClient(base_url="http://localhost:7778")
# Get available teams
config = await client.aget_config(headers=HEADERS)
if not config.teams:
print("No teams available")
return
team_id = config.teams[0].id
print(f"Streaming from team: {team_id}")
print("\nResponse: ", end="", flush=True)
async for event in client.run_team_stream(
team_id=team_id,
message="Tell me about Python programming in 2 sentences.",
headers=HEADERS,
):
if isinstance(event, RunContentEvent):
print(event.content, end="", flush=True)
elif isinstance(event, RunCompletedEvent):
pass
print("\n")
async def main():
await run_team_non_streaming()
await run_team_streaming()
if __name__ == "__main__":
asyncio.run(main())Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U "agno[os]" openaiSet the server model key
Set this key in the terminal that starts the example server. The client sends requests to AgentOS and does not call OpenAI directly.
export OPENAI_API_KEY="your_openai_api_key_here"Start an AgentOS Server
Set OS_SECURITY_KEY in the client terminal to the same value used by the server. The code sends it as a bearer credential on each request.
export OS_SECURITY_KEY="your_os_security_key_here"Start the client example server on port 7778. It registers the team used by this client.
Run the Client
python run_teams.py