Running Workflows
Execute workflow runs with streaming and non-streaming responses
Create a Python file
import asyncio
import os
from agno.client import AgentOSClient
HEADERS = {"Authorization": f"Bearer {os.environ['OS_SECURITY_KEY']}"}
async def run_workflow_non_streaming():
"""Execute a non-streaming workflow run."""
print("=" * 60)
print("Non-Streaming Workflow Run")
print("=" * 60)
client = AgentOSClient(base_url="http://localhost:7778")
# Get available workflows
config = await client.aget_config(headers=HEADERS)
if not config.workflows:
print("No workflows available")
return
workflow_id = config.workflows[0].id
print(f"Running workflow: {workflow_id}")
try:
result = await client.run_workflow(
headers=HEADERS,
workflow_id=workflow_id,
message="What are the benefits of using Python for data science?",
)
print(f"\nRun ID: {result.run_id}")
print(f"Content: {result.content}")
except Exception as e:
print(f"Error: {e}")
async def run_workflow_streaming():
"""Execute a streaming workflow run."""
print("\n" + "=" * 60)
print("Streaming Workflow Run")
print("=" * 60)
client = AgentOSClient(base_url="http://localhost:7778")
# Get available workflows
config = await client.aget_config(headers=HEADERS)
if not config.workflows:
print("No workflows available")
return
workflow_id = config.workflows[0].id
print(f"Streaming from workflow: {workflow_id}")
print("\nResponse: ", end="", flush=True)
try:
printed_content = False
async for event in client.run_workflow_stream(
headers=HEADERS,
workflow_id=workflow_id,
message="Explain machine learning in simple terms.",
):
content = getattr(event, "content", None)
if event.event in ("RunContent", "TeamRunContent") and content:
print(content, end="", flush=True)
printed_content = True
elif (
event.event in ("WorkflowCompleted", "WorkflowAgentCompleted")
and content
and not printed_content
):
# Callable steps may finish without emitting model text deltas.
print(content, end="", flush=True)
printed_content = True
print("\n")
except Exception as e:
print(f"\nError: {type(e).__name__}: {e}")
async def main():
await run_workflow_non_streaming()
await run_workflow_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 workflow used by this client.
Run the Client
python run_workflows.py