bodhi-realtime-agent / ConversationContext
Class: ConversationContext
Defined in: core/conversation-context.ts:24
In-memory conversation timeline that tracks all messages, tool calls, and agent transfers.
Key concepts:
- Items: Append-only list of ConversationItems (user messages, assistant messages, tool events, transfers).
- Checkpoint: A cursor into the items list.
getItemsSinceCheckpoint()returns only new items since the last checkpoint. Used by ConversationHistoryWriter and MemoryDistiller to process incremental batches. - Summary: A compressed representation of older conversation turns. When set via
setSummary(), items before the checkpoint are evicted (they're captured in the summary). - Token estimate: Rough heuristic (
content.length / 4) used to decide when to trigger summarization.
Constructors
Constructor
new ConversationContext():
ConversationContext
Returns
ConversationContext
Accessors
items
Get Signature
get items(): readonly
ConversationItem[]
Defined in: core/conversation-context.ts:29
Returns
readonly ConversationItem[]
summary
Get Signature
get summary():
string|null
Defined in: core/conversation-context.ts:33
Returns
string | null
tokenEstimate
Get Signature
get tokenEstimate():
number
Defined in: core/conversation-context.ts:38
Rough token count estimate for all items + summary (content.length / 4).
Returns
number
Methods
addAgentTransfer()
addAgentTransfer(
fromAgent,toAgent):void
Defined in: core/conversation-context.ts:73
Parameters
fromAgent
string
toAgent
string
Returns
void
addAssistantMessage()
addAssistantMessage(
content):void
Defined in: core/conversation-context.ts:53
Parameters
content
string
Returns
void
addToolCall()
addToolCall(
call):void
Defined in: core/conversation-context.ts:57
Parameters
call
Returns
void
addToolResult()
addToolResult(
result):void
Defined in: core/conversation-context.ts:65
Parameters
result
Returns
void
addUserMessage()
addUserMessage(
content):void
Defined in: core/conversation-context.ts:49
Parameters
content
string
Returns
void
getItemsSinceCheckpoint()
getItemsSinceCheckpoint():
ConversationItem[]
Defined in: core/conversation-context.ts:82
Return all items added since the last checkpoint (or all items if no checkpoint set).
Returns
getSubagentContext()
getSubagentContext(
task,agentInstructions,memoryFacts,recentTurnCount):SubagentContextSnapshot
Defined in: core/conversation-context.ts:100
Build a snapshot of conversation state for a subagent (summary + recent turns + memory).
Parameters
task
agentInstructions
string
memoryFacts
recentTurnCount
number = 10
Returns
markCheckpoint()
markCheckpoint():
void
Defined in: core/conversation-context.ts:87
Advance the checkpoint cursor to the current end of the items list.
Returns
void
setSummary()
setSummary(
summary):void
Defined in: core/conversation-context.ts:92
Store a compressed summary and evict all items before the current checkpoint.
Parameters
summary
string
Returns
void
toReplayContent()
toReplayContent():
ReplayItem[]
Defined in: core/conversation-context.ts:117
Format the conversation as provider-neutral ReplayItem[] for replay after reconnection.