Files
workflows-py/examples/client/base/workflow_client.py
Adrian Lyjak db90f89b74 Separate server/client, and move to llama_agents namespace (#277)
* prep packages

* wrong coverage detection I think

* add ts deps?

* extend path for namespaces

* the big move, import issues though

* llama_index.workflows

* llama_agents

* alias may be working

* add type checker ignores for workflows secondary namespace, update ty, and add re-exports

* Add descriptions to new client and server packages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Rather, commit the outputs

* keep the py files separate

* ignore examples deps

* Create afraid-books-own.md

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:16:02 -05:00

40 lines
1.2 KiB
Python

import asyncio
from typing import Literal
from llama_agents.client import WorkflowClient
from pydantic import Field
from workflows.events import StartEvent
class InputNumbers(StartEvent):
a: int
b: int
operation: Literal["addition", "subtraction"] = Field(default="addition")
async def main() -> None:
client = WorkflowClient(base_url="http://localhost:8000")
workflows = await client.list_workflows()
print("===== AVAILABLE WORKFLOWS ====")
print(workflows)
await client.is_healthy() # will raise an exception if the server is not healthy
handler = await client.run_workflow_nowait(
"add_or_subtract",
start_event=InputNumbers(a=1, b=3, operation="addition"),
context=None,
)
handler_id = handler.handler_id
print("==== STARTING THE WORKFLOW ===")
print(f"Workflow running with handler ID: {handler_id}")
print("=== STREAMING EVENTS ===")
async for event in client.get_workflow_events(handler_id=handler_id):
print(f"Received event type={event.type} data={event.value}")
result = await client.get_handler(handler_id)
print(f"Final result: {result.result} (status: {result.status})")
if __name__ == "__main__":
asyncio.run(main())