Client
WorkflowClient
#
Python client for interacting with a WorkflowServer.
Provides methods for listing workflows, running them synchronously or asynchronously, streaming events, and sending events for human-in-the-loop workflows.
Example:
from llama_agents.client import WorkflowClient
from workflows.events import StartEvent
client = WorkflowClient(base_url="http://localhost:8080")
# Run synchronously
result = await client.run_workflow("greet", start_event=StartEvent(name="Ada"))
print(result.result)
# Run async and stream events
handler = await client.run_workflow_nowait("greet")
stream = client.get_workflow_events(handler.handler_id)
async for event in stream:
print(event.type, event.value)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str | None
|
Base URL of the workflow server (e.g. |
None
|
httpx_client
|
AsyncClient | None
|
Pre-configured |
None
|
Provide exactly one of base_url or httpx_client.
Source code in llama_agents/client/client.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
is_healthy
async
#
is_healthy() -> HealthResponse
Check whether the workflow server is healthy.
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the server returns an error status. |
Source code in llama_agents/client/client.py
220 221 222 223 224 225 226 227 228 229 | |
list_workflows
async
#
list_workflows() -> WorkflowsListResponse
List the names of all workflows registered on the server.
Source code in llama_agents/client/client.py
231 232 233 234 235 236 237 238 | |
get_workflow_schema
async
#
get_workflow_schema(workflow_name: str) -> WorkflowSchemaResponse
Get the start and stop event schemas for a workflow.
Source code in llama_agents/client/client.py
240 241 242 243 244 245 | |
get_workflow_events_schema
async
#
get_workflow_events_schema(workflow_name: str) -> WorkflowEventsListResponse
Get the schemas of events registered for a workflow.
Source code in llama_agents/client/client.py
247 248 249 250 251 252 253 254 | |
get_workflow_graph
async
#
get_workflow_graph(workflow_name: str) -> WorkflowGraphResponse
Get the directed graph representation of a workflow.
Source code in llama_agents/client/client.py
256 257 258 259 260 261 | |
run_workflow
async
#
run_workflow(workflow_name: str, handler_id: str | None = None, start_event: StartEvent | dict[str, Any] | None = None, context: Context | dict[str, Any] | None = None) -> HandlerData
Run the workflow and block until completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_name
|
str
|
Name of the registered workflow to run. |
required |
start_event
|
StartEvent | dict[str, Any] | None
|
Input event for the workflow. Can be a |
None
|
context
|
Context | dict[str, Any] | None
|
Workflow context to restore, for continuing a previous run. |
None
|
handler_id
|
str | None
|
Handler identifier to continue from a previous completed run. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
HandlerData |
HandlerData
|
Handler metadata including the final result. |
Source code in llama_agents/client/client.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
run_workflow_nowait
async
#
run_workflow_nowait(workflow_name: str, handler_id: str | None = None, start_event: StartEvent | dict[str, Any] | None = None, context: Context | dict[str, Any] | None = None) -> HandlerData
Start the workflow without waiting for completion.
Use the returned handler_id to stream events, poll for results,
or send events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow_name
|
str
|
Name of the registered workflow to run. |
required |
start_event
|
StartEvent | dict[str, Any] | None
|
Input event for the workflow. Can be a |
None
|
context
|
Context | dict[str, Any] | None
|
Workflow context to restore, for continuing a previous run. |
None
|
handler_id
|
str | None
|
Handler identifier to continue from a previous completed run. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
HandlerData |
HandlerData
|
Handler metadata including the |
Source code in llama_agents/client/client.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
get_workflow_events
#
get_workflow_events(handler_id: str, include_internal_events: bool = False, after_sequence: int | Literal['now'] = -1, max_reconnect_attempts: int = 3) -> EventStream
Stream events as they are produced by the workflow.
Returns an EventStream whose last_sequence property tracks
the sequence number of the most recently yielded event. Uses SSE
and automatically reconnects from the last received event on
connection drops.
Example:
stream = client.get_workflow_events(handler_id)
async for event in stream:
print(event.type, stream.last_sequence)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_id
|
str
|
ID of the handler running the workflow. |
required |
include_internal_events
|
bool
|
Include internal dispatch events.
Defaults to |
False
|
after_sequence
|
int | Literal['now']
|
Where to start streaming. |
-1
|
max_reconnect_attempts
|
int
|
Maximum reconnect attempts on connection
drop. Defaults to |
3
|
Source code in llama_agents/client/client.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 | |
send_event
async
#
send_event(handler_id: str, event: Event | dict[str, Any], step: str | None = None) -> SendEventResponse
Send an event to a running workflow.
Useful for human-in-the-loop workflows that wait for external input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_id
|
str
|
ID of the handler running the workflow. |
required |
event
|
Event | dict[str, Any]
|
Event to send, as an |
required |
step
|
str | None
|
Target a specific workflow step. When |
None
|
Source code in llama_agents/client/client.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
get_handlers
async
#
get_handlers(status: list[Status] | None = None, workflow_name: list[str] | None = None) -> HandlersListResponse
List all workflow handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
list[Status] | None
|
Filter by handler status (e.g. |
None
|
workflow_name
|
list[str] | None
|
Filter by workflow name. |
None
|
Source code in llama_agents/client/client.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
get_handler
async
#
get_handler(handler_id: str) -> HandlerData
Get a workflow handler by ID.
Returns handler metadata including status, result (if completed), and timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_id
|
str
|
ID of the handler. |
required |
Source code in llama_agents/client/client.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
wait_for_handler
async
#
wait_for_handler(handler_id: str, *, timeout: float | None = None, poll_interval: float = 0.5, max_poll_interval: float = 5.0, backoff: Literal['constant', 'linear', 'exponential'] = 'linear') -> HandlerData
Wait until a workflow handler reaches a terminal status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_id
|
str
|
ID of the handler to poll. |
required |
timeout
|
float | None
|
Maximum number of seconds to wait. |
None
|
poll_interval
|
float
|
Initial number of seconds between status requests. |
0.5
|
max_poll_interval
|
float
|
Maximum number of seconds between requests. |
5.0
|
backoff
|
Literal['constant', 'linear', 'exponential']
|
Strategy for increasing the polling interval after each non-terminal response. |
'linear'
|
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the handler is still running after |
ValueError
|
If |
HTTPStatusError
|
If a status request fails. |
Source code in llama_agents/client/client.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
cancel_handler
async
#
cancel_handler(handler_id: str, purge: bool = False) -> CancelHandlerResponse
Cancel a running workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_id
|
str
|
ID of the handler to cancel. |
required |
purge
|
bool
|
Also remove the handler from the persistence store.
Defaults to |
False
|
Source code in llama_agents/client/client.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
EventStream
#
Async iterator over workflow events that exposes the current stream position.
Returned by WorkflowClient.get_workflow_events(). Use
last_sequence to capture the cursor for resuming later::
stream = client.get_workflow_events(handler_id)
async for event in stream:
print(event.type, stream.last_sequence)
# Resume from where we left off:
stream = client.get_workflow_events(
handler_id, after_sequence=stream.last_sequence
)
Source code in llama_agents/client/client.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
last_sequence
property
#
last_sequence: int | Literal['now']
The sequence number of the most recently yielded event, or the
initial after_sequence value if no events have been yielded yet.
aclose
async
#
aclose() -> None
Cancel the background reader and release resources.
Source code in llama_agents/client/client.py
146 147 148 149 150 151 152 153 154 155 | |