Skip to content

API Reference parrot.memory.persistence

github-actions[bot] edited this page Dec 2, 2026 · 1 revision

parrot.memory.persistence

View source

Turn persistence vocabulary: topics, presentation model, publisher (FEAT-886).

The bot hands the RAW turn plus a :class:TurnPresentation to an optional :class:TurnPublisher; ChatStorage subscribes on the other side of the bus. This module holds no bus lifecycle — see parrot.storage.turn_bus.

Alias AIMessage

Re-exported from parrot.models.responses.AIMessage.

Class BusTurnPublisher

TurnPublisher over a navigator_eventbus.EventBus.

Parameter Type Default Description
bus Any

Method BusTurnPublisher.publish

Emit one envelope on :data:TURN_COMPLETED_TOPIC with event_id == turn_event_id(...).

publish(event: 'TurnCompletedEvent') -> None

Parameter Type Default Description
event 'TurnCompletedEvent' The completed-turn event; its (agent, user, session, turn_id) scope becomes the envelope id.

Raises:

  • KeyError — If the turn dict carries no turn_id.
  • Exception — Whatever the bus raises when the outbox rejects the write — never swallowed.

Attribute CONVERSATION_DELETED_TOPIC

Type: str

Attribute TURN_COMPLETED_TOPIC

Type: str

Alias TurnCompletedEvent

Re-exported from parrot.core.events.lifecycle.events.memory.TurnCompletedEvent.

Class TurnPresentation

Presentation and usage fields the bot derives from the round's AIMessage.

Fields:

Field Type Default Description
output Any None
output_mode Optional[str] None
data Any None
code Optional[str] None
sources List[Dict[str, Any]]
response_time_ms Optional[int] None
tenant Optional[str] None
model Optional[str] None
provider Optional[str] None
usage Optional[Dict[str, Any]] None
cost_usd Optional[float] None

Method TurnPresentation.from_ai_message

Build from a round's AIMessage. Never raises on a missing attribute; absent → None.

from_ai_message(response: 'AIMessage', *, output_mode: Optional[str], response_time_ms: Optional[int], tenant: Optional[str]) -> 'TurnPresentation'

Parameter Type Default Description
response 'AIMessage' The round's final AIMessage.
output_mode Optional[str] The resolved output mode (string value), if any.
response_time_ms Optional[int] The bot's own elapsed time for the round.
tenant Optional[str] The bound request tenant (current_tenant.get()).

Returns: 'TurnPresentation' — A populated presentation; every field the message lacks is None / [].

Class TurnPublisher

Hands one completed turn to the turn bus.

Method TurnPublisher.publish

Hand the event to the bus. Raises only when the outbox rejects the write.

publish(event: 'TurnCompletedEvent') -> None

Parameter Type Default Description
event 'TurnCompletedEvent'

Function turn_event_id

Deterministic bus event_id for one turn, scoped exactly like the turn's storage key.

Every backend keys a turn by (user, agent, session, turn_id); the bus dedups on event_id (globally, for a window), so the id must carry the same scope: a retry of the same turn gets the same id and is deduplicated, while two conversations that reuse a client turn_id get different ids.

turn_event_id(agent_name: str, user_id: str, session_id: str, turn_id: str) -> str

Parameter Type Default Description
agent_name str
user_id str
session_id str
turn_id str

Returns: str

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally