Skip to content

API Reference parrot.tools.working_memory.task_memory.config

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

parrot.tools.working_memory.task_memory.config

View source

Configuration for recoverable task memory (FEAT-538).

Task memory is opt-in. With no configuration the toolkit behaves exactly as it does today: legacy schemas, legacy raw-result behaviour, no task tools, no observer, no journal (spec AC13).

Every knob is read from navconfig under the TASK_MEMORY_* prefix by :meth:TaskMemoryConfig.from_env, but a caller may also construct the model directly — tests do, and so does any host that configures the toolkit programmatically. Importing this module never touches the network, a database or a file.

.. warning::

Delivery A is not durable. Setting durable=True expresses an intent; it is honoured only once Delivery B's PostgreSQL store is wired in, and the store factory — not this module — performs the lazy backend availability check. Nothing here downgrades a durability request silently.

Attribute DEFAULT_REDACTED_KEYS

Type: FrozenSet[str]

Class DurableStartupError

A durable deployment could not satisfy its own prerequisites.

Raised at startup rather than at the first append. The alternative — degrading to the in-memory store — is precisely the failure this feature exists to prevent: the deployment looks healthy, and the loss only becomes visible after the restart that was supposed to be survivable.

Attribute MIB

Type: int

Class TaskMemoryConfig

Opt-in configuration for the task-memory subsystem.

Defaults reproduce the specification's §2 limits and §2 Retention and Redaction table exactly. Where Phase 0 (TASK-2970) measured a default, the measurement is cited on the field.

Fields:

Field Type Default Description
enabled bool False Master switch. False preserves every existing public schema, output, guardrail, permission and compression behaviour byte for byte.
durable bool False Whether the PostgreSQL-backed durable stores are used. Delivery A rejects True.
best_effort_tracking bool False Explicit opt-in to continuing when the journal is unavailable. Degradation is then surfaced in the result (D8); it is never silent.
snapshot_max_bytes int 64 * MIB RAM snapshot cap. Governs the optional RAM copy only — in durable mode supported artifacts below the cap are still written through to durable storage, so raising it buys retained bytes, not durability.
memory_cache_max_bytes int 512 * MIB Byte-accounted LRU ceiling for retained in-memory artifact payloads.
max_rehydrate_bytes int 2000000 Hard ceiling for wm_get_result (include_raw=True). 0 means never rehydrate. A caller may lower this per call but can never raise it.
raw_page_limit_default int 100 Default page size for tabular raw reads.
raw_page_limit_max int 1000 Maximum page size for tabular raw reads.
recall_max_tokens int 2500 Default token budget for one recall.
recall_max_tokens_ceiling int 16000 Largest budget a caller may request.
recall_recent_calls_limit int 8 Default number of recent calls in a recall.
recall_recent_calls_ceiling int 100 Largest recent-call count a caller may request.
recall_cache_ttl_seconds int 600 TTL for the recall cache.
lease_ttl_seconds int 30 TTL for a task append lease, renewed only by its owner.
context_ttl_seconds int 86400 TTL for the cached turn context. The context cache is never authoritative for task state.
inactivity_pause_days int 7 Days without activity before an active task is paused. Reads do not reset activity.
abandoned_cancel_days int 30 Days after an inactivity pause before the task is cancelled, measured from that pause.
terminal_retention_days int 90 Days a terminal task's journal and projection are retained, measured from terminal_at.
unpinned_version_ttl_hours int 24 How long an unpinned, non-current artifact version survives.
orphan_blob_grace_hours int 1 How long an orphan blob survives before sweeping, and only when nothing references it.
journal_soft_limit int 50000 Event count above which recall stops retaining optional recent-call material.
journal_hard_limit int 100000 Event count above which new foreground work is refused. History is never silently discarded.
journal_reserved_events int 1000 Headroom above the hard limit kept for terminal, recovery and retention events.
max_open_tasks_per_scope int Limits.MAX_OPEN_TASKS_PER_SCOPE Simultaneously open tasks per scope.
dsn Optional[str] None
pool_min_size int 1
pool_max_size int 10
blob_prefix str 'task_memory'
retention_interval_seconds float 3600.0
archive_uri Optional[str] None Where terminal journals are archived as JSONL. With no URI, terminal deletion is deliberately irreversible (OQ1).
extra_redacted_keys Tuple[str, ...] () Additional denied key names, merged with :data:DEFAULT_REDACTED_KEYS.
validator_names Tuple[str, ...] ('artifact_exists', 'artifact_fingerprint_matches', 'artifact_non_empty', 'no_pending_tool_failures') Code-registered completion validators available to validated completion policies.

Attributes:

Attribute Type Description
redacted_keys FrozenSet[str] Every denied key name: the built-ins plus configured additions.

Method TaskMemoryConfig.resolve_rehydrate_bytes

Clamp a caller's raw-read budget to the configured ceiling.

