Option 1: onText (simplest)
If you only need to print or append text chunks, pass onText to run():
run() still returns the full AgentRunResult when finished — streaming is additive, not a separate API shape.
Option 2: agent.stream() (full events)
Use stream() when you need visibility into tool calls, repair attempts, rollbacks, or handoffs — not just text.
AgentRunResult that run() would:
Event types
Use
onEvent on run() if you want these callbacks without managing an async generator:
Provider support
BothcreateAnthropicProvider and createOpenAIProvider implement streamTurn() automatically. No extra config — if the provider supports streaming, kenpachi uses it.
Providers that only implement createTurn() (e.g. test fakes) still work: text arrives as a single text_delta so your event handlers stay consistent.
Building a chat UI
A typical React pattern:streaming while the run is in progress; commit result.text when done.