Context Events • AI Agent SDK
Context Events for PraisonAI Agents.
context_events
AI Agent
Context Events for PraisonAI Agents.
Provides context-level tracing for replay functionality. Tracks context changes during agent execution for debugging and replay.
Zero Performance Impact:
- NoOpSink is the default (zero overhead when not used)
- Disabled emitter has near-zero overhead
- Uses __slots__ for memory efficiency
Schema Version: 1.1 (adds optional run_id / parent_seq / node_id; 1.0 files still load)
Import
from praisonaiagents.trace import context_eventsClasses
Types of context events for replay.
ContextEventA single context event for replay.
ContextTraceSinkProtocolProtocol for context trace event sinks.
ContextNoOpSinkNo-operation sink that discards all events.
ContextListSinkSink that collects events in a list.
ContextTraceEmitterEmitter for context trace events.
Functions
Get the current context trace emitter.
set_context_emitter()Set the context trace emitter for the current async context.
reset_context_emitter()Reset the context emitter to its previous state.
trace_context()Context manager for trace emitter lifecycle.
copy_context_to_callable()Wrap a callable to copy the current context to the new thread/executor.
Constants
| Name | Value |
|---|---|
CONTEXT_SCHEMA_VERSION | '1.1' |
_SPAN_START | {'session_start': 'session', 'agent_start': 'agent', 'tool_call_start': 'tool_call', 'workflow_start': 'workflow', 'task_start': 'task', 'step_start': 'step', 'approval_requested': 'approval'} |
_SPAN_END | {'session_end': 'session', 'agent_end': 'agent', 'tool_call_end': 'tool_call', 'workflow_end': 'workflow', 'task_end': 'task', 'step_end': 'step', 'approval_decided': 'approval'} |
_PREVIEW_LIMIT | 500 |
_UNSET | object() |