Stream tokens from anDocumentation Index
Fetch the complete documentation index at: https://docs.swarms.world/llms.txt
Use this file to discover all available pages before exploring further.
Agent the moment the LLM produces them — across every internal loop including tool-call turns, synthesis turns, and the autonomous plan/execute/summary cycle.
The Agent exposes two generator methods:
agent.run_stream(task)— sync generator yieldingstrtokensagent.arun_stream(task)— async generator yieldingstrtokens
max_loops value (1, integer > 1 with tools, or "auto").
Sync Streaming with a Multi-Loop Tool-Calling Agent
Tokens stream during the tool-call turn AND the synthesis turn that runs after the tool returns.Async Streaming
Drop-in for any async caller. The agent loop runs in a thread executor; tokens flow through anasyncio.Queue so the caller’s event loop is never blocked.
Streaming Through the Autonomous Loop
Whenmax_loops="auto", the agent runs a plan→execute→summary cycle. All phases stream their tokens — including the final summary phase.
run_stream and arun_stream are real LLM streaming, not buffered chunking. Tokens arrive over the wall-clock duration of the LLM call (typically 10–80 ms apart inside a network burst), not all at once at the end.Related
- Agent Configuration —
streaming_on,streaming_callback, and the streaming method signatures - Streaming — full overview of every streaming mode
- SequentialWorkflow Streaming — pipeline streaming across multiple agents