Skip to content

API Reference parrot.tools.working_memory.task_memory.artifacts

github-actions[bot] edited this page Nov 10, 2026 · 4 revisions

parrot.tools.working_memory.task_memory.artifacts

View source

In-memory versioned artifact backend (FEAT-538, decision D1).

This is the pluggable backend of WorkingMemoryCatalog — not a sibling index. It answers four questions the catalog alone cannot:

  1. Which exact bytes did a step prove something with? Aliases are mutable; artifact_id@version is not. Overwriting an alias allocates a new version of the same identity and moves the alias to it, leaving the old version valid and resolvable. An overwrite is therefore never a mutation of prior evidence.
  2. Whose is it? Every operation takes a trusted :class:~parrot.tools.working_memory.task_memory.models.TaskScope first and checks it. A globally unique artifact_id is an identifier, not a capability.
  3. Are we still holding the bytes? Retention is byte-accounted against a bounded LRU. When bytes go, the descriptor says so — availability flips and, for pinned evidence, an explicit invalidation receipt is raised. Nothing is quietly presented as verified after its bytes are gone.
  4. Does the fingerprint mean anything? That question belongs to :mod:.snapshots, and this module never second-guesses its answer: whatever it reports as unverifiable is recorded unverifiable.

.. warning::

Delivery A is not durable. This backend is process-local. It is for tests and single-process compatibility; nothing here survives a restart. Durable multi-pod continuity arrives with Delivery B's PostgreSQL store and blob write-through.

Concurrency

Snapshotting and hashing dominate registration cost (Phase 0 measured ~9.5 s for a 256 MiB numeric frame) so they run on a worker thread outside the mutation lock. Version allocation, alias movement, LRU accounting and publication all happen on the owning event loop under a single :class:asyncio.Lock. Two concurrent writers to the same alias therefore serialize at allocation and receive distinct, monotonically increasing versions — while neither blocks the other's hashing.

The lock is never held across snapshotting, and never across tool execution.

Class CapacityReport

What the store is currently holding.

Both retained snapshots and retained live references count, which is what makes this an honest figure: an unverifiable value is not copied, but keeping a reference to it keeps it alive just the same.

Parameter Type Default Description
retained_bytes int
limit int
version_count int
pinned_bytes int
tombstone_count int

Fields:

Field Type Default Description
retained_bytes int Bytes currently accounted against the budget.
limit int The configured ceiling.
version_count int Versions with bytes still retained.
pinned_bytes int Of retained_bytes, how much is pinned evidence and therefore only evictable as a last resort.
tombstone_count int Versions whose metadata survives without bytes.

Attributes:

Attribute Type Description
available_bytes int Headroom left before eviction begins (never negative).

Attribute DEFAULT_ARTIFACT_PAGE

Type: int

Class EvictionReason

Why a version's retained bytes were released.

Class InMemoryArtifactStore

Process-local :class:ArtifactStore with scoped versioned aliases.

Satisfies the full :class:parrot.interfaces.artifact_store.ArtifactStore protocol and passes ArtifactStoreConformance.

Parameter Type Default Description
config Optional[TaskMemoryConfig] None Task-memory configuration. Supplies the RAM snapshot cap (64 MiB) and the retained-bytes budget (512 MiB).
spill_handler Optional[SpillHandler] None Optional durable tier for oversized supported values. Delivery A supplies none.

Method InMemoryArtifactStore.put

Register a value, allocating or incrementing its version.

Snapshotting and fingerprinting run on a worker thread before the lock is taken; only allocation and publication are serialized. See the module docstring.

pin_for registers and pins in one act, and that matters for more than convenience. Capacity is enforced at the end of this call, and a version that is not yet pinned is an ordinary eviction candidate — so a value pinned only afterwards can be evicted at birth, before its pin ever applies. Passing pin_for is the only way a newly registered version competes for retention on equal terms with existing pinned evidence.

put(scope: TaskScope, key: str, value: Any, *, task_id: Optional[str] = None, kind: Optional[ArtifactKind] = None, description: str = '', producer_call_id: Optional[str] = None, attribution: Attribution = Attribution.NONE, turn_id: Optional[str] = None, metadata: Optional[dict] = None, transaction: Optional[Any] = None, pin_for: Optional[str] = None) -> ArtifactDescriptor

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
key str Working-memory alias to publish under.
value Any The value to register.
task_id Optional[str] None Owning task, when one is selected.
kind Optional[ArtifactKind] None Explicit evidence type; inferred when None.
description str '' Human-readable description (retained by the caller's catalog, not stored in the descriptor).
producer_call_id Optional[str] None The physical attempt that produced it.
attribution Attribution Attribution.NONE How that attempt was attributed.
turn_id Optional[str] None The conversation turn.
metadata Optional[dict] None Caller metadata. Unused here; the catalog owns it.
transaction Optional[Any] None Shared transaction. In-memory storage has nothing to enlist, so this is accepted and ignored.
pin_for Optional[str] None Task id to pin this version for, atomically with registration. See above.

Returns: ArtifactDescriptor — The read projection of the newly registered version.

Raises:

  • LimitExceeded — If the alias key is longer than :data:Limits.MAX_IDENTIFIER.

Method InMemoryArtifactStore.capacity

Return what the store is currently holding.

capacity() -> CapacityReport

Returns: CapacityReport — class:CapacityReport.

Method InMemoryArtifactStore.drain_receipts

Take and clear the pending invalidation receipts.

The task service converts these into artifact_invalidated journal events. This module deliberately owns no journal.

drain_receipts() -> Tuple[InvalidationReceipt, ...]

Returns: Tuple[InvalidationReceipt, ...] — The receipts, oldest first.

Method InMemoryArtifactStore.pin_evidence

Record that task_id references this version as evidence.

Pinning is what keeps a version out of ordinary LRU eviction. Several tasks may pin the same version — cross-task evidence references defer deletion until every pin is gone.

pin_evidence(scope: TaskScope, ref: EvidenceRef, task_id: str) -> bool

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version to pin.
task_id str The task referencing it.

Returns: bool — True when the pin was recorded, False when the version does not exist in this scope.

Method InMemoryArtifactStore.unpin_evidence

Remove one task's evidence reference to a version.

unpin_evidence(scope: TaskScope, ref: EvidenceRef, task_id: str) -> bool

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version.
task_id str The task releasing it.

Returns: bool — True when a pin was removed.

Method InMemoryArtifactStore.pins_for

Return the task ids pinning a version.

pins_for(scope: TaskScope, ref: EvidenceRef) -> Tuple[str, ...]

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version.

Returns: Tuple[str, ...] — The pinning task ids, sorted. Empty when unknown or unpinned.

Method InMemoryArtifactStore.get_current

Resolve an alias to the version it currently points at.

get_current(scope: TaskScope, key: str, *, task_id: Optional[str] = None) -> Optional[ArtifactDescriptor]

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
key str The alias.
task_id Optional[str] None Owning task namespace.

Returns: Optional[ArtifactDescriptor] — The current descriptor, or None when the alias is unknown in this namespace.

Method InMemoryArtifactStore.get_version

Resolve one exact version, checking scope.

get_version(scope: TaskScope, ref: EvidenceRef, *, task_id: Optional[str] = None) -> Optional[ArtifactDescriptor]

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version.
task_id Optional[str] None Owning task, when validating a same-scope cross-task evidence reference. A mismatch is reported as absent.

Returns: Optional[ArtifactDescriptor] — The descriptor, or None.

Method InMemoryArtifactStore.load_payload

Materialize a version's payload under a hard byte ceiling.

The ceiling is checked before anything is handed back; an over-limit read carries no payload at all. For tabular values a bounded page may be returned without the whole table ever being measured against the ceiling — the page is measured instead.

load_payload(scope: TaskScope, ref: EvidenceRef, *, max_bytes: int, offset: Optional[int] = None, limit: Optional[int] = None) -> PayloadResult

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version to read.
max_bytes int Hard byte ceiling. 0 means never materialize.
offset Optional[int] None Row offset, for tabular values.
limit Optional[int] None Row count, for tabular values.

Returns: PayloadResult — Either the payload or a refusal reason.

Raises:

  • ValueError — If max_bytes is negative.

Method InMemoryArtifactStore.list

Page artifact descriptors in a scope.

Descriptors are metadata only; building the page touches no payload, calls no repr() and computes no summary.

list(scope: TaskScope, *, task_id: Optional[str] = None, kinds: Optional[Sequence[ArtifactKind]] = None, limit: int = DEFAULT_ARTIFACT_PAGE, cursor: Optional[str] = None, as_of_seq: Optional[int] = None) -> ArtifactPage

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
task_id Optional[str] None Restrict to one task's namespace.
kinds Optional[Sequence[ArtifactKind]] None Restrict to these evidence types.
limit int DEFAULT_ARTIFACT_PAGE Bounded page size.
cursor Optional[str] None Opaque cursor from a previous page.
as_of_seq Optional[int] None Accepted for contract symmetry. The in-memory store has no journal fence, so it is recorded in the cursor query and otherwise unused.

Returns: ArtifactPage — A bounded page of descriptors.

Raises:

  • CursorError — If the cursor is malformed, out of bounds, or was issued for a different scope or query.

Method InMemoryArtifactStore.invalidate

Mark one version's content as no longer valid evidence.

Bytes are left alone: invalidation is a statement about evidence, not about storage, and a persisted payload remains loadable.

invalidate(scope: TaskScope, ref: EvidenceRef, *, reason: str, transaction: Optional[Any] = None) -> ArtifactDescriptor

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version.
reason str Why.
transaction Optional[Any] None Accepted and ignored by the in-memory store.

Returns: ArtifactDescriptor — The updated descriptor.

Raises:

  • ScopeViolation — If the version does not exist in this scope.

Method InMemoryArtifactStore.evict

Release a version's retained bytes, keeping its metadata.

Explicit eviction does not invalidate: the caller asked for the bytes back and the fingerprint still describes what the version contained. Pinned evidence is still evicted on request — but a receipt is raised so the caller cannot lose track of it.

evict(scope: TaskScope, ref: EvidenceRef) -> bool

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The exact version.

Returns: bool — True when bytes were released.

Method InMemoryArtifactStore.drop_alias

Remove a live alias without deleting the versions behind it.

The identity and its version counter survive as a tombstone, so a later re-put under the same key continues at latest + 1. Restarting at 1 would let a fresh unrelated version shadow still-pinned evidence.

drop_alias(scope: TaskScope, key: str, *, task_id: Optional[str] = None) -> bool

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
key str The alias to remove.
task_id Optional[str] None Owning task namespace.

Returns: bool — True when the alias existed.

Method InMemoryArtifactStore.transaction

Yield a transaction handle this store and a task store can share.

In-memory storage has nothing to commit or roll back; the handle exists so the same call sites work against both backends.

transaction() -> AsyncIterator['_MemoryTransaction']

Returns: AsyncIterator['_MemoryTransaction']

Method InMemoryArtifactStore.close

Drop everything held in memory.

close() -> None

Class InvalidationReceipt

Record that pinned evidence could not be retained.

Delivery A cannot promise retained bytes. When the byte budget forces out a version that a task still references as evidence, silently dropping it would leave a step labeled valid with nothing behind it. Instead the store invalidates the version, keeps a metadata tombstone, and raises one of these.

The task service drains these and turns them into artifact_invalidated journal events. They are receipts, not events: this module has no journal and must not acquire one.

Parameter Type Default Description
scope TaskScope
ref EvidenceRef
task_id Optional[str]
pinned_by Tuple[str, ...]
reason str
released_bytes int
occurred_at Any

Fields:

Field Type Default Description
scope TaskScope Owning scope.
ref EvidenceRef The exact version whose bytes were released.
task_id Optional[str] The task that owned the version.
pinned_by Tuple[str, ...] Every task that referenced it as evidence.
reason str Why the bytes went.
released_bytes int How many bytes were reclaimed.
occurred_at Any When.

Class SpillHandler

Optional durable tier for values above the RAM snapshot cap.

Delivery A ships no implementation: without a handler an oversized supported value is recorded with bounded metadata and evidence_verifiable=False, because nothing is retaining it. Delivery B's blob adapter implements this.

Method SpillHandler.spill

Write a value to durable storage and return its reference.

spill(scope: TaskScope, ref: EvidenceRef, kind: ArtifactKind, value: Any) -> SpillReceipt

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The version being written.
kind ArtifactKind Its evidence type.
value Any The value to write.

Returns: SpillReceipt — The receipt describing what was written.

Method SpillHandler.load

Read spilled bytes back under a hard ceiling.

load(scope: TaskScope, ref: EvidenceRef, storage_ref: str, *, max_bytes: int) -> Any

Parameter Type Default Description
scope TaskScope Trusted runtime scope.
ref EvidenceRef The version to read.
storage_ref str Reference returned by :meth:spill.
max_bytes int Hard byte ceiling.

Returns: Any — The materialized value.

Class SpillReceipt

What a durable tier returns after accepting an oversized value.

Parameter Type Default Description
storage_ref str
byte_size int
fingerprint Optional[str] None
fingerprint_algorithm Optional[str] None

Fields:

Field Type Default Description
storage_ref str Backend reference to the written bytes. Never published before the bytes exist.
byte_size int Size of what was written.
fingerprint Optional[str] None Canonical content fingerprint, when the tier computed one. None leaves the version unverifiable rather than inventing an integrity claim.
fingerprint_algorithm Optional[str] None Identity and version of that algorithm.

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