Skip to main content
Event emission and observability: subscribe to session and pipeline events, and configure logging, metrics, and tracing for a running agent.

EventEmitter

Lightweight event emitter supporting synchronous and asynchronous handlers. Handlers are registered against events and invoked when the corresponding event is emitted. Coroutine handlers are scheduled on the running event loop, or run to completion if no loop is active. Exceptions raised by handlers are logged and do not propagate to the caller. The emitter is generic over the event key type T; event keys are coerced to strings internally.

Constructor

emit

Emit an event, invoking all registered handlers with the given arguments. Handlers are called in registration order. Coroutine handlers are scheduled on the running event loop. If the emitter is closed, the call is a no-op.
event
T
required
The event to emit.

off

Remove a previously registered handler for an event. If the handler is not registered for the event, the call is a no-op.
event
T
required
The event the handler was registered for.
callback
Callable[..., Any]
required
The handler to remove.

on

Register a handler for an event. Can be used directly by passing a callback, or as a decorator when callback is omitted.
event
T
required
The event to listen for.
callback
Callable[..., Any] | None
The handler to invoke when the event is emitted. If None, a decorator is returned that registers the decorated function.
returns
Callable[..., Any]
The registered callback when callback is provided, otherwise a decorator that registers and returns the function it wraps.

MetricsOptions

Fields

enabled
bool
default:"True"
export_url
Optional[str]
export_headers
Optional[Dict[str, str]]

TracesOptions

Fields

enabled
bool
default:"True"
export_url
Optional[str]
export_headers
Optional[Dict[str, str]]

LoggingOptions

Fields

enabled
bool
default:"False"
level
'str | list[str]'
default:"INFO"
export_url
Optional[str]
export_headers
Optional[Dict[str, str]]

ObservabilityOptions

Fields

traces
Optional[TracesOptions]
metrics
Optional[MetricsOptions]
logs
Optional[LoggingOptions]

setup_logging

Configure the zrt.agents logger with a colorized console handler. Replaces any existing handlers on the zrt.agents logger with a single stream handler writing to standard output. Colorized output is enabled when the output stream supports it. Propagation to ancestor loggers is disabled.
level
default:"20"
Logging level to apply to the logger. Defaults to logging.INFO.
returns
The configured zrt.agents logging.Logger instance.