The configuration is a hard ceiling: a caller may lower it but cannot raise it. 0 means never rehydrate, and no request can reopen that.

resolve_rehydrate_bytes(requested: Optional[int]) -> int

Parameter Type Default Description
requested Optional[int] The caller's requested budget, or None to use the configured value.

Returns: int — The effective byte budget.

Raises:

  • ValueError — If requested is negative.

Method TaskMemoryConfig.resolve_page_limit

Clamp a tabular page size to the configured maximum.

resolve_page_limit(requested: Optional[int]) -> int

Parameter Type Default Description
requested Optional[int] The caller's requested page size, or None.

Returns: int — The effective page size.

Raises:

  • ValueError — If requested is not positive.

Method TaskMemoryConfig.is_journal_exhausted

Whether the journal may still accept an event.

Foreground work is refused before the reserved headroom is consumed, so terminal, recovery and retention events remain appendable. History is never silently discarded.

is_journal_exhausted(event_count: int, *, reserved: bool = False) -> bool

Parameter Type Default Description
event_count int Events already appended to the task.
reserved bool False Whether the event being appended is a reserved kind (terminal, recovery or retention).

Returns: bool — True when the append must be refused.

Method TaskMemoryConfig.from_env

Build a configuration from TASK_MEMORY_* navconfig values.

Every field is optional: an absent variable keeps this class's default. Explicit overrides win over the environment, which is what lets a host configure the toolkit programmatically without unsetting variables.

from_env(**overrides: Any) -> 'TaskMemoryConfig'

Parameter Type Default Description
**overrides Any {} Field values that take precedence over the environment.

Returns: 'TaskMemoryConfig' — The resolved configuration.

Class TaskMemoryRuntime

Owns the durable backend graph and its background scheduling.

This lives in the configuration module because it is the wiring the configuration describes: one place that turns a :class:TaskMemoryConfig into connected stores, and back again on shutdown. It builds one task store and one artifact store over it, so the toolkit, the observer and the plan factory all share the same backend and the same transaction coordinator (D1). Nothing here constructs a sibling artifact store.

Ownership is tracked deliberately. A runtime handed a pool or a file manager by its host did not create them and must not close them: shutting down a bot should not tear down a connection pool the rest of the application is still using.

Parameter Type Default Description
config TaskMemoryConfig The resolved configuration.
file_manager Optional[Any] None Blob backend. Required when durable is true.
association Optional[Any] None Optional association store, for durable selection.
pool Optional[Any] None An existing asyncpg pool to borrow rather than create.
archive Optional[Any] None Optional :class:ArchiveWriter. Supplied by the host because the packaged writer is scope-bound while this runtime is not; see :meth:_build_sweeper.

Attributes:

Attribute Type Description
store Optional[Any]
artifacts Optional[Any]
blobs Optional[Any]
sweeper Optional[Any]
periodic Optional[Any]
is_running bool Whether the runtime has completed startup.

Method TaskMemoryRuntime.start

Connect the backends and verify their prerequisites.

Idempotent. Every prerequisite is checked BEFORE anything is scheduled, so a misconfigured deployment fails during startup with a message naming what is missing, rather than at the first append with something unreadable from inside a transaction.

start(*, start_scheduler: bool = True) -> 'TaskMemoryRuntime'

Parameter Type Default Description
start_scheduler bool True Whether to run the in-process retention loop. A host scheduling :meth:run_once from a qworker should pass False and leave the loop stopped.

Returns: 'TaskMemoryRuntime' — This runtime.

Raises:

  • DurableStartupError — If a durable prerequisite is missing.

Method TaskMemoryRuntime.track_scope

Register a scope for periodic sweeping.

track_scope(scope: Any) -> None

Parameter Type Default Description
scope Any The scope to sweep on each cycle.

Method TaskMemoryRuntime.run_once

Run one retention sweep. The host-scheduler entry point.

Exposed so a deployment with its own scheduler (a qworker, a cron) can drive retention without this package taking a queue dependency.

run_once(scopes: Optional[Sequence[Any]] = None) -> Any

Parameter Type Default Description
scopes Optional[Sequence[Any]] None Scopes to sweep; the tracked scopes when omitted.

Returns: Any — The sweep report, or None when nothing is configured.

Method TaskMemoryRuntime.task_memory

Build a composition root over the SHARED stores.

task_memory(scope: Any, **kwargs: Any) -> Any

Parameter Type Default Description
scope Any The trusted runtime scope.
**kwargs Any {} Forwarded to :class:TaskMemory.

Returns: Any — The composition root.

Raises:

  • DurableStartupError — If the runtime has not been started.

Method TaskMemoryRuntime.stop

Stop scheduling and close only what this runtime owns.

Safe to call from a cancelled shutdown: each step is independent and reports rather than raises, so one failing close cannot skip the rest and leak the others.

stop() -> None

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