Skip to main content
AFK supports real-time streaming via Runner.run_stream(). Instead of waiting for the full response, you receive events as they happen: incremental text, tool lifecycle updates, and terminal status.

Quick example

Event reference

run_stream() emits AgentStreamEvent values with these types:

Streaming modes

  • If the provider supports streaming, AFK forwards model deltas as text_delta.
  • If the provider is non-streaming, AFK emits chunked fallback text_delta from final text so UI behavior stays consistent.

Stream control

AgentStreamHandle is read-only. For lifecycle controls (pause(), resume(), cancel(), interrupt()), use run_handle().

Background tools example

Error handling

error events indicate stream/runtime bridge failures. Tool failures are reported through tool_completed (tool_success=False) and do not necessarily fail the run.

Next steps

Memory

Persist state across streaming runs.

Core Runner

Full lifecycle and API reference.