> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Event • AI Agent SDK

> ContextEvent: A single context event for replay.

# ContextEvent

> Defined in the [**Context Events**](../modules/context_events) module.

<Badge color="blue">AI Agent</Badge>

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

## Properties

<ResponseField name="event_type" type="ContextEventType">
  No description available.
</ResponseField>

<ResponseField name="timestamp" type="float">
  No description available.
</ResponseField>

<ResponseField name="session_id" type="str">
  No description available.
</ResponseField>

<ResponseField name="agent_name" type="Optional[str]">
  No description available.
</ResponseField>

<ResponseField name="sequence_num" type="int">
  No description available.
</ResponseField>

<ResponseField name="messages_count" type="int">
  No description available.
</ResponseField>

<ResponseField name="tokens_used" type="int">
  No description available.
</ResponseField>

<ResponseField name="tokens_budget" type="int">
  No description available.
</ResponseField>

<ResponseField name="data" type="Dict[str, Any]">
  No description available.
</ResponseField>

<ResponseField name="branch_id" type="Optional[str]">
  No description available.
</ResponseField>

<ResponseField name="prompt_tokens" type="int">
  No description available.
</ResponseField>

<ResponseField name="completion_tokens" type="int">
  No description available.
</ResponseField>

<ResponseField name="cost_usd" type="float">
  No description available.
</ResponseField>

<ResponseField name="content_hash" type="Optional[str]">
  No description available.
</ResponseField>

<Accordion title="Internal & Generic Methods">
  * **from\_dict**: Create ContextEvent from dictionary.
  * **to\_dict**: Convert to dictionary for serialization.
  * **to\_json**: Convert to JSON string.
</Accordion>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/trace/context_events.py#L165">
  `praisonaiagents/trace/context_events.py` at line 165
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Context Concept" icon="layer-group" href="/docs/docs/concepts/context" />

  <Card title="Context Management" icon="sliders" href="/docs/docs/features/context-management" />

  <Card title="Context Strategies" icon="diagram-project" href="/docs/docs/features/context-strategies" />
</CardGroup>
