Skip to main content
Two progress mechanisms exist and they are complementary:
  • This pageemit_tool_progress() from praisonaiagents.streaming.events. Use when you want progress to flow through the stream event bus (UI callbacks, stream=True consumers).
  • Deferred & Progress ToolsToolProgress + on_progress= callback + defer() from praisonaiagents.tools. Use when you want the executor to record progress on the ToolResult and support long-running deferred jobs.
Call emit_tool_progress() from inside any tool to push partial output while it runs — zero overhead when no consumer is listening.
The user runs a long tool with streaming enabled; partial progress events surface in the UI while the tool still runs.

Quick Start

1

Emit progress from your tool

Call emit_tool_progress anywhere inside a tool function:
2

Connect a streaming consumer

Subscribe a callback that listens for TOOL_PROGRESS events:

How It Works

The channel is thread-local via contextvars.ContextVar — safe in multi-agent scenarios with concurrent tool calls.

API Reference

emit_tool_progress

Returns 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.

Common Patterns

Percentage progress bar

Separate stdout and stderr streams

Long-running shell command


Best Practices

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.
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.
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.
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.
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.

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

Deferred & Progress Tools

Callback-based progress + deferred results on ToolResult