Skip to content

API Reference parrot.storage.models

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.storage.models

View source

Data models for chat persistence.

Dedicated models that capture the full interaction payload (user input, agent output, metadata, tool calls, sources, timing).

Also contains Pydantic models for artifact and thread persistence (FEAT-103: agent-artifact-persistency).

Class Artifact

Full artifact with definition payload.

The definition field holds the artifact data inline. For CHART artifacts the definition carries a :class:~parrot.models.outputs.StructuredChartConfig dump (camelCase, data excluded). For other artifact types it holds the type-specific payload (canvas blocks, infographic response, …). When the serialised definition exceeds 200 KB it is offloaded to S3 and definition_ref holds the S3 URI instead.

Fields:

Field Type Default Description
artifact_id str
artifact_type ArtifactType
title str
created_at datetime
updated_at datetime
source_turn_id Optional[str] None
created_by ArtifactCreator ArtifactCreator.USER
definition Optional[Dict[str, Any]] None
definition_ref Optional[str] None

Method Artifact.from_structured_config

Create an Artifact for any structured output type (chart / map / table).

Serialises cfg with camelCase aliases and without the data key so that the wire definition carries only the presentation config (rows live in response.data). This is the canonical constructor for the artifacts[] envelope introduced by FEAT-224.

from_structured_config(cfg: Any, artifact_type: ArtifactType, artifact_id: str, title: str, created_at: datetime, updated_at: datetime, **kwargs: Any) -> Artifact

Parameter Type Default Description
cfg Any A Structured{Chart,Table,Map}Config instance.
artifact_type ArtifactType One of :attr:ArtifactType.CHART, :attr:ArtifactType.MAP, or :attr:ArtifactType.TABLE.
artifact_id str Unique artifact identifier (mint once per turn).
title str Display title for the artifact.
created_at datetime Creation timestamp.
updated_at datetime Last-updated timestamp.
**kwargs Any {} Additional :class:Artifact fields (e.g. source_turn_id).

Returns: Artifact — class:Artifact whose definition is the camelCase config dict with data excluded.

Method Artifact.from_chart_config

Create a CHART Artifact whose definition carries the converged config.

Backward-compatible wrapper around :meth:from_structured_config — returns an identical artifact to the pre-FEAT-224 implementation.

from_chart_config(cfg: Any, artifact_id: str, title: str, created_at: datetime, updated_at: datetime, **kwargs: Any) -> Artifact

Parameter Type Default Description
cfg Any A :class:~parrot.models.outputs.StructuredChartConfig instance.
artifact_id str Unique artifact identifier.
title str Display title for the artifact.
created_at datetime Creation timestamp.
updated_at datetime Last-updated timestamp.
**kwargs Any {} Additional Artifact fields (e.g. source_turn_id).

Returns: Artifact — class:Artifact of type :attr:ArtifactType.CHART.

Method Artifact.as_chart_config

Parse definition as a :class:~parrot.models.outputs.StructuredChartConfig.

Returns None when this is not a CHART artifact, definition is absent, or parsing fails.

as_chart_config() -> Any

Returns: Any — class:~parrot.models.outputs.StructuredChartConfig on success, None otherwise.

Class ArtifactCreator

Who created the artifact.

Class ArtifactSummary

Lightweight artifact reference for thread metadata.

Used in list endpoints where the full definition is not needed.

Fields:

Field Type Default Description
id str
type ArtifactType
title str
created_at datetime
updated_at Optional[datetime] None

Class ArtifactType

Type of artifact produced by an agent or user.

Class CanvasBlock

Individual block within a canvas tab.

Fields:

Field Type Default Description
block_id str
block_type CanvasBlockType
content Optional[str] None
artifact_ref Optional[str] None
source_turn_id Optional[str] None
display_options Optional[Dict[str, Any]] None
position int 0

Class CanvasBlockType

Type of block within a canvas tab.

Class CanvasDefinition

Complete canvas tab artifact definition.

Fields:

Field Type Default Description
tab_id str
title str
blocks List[CanvasBlock]
layout str 'vertical'
export_config Optional[Dict[str, Any]] None

Class ChatMessage

Represents a single chat message (one direction: user OR assistant).

This is the atomic persistence unit — one document per message in DocumentDB and one entry per message in the Redis turn list.

Parameter Type Default Description
message_id str
session_id str
user_id str
agent_id str
role str
content str
timestamp datetime datetime.now()
output Optional[Any] None
output_mode Optional[str] None
data Optional[Any] None
code Optional[str] None
model Optional[str] None
provider Optional[str] None
response_time_ms Optional[int] None
tool_calls List[ToolCall] list()
sources List[Source] list()
metadata Dict[str, Any] dict()

Fields:

Field Type Default Description
message_id str
session_id str
user_id str
agent_id str
role str
content str
timestamp datetime field(default_factory=datetime.now)
output Optional[Any] None
output_mode Optional[str] None
data Optional[Any] None
code Optional[str] None
model Optional[str] None
provider Optional[str] None
response_time_ms Optional[int] None
tool_calls List[ToolCall] field(default_factory=list)
sources List[Source] field(default_factory=list)
metadata Dict[str, Any] field(default_factory=dict)

Method ChatMessage.to_dict

Serialize to dictionary suitable for DocumentDB storage.

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Method ChatMessage.from_dict

Deserialize from dictionary.

from_dict(data: Dict[str, Any]) -> ChatMessage

Parameter Type Default Description
data Dict[str, Any]

Returns: ChatMessage

Class ChatStorageTurn

Full audit record of one conversation turn (spec FEAT-886 §2 Data Models).

agent_id is the agent NAME (the ChatStorage key); chatbot_id is the bot's memory_key_id and may differ. timestamp and sequence are emitter-owned and immutable once stored.

Fields:

Field Type Default Description
schema_version int 2
turn_id str
user_id str
session_id str
agent_id str
chatbot_id Optional[str] None
timestamp datetime
sequence int 0
user_message str
assistant_response str
context_used Optional[str] None
tools_used List[str]
tool_invocations List[Dict[str, Any]]
error Optional[str] None
token_count Optional[Dict[str, Any]] None
state str 'raw'
norm_version Optional[str] None
metadata Dict[str, Any]
presentation TurnPresentation

Method ChatStorageTurn.from_event_payload

Build from a TurnCompletedEvent payload.

from_event_payload(payload: Dict[str, Any]) -> ChatStorageTurn

Parameter Type Default Description
payload Dict[str, Any]

Returns: ChatStorageTurn

Raises:

  • InvalidTurnPayloadError — turn_id, user_id, session_id, agent_name or a parseable timestamp is missing (permanent defect — never retried).

Method ChatStorageTurn.from_row

Tolerant reader for rows written before and after FEAT-886.

A row carrying schema_version >= 2 is the current layout. A row without it is legacy: missing fields default, tool_calls map to tool_invocations and the reported schema_version is 1. user_id / agent_id / session_id are used only when the row itself does not carry them (legacy rows don't: they are key parts of the backend row).

from_row(row: Dict[str, Any], *, user_id: str = '', agent_id: str = '', session_id: str = '') -> ChatStorageTurn

Parameter Type Default Description
row Dict[str, Any]
user_id str ''
agent_id str ''
session_id str ''

Returns: ChatStorageTurn

Method ChatStorageTurn.to_row

JSON-safe dict for ConversationBackend.put_turn.

timestamp is ISO-8601 UTC and sequence an int: the backends derive their chronological index from exactly these two keys.

to_row() -> Dict[str, Any]

Returns: Dict[str, Any]

Method ChatStorageTurn.to_conversation_turn

Project onto the working-memory turn; presentation is dropped.

to_conversation_turn() -> ConversationTurn

Returns: ConversationTurn

Method ChatStorageTurn.to_messages

The user + assistant dicts ChatStorage.load_conversation returns, with rich fields.

to_messages() -> List[Dict[str, Any]]

Returns: List[Dict[str, Any]]

Class Conversation

Conversation metadata — one document per session in DocumentDB.

Tracks the lifecycle of a conversation session: when it started, when the last message was sent, token counts, title, etc.

Parameter Type Default Description
session_id str
user_id str
agent_id str
title Optional[str] None
created_at datetime datetime.now()
updated_at datetime datetime.now()
message_count int 0
last_user_message Optional[str] None
last_assistant_message Optional[str] None
model Optional[str] None
provider Optional[str] None
metadata Dict[str, Any] dict()

Fields:

Field Type Default Description
session_id str
user_id str
agent_id str
title Optional[str] None
created_at datetime field(default_factory=datetime.now)
updated_at datetime field(default_factory=datetime.now)
message_count int 0
last_user_message Optional[str] None
last_assistant_message Optional[str] None
model Optional[str] None
provider Optional[str] None
metadata Dict[str, Any] field(default_factory=dict)

Method Conversation.to_dict

Serialize to dictionary suitable for DocumentDB storage.

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Method Conversation.from_dict

Deserialize from dictionary.

from_dict(data: Dict[str, Any]) -> Conversation

Parameter Type Default Description
data Dict[str, Any]

Returns: Conversation

Alias ConversationTurn

Re-exported from parrot.memory.abstract.ConversationTurn.

Alias InvalidTurnPayloadError

Re-exported from parrot.storage.errors.InvalidTurnPayloadError.

Class MessageRole

Role of the message sender.

Class Source

A source/reference returned by the agent.

Parameter Type Default Description
content str ''
metadata Dict[str, Any] dict()

Fields:

Field Type Default Description
content str ''
metadata Dict[str, Any] field(default_factory=dict)

Method Source.to_dict

Serialize to dictionary.

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Method Source.from_dict

Deserialize from dictionary.

from_dict(data: Dict[str, Any]) -> Source

Parameter Type Default Description
data Dict[str, Any]

Returns: Source

Class ThreadMetadata

Conversation thread metadata stored in DynamoDB.

This is a new Pydantic model — it does NOT replace the existing Conversation dataclass which is used by the DocumentDB path.

Fields:

Field Type Default Description
session_id str
user_id str
agent_id str
title Optional[str] None
created_at datetime
updated_at datetime
turn_count int 0
pinned bool False
archived bool False
tags List[str]

Alias TokenCount

Re-exported from parrot.memory.compaction.models.TokenCount.

Class ToolCall

A single tool invocation within a turn.

Parameter Type Default Description
name str
status str 'completed'
output Optional[Any] None
arguments Optional[Dict[str, Any]] None

Fields:

Field Type Default Description
name str
status str 'completed'
output Optional[Any] None
arguments Optional[Dict[str, Any]] None

Method ToolCall.to_dict

Serialize to dictionary.

to_dict() -> Dict[str, Any]

Returns: Dict[str, Any]

Method ToolCall.from_dict

Deserialize from dictionary.

from_dict(data: Dict[str, Any]) -> ToolCall

Parameter Type Default Description
data Dict[str, Any]

Returns: ToolCall

Alias ToolInvocation

Re-exported from parrot.memory.compaction.models.ToolInvocation.

Alias ToolStatus

Re-exported from parrot.memory.compaction.models.ToolStatus.

Alias TurnPresentation

Re-exported from parrot.memory.persistence.TurnPresentation.

Alias TurnState

Re-exported from parrot.memory.compaction.models.TurnState.

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