core.history.permanent
Maintain an append-only chronological turn history with coalesced consecutive user turns.
Maintain an append-only chronological turn history with coalesced consecutive user turns.
- class PermanentHistory[source]
Bases:
objectAppend-only chronological turn history with timestamps.
Each turn stores a
role("user"or"assistant"), structuredcontent, a per-turntimestamp, and optionalmetadata. Consecutive user turns are coalesced by appending content unless the caller passes non-Nonemetadata, in which case a new turn is always created (so distinctprompt_namemetadata is never silently merged).- add_turn_assistant(content, metadata=None)[source]
Append an assistant turn with the current timestamp.
- add_turn_user(content, metadata=None)[source]
Append a user turn, coalescing with the previous user turn when adjacent.
Coalescing only happens when metadata is
None. If metadata is provided, a new turn is always created so distinctprompt_namemetadata is never silently merged into the previous user turn.
Classes
- class PermanentHistory[source]
Bases:
objectAppend-only chronological turn history with timestamps.
Each turn stores a
role("user"or"assistant"), structuredcontent, a per-turntimestamp, and optionalmetadata. Consecutive user turns are coalesced by appending content unless the caller passes non-Nonemetadata, in which case a new turn is always created (so distinctprompt_namemetadata is never silently merged).- add_turn_assistant(content, metadata=None)[source]
Append an assistant turn with the current timestamp.
- add_turn_user(content, metadata=None)[source]
Append a user turn, coalescing with the previous user turn when adjacent.
Coalescing only happens when metadata is
None. If metadata is provided, a new turn is always created so distinctprompt_namemetadata is never silently merged into the previous user turn.