emit_tool_progress() from inside any tool to push partial output while it runs — zero overhead when no consumer is listening.
Quick Start
How It Works
The channel is thread-local viacontextvars.ContextVar — safe in multi-agent scenarios with concurrent tool calls.
API Reference
emit_tool_progress
| Parameter | Type | Description |
|---|---|---|
output | str | None | Partial text or output chunk (e.g. a line of stdout) |
progress | float | None | Completion fraction in range 0.0–1.0, stored in metadata["progress"] |
metadata | dict | None | Additional structured metadata (e.g. {"stream": "stderr"}) |
True if forwarded to an active sink, False if no sink is active (the common case outside an agent run — safe no-op).
StreamEventType.TOOL_PROGRESS
The event type emitted by emit_tool_progress. Check event.type == StreamEventType.TOOL_PROGRESS in a stream callback to filter these events.
| Field | Type | Description |
|---|---|---|
type | StreamEventType | Always StreamEventType.TOOL_PROGRESS |
content | str | None | The output text passed to emit_tool_progress |
metadata | dict | None | Contains progress (float) and any extra metadata |
timestamp | float | High-precision time.perf_counter() timestamp |
Common Patterns
Percentage progress bar
Separate stdout and stderr streams
Long-running shell command
Best Practices
Zero overhead when unused
Zero overhead when unused
emit_tool_progress is a cheap no-op returning False when no sink is active. Sprinkle it freely in your tool code — it has no performance cost outside an agent run.Keep messages short and structured
Keep messages short and structured
Progress messages should be brief — a single line of output or a status string. Use
metadata for structured data and progress for the completion fraction. Avoid emitting full JSON blobs as the output string.Don't emit too frequently
Don't emit too frequently
Very high-frequency calls (thousands per second) add overhead to the event path. Emit on meaningful boundaries: completed chunks, processed records, or at fixed time intervals.
Use progress for fractional completion
Use progress for fractional completion
The
progress parameter is a float in 0.0–1.0. It’s stored under metadata["progress"] and is the standard way for consumers to render progress bars. If you don’t know total size, omit it and just stream text output.Sink failures never break tool execution
Sink failures never break tool execution
If the registered sink callback raises an exception,
emit_tool_progress catches it, logs at DEBUG level, and returns False. Tool execution always continues regardless of progress delivery failures.Related
Streaming
Core streaming and event system
Streaming Tool Events
TOOL_CALL_START and TOOL_CALL_END events
Run Stream Events
All run-level streaming events
Custom Tools
Building your own tools

