Skip to content

Memory

OpenDataSci keeps conversation history as rolling turn summaries rather than raw messages. Completed turns are summarised and discarded; only the current in-progress turn is kept in full.

Concepts

Class What it represents
ChatTurnSummary A compressed record of a single completed turn.
ChatHistoryCompaction A further-folded narrative produced by Agent.compact_chat_history().
ChatTurnContext The assembled messages fed to the LLM at the start of each turn — summaries, compaction recall, current plan, and the ongoing turn.

Inspecting memory from graph state

Turn summaries and the compaction record live in AgentState and can be read from a graph snapshot:

snapshot = agent.graph.get_state({"configurable": {"thread_id": session_id}})
turn_summaries = snapshot.values.get("turn_summaries", [])
for record in turn_summaries:
    print(record.to_content())

compaction = snapshot.values.get("chat_history_compaction")
if compaction is not None:
    print(compaction.to_content())

Message types

opendatasci.memory.messages defines typed LangChain message subclasses. Each carries a created_at timestamp. The principal user-facing type is UserMessage, which marks a message as originating from the user and flags interrupt replies via is_input_on_interrupt.

Class Base Purpose
UserMessage HumanMessage A message from the user.
CompactionMessage HumanMessage A harness message carrying a compacted history recall block.
AgentToAgentMessage HumanMessage A message sent from the orchestrator to a sub-agent.
SummaryMessage HumanMessage A harness message carrying a turn-summary recall block.
PlanMessage HumanMessage A harness message carrying the current session plan.
AgentMessage AIMessage A message produced by the LLM agent.

Reference

UserMessage

Bases: HumanMessage, RenderableMessageMixin['UserMessage']

A message that originated directly from the user.


CompactionMessage

Bases: HumanMessage, RenderableMessageMixin['CompactionMessage']

A harness message carrying a compacted history recall block.


AgentToAgentMessage

Bases: HumanMessage, RenderableMessageMixin['AgentToAgentMessage']

A message sent from one agent to another (e.g. orchestrator to ConcurrentWorkerAgent).


SummaryMessage

Bases: HumanMessage, RenderableMessageMixin['SummaryMessage']

Harness-constructed message carrying a turn-summary recall.


PlanMessage

Bases: HumanMessage, RenderableMessageMixin['PlanMessage']

Harness-constructed message carrying the current session plan.


AgentMessage

Bases: AIMessage

A message produced by the LLM agent.


ChatTurnContext dataclass

ChatTurnContext(messages: list[BaseMessage], turn_summaries: list[ChatTurnSummary], chat_history_compaction: ChatHistoryCompaction | None)

The assembled messages for a single LLM call.

Attributes:

Name Type Description
messages list[BaseMessage]

Compaction recall (if any), turn-summary recall messages, the current plan (if any), and the ongoing turn's messages — all rendered for the LLM.

turn_summaries list[ChatTurnSummary]

Updated rolling summary list to write back to agent state.

chat_history_compaction ChatHistoryCompaction | None

Updated compaction to write back to agent state. None means either no compaction exists or it was cleared because the summary window became full and the compaction is no longer needed.


ChatTurnSummary dataclass

ChatTurnSummary(turn_start_timestamp: datetime, turn_end_timestamp: datetime, user_message_summary: str, actions_summary: str, agent_response_summary: str)

Bases: LLMDigestibleMixin

Summary of a single completed conversation turn.


ChatHistoryCompaction dataclass

ChatHistoryCompaction(compacted_at: datetime, timespan: tuple[datetime, datetime] | None, content: str)

Bases: LLMDigestibleMixin

A folded compaction of multiple :class:ChatTurnSummary records.

Produced by :class:ChatHistoryCompactor when the user explicitly requests history compaction. Unlike a per-turn summary this record has no user message or structured fields — only a free-form LLM-generated narrative and the time range it covers.