Context Event • AI Agent SDK
ContextEvent: A single context event for replay.
ContextEvent
Defined in the Context Events module.
AI Agent
A single context event for replay.
Represents a discrete change in agent context during execution. Designed for minimal memory footprint and fast serialization.
Attributes: event_type: Type of context event timestamp: Unix timestamp when event occurred session_id: Session identifier for grouping events agent_name: Name of the agent (if applicable) sequence_num: Sequential event number within session messages_count: Number of messages in context at this point tokens_used: Tokens used in context at this point tokens_budget: Total token budget available data: Event-specific data (tool args, message content, etc.) branch_id: Optional branch identifier for parallel execution tracking prompt_tokens: Number of tokens in the prompt/request completion_tokens: Number of tokens in the completion/response cost_usd: Estimated cost in USD for this event content_hash: SHA256 hash of content for duplicate detection run_id: The team/flow/recorded run this event belongs to (1.1) parent_seq: sequence_num of the enclosing (or, on _end, the closed) _start event (1.1) node_id: Graph node the event concerns, e.g. `agent:Writer` (1.1)
Properties
ContextEventTypeNo description available.
floatNo description available.
strNo description available.
Optional[str]No description available.
intNo description available.
intNo description available.
intNo description available.
intNo description available.
Dict[str, Any]No description available.
Optional[str]No description available.
intNo description available.
intNo description available.
floatNo description available.
Optional[str]No description available.
Optional[str]No description available.
Optional[int]No description available.
Optional[str]No description available.
Internal & Generic Methods
- from_dict: Create ContextEvent from dictionary.
- to_dict: Convert to dictionary for serialization.
- to_json: Convert to JSON string.
Source
View on GitHubpraisonaiagents/trace/context_events.py at line 364