Adapt Memory¶
Adapt Memory — mvp.adapt_memory
Cluster: Knowledge & Grounding | Type: component | MCP Tools: 54
Overview¶
adapt_memory has two surfaces. The lightweight AdaptMemoryBlock is an in-process key-value memory store that persists arbitrary values only across infer() calls within the same block instance. It supports store, retrieve, list (with optional limit), delete, clear, and metadata ops on named records that carry a timestamp and optional tag list. The state dict is held on the block dataclass, making it suitable for short-lived agent sessions where a lightweight working memory is needed without a database dependency.
For launch-facing MCP usage, prefer the SQLite-backed memory_mcp server. It persists memory across process restarts via MEMORY_DB_PATH (default ~/.memory/memory.db) and adds episodic, semantic, procedural, relational, STM/LTM, working-memory, search operations, and an explicit advanced backend-adapter layer. Treat the simple in-process block as a basic/internal interface; use memory_mcp for user workflows where non-technical users expect recall to survive installation, restart, and multi-session use.
The stable curated API remains the default. Advanced backend-native operations are opt-in through memory_backend_capabilities, memory_backend_call, memory_extract_entities, memory_backend_search, and memory_pack_context_native. These advanced calls are allowlisted, payload-bounded, audited with redacted metadata, and normalized into completion_state, warning_card, evidence, request_id, and run_id fields.
Reliability mapping (CRUD, three-way): durable SQLite operations return verified ONLY when the evidence carries a store confirmation (a row id or row count); an ephemeral db_path=":memory:" store returns qualified-draft with degradation_reason="ephemeral_store" and a G6_E_MEMORY_EPHEMERAL_STORE warning; a store exception fails closed to blocked-escalated with G6_E_MEMORY_STORE_UNAVAILABLE rather than silently succeeding. There is no path where an in-:memory: or store-failed operation reads as verified. The simple in-process AdaptMemoryBlock is non-durable by construction and is always qualified-draft, never verified; its degraded/degradation_reason channel is reserved for the silent-overwrite signal (key_already_exists). The advanced backend lane was already honest and is unchanged: quality-changing fallbacks return qualified-draft with backend_unavailable:*/fallback_used evidence, and unavailable/disallowed/invalid backend requests return blocked-escalated. The component stays beta (awaiting GDPval calibration).
When to use:
- Accumulating intermediate results across multiple agent steps within a session
- Caching retrieved documents or computed values to avoid redundant processing
- Passing named artefacts between pipeline stages without serialising to disk
- Building a simple blackboard architecture where multiple blocks read and write shared state
Example:
from mvp.adapt_memory import AdaptMemoryBlock, MemoryInput
block = AdaptMemoryBlock(name="memory")
block.infer(MemoryInput(op="store", key="plan", value={"steps": ["research", "draft", "review"]}))
result = block.infer(MemoryInput(op="retrieve", key="plan"))
# result.value.value → {"steps": ["research", "draft", "review"]}
# result.value.found → True
Works well with: adapt_instructor, goal_engine, ctx_rag
Public API¶
AdaptMemoryBlock(AIBlock[MemoryInput, MemoryOutput, dict])¶
In-process key-value memory store.
| Field | Type | Default |
|---|---|---|
name | str | 'adapt_memory' |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(data: MemoryInput) -> Result[MemoryOutput]¶
MemoryRecord(BaseModel)¶
A single entry in the memory store.
| Field | Type | Default |
|---|---|---|
key | str | required |
value | Any | required |
timestamp | float | Field(default_factory=time.time) |
tags | list[str] | Field(default_factory=list) |
confirmation_state | Literal['unconfirmed', 'confirmed'] | 'unconfirmed' |
MemoryInput(BaseModel)¶
Input for AdaptMemoryBlock.
| Field | Type | Default |
|---|---|---|
op | Literal['ops', 'help', 'store', 'retrieve', 'list', 'delete', 'clear', 'confirm'] | required |
key | str | '' |
value | Any | None |
tags | list[str] | Field(default_factory=list) |
limit | int | 100 |
replace | bool | False |
MemoryOutput(BaseModel)¶
Output from AdaptMemoryBlock.
| Field | Type | Default |
|---|---|---|
op | str | required |
key | str | '' |
value | Any | None |
records | list[MemoryRecord] | Field(default_factory=list) |
count | int | 0 |
found | bool | False |
degraded | bool | False |
degradation_reason | str | '' |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated'] | 'qualified-draft' |
warning_card | dict[str, Any] | Field(default_factory=dict) |
evidence | list[dict[str, Any]] | Field(default_factory=list) |
request_id | str | '' |
task_id | str | '' |
run_id | str | '' |
AdaptMemoryBlock(AIBlock[MCPMemoryInput, MCPMemoryOutput, dict])¶
Unified memory block with SQLite persistence and 7 memory types.
| Field | Type | Default |
|---|---|---|
name | str | 'adapt_memory_mcp' |
state | dict \| None | None |
db_path | str | ':memory:' |
wm_capacity | int | 50 |
wm_promotion_threshold | float | 0.7 |
stm_to_ltm_accesses | int | 3 |
resource_bounds | ResourceBounds \| None | None |
usage | ResourceUsage | field(default_factory=ResourceUsage) |
Methods:
infer(data: MCPMemoryInput) -> Result[MCPMemoryOutput]¶
MCPMemoryRecord(BaseModel)¶
A single memory record stored in SQLite.
| Field | Type | Default |
|---|---|---|
id | str | Field(default_factory=lambda: str(uuid.uuid4())) |
key | str | required |
value | str | required |
tier | Literal['wm', 'stm', 'ltm', 'any'] | 'any' |
memory_type | Literal['episodic', 'semantic', 'procedural', 'relational', 'general'] | 'general' |
tags | list[str] | Field(default_factory=list) |
timestamp | str | Field(default_factory=lambda: datetime.now(timezone.utc).isoformat()) |
version | int | 1 |
provenance | str | '' |
MCPMemoryInput(BaseModel)¶
Input for the unified AdaptMemoryBlock (30 operations).
| Field | Type | Default |
|---|---|---|
op | Literal['ops', 'help', 'store', 'retrieve', 'list', 'delete', 'clear', 'record_event', 'query_timeline', 'summarize_events', 'store_fact', 'query_graph', 'link_entities', 'store_procedure', 'retrieve_procedure', 'evaluate_run', 'set_state', 'get_state', 'log_interaction', 'semantic_search', 'tag_search', 'temporal_search', 'observe', 'attend', 'recall_working', 'wm_status', 'promote', 'pack_context', 'memory_backend_capabilities', 'memory_backend_call', 'memory_extract_entities', 'memory_backend_search', 'memory_pack_context_native', 'recommend', 'list_patterns'] | required |
key | str | '' |
value | str | '' |
tags | list[str] | Field(default_factory=list) |
tier | Literal['wm', 'stm', 'ltm', 'any'] | 'any' |
memory_type | Literal['episodic', 'semantic', 'procedural', 'relational', 'general', 'any'] | 'any' |
limit | int | 100 |
query | str | '' |
top_k | int | 5 |
max_tokens | int | 2000 |
event_type | str | '' |
start_time | str | '' |
end_time | str | '' |
subject | str | '' |
predicate | str | '' |
object_ | str | Field('', alias='object') |
steps | list[str] | Field(default_factory=list) |
success | bool | True |
notes | str | '' |
relevance_score | float | 1.0 |
source | str | '' |
backend_name | str | '' |
backend_action | str | '' |
backend_payload | dict[str, Any] | Field(default_factory=dict) |
request_id | str | Field(default_factory=lambda: str(uuid.uuid4())) |
task_id | str | '' |
run_id | str | Field(default_factory=lambda: str(uuid.uuid4())) |
MCPMemoryOutput(BaseModel)¶
Output from the unified AdaptMemoryBlock.
| Field | Type | Default |
|---|---|---|
op | str | required |
key | str | '' |
value | Any \| None | None |
found | bool | False |
count | int | 0 |
records | list[MCPMemoryRecord] | Field(default_factory=list) |
facts | list[dict[str, Any]] | Field(default_factory=list) |
retrieved | list[str] | Field(default_factory=list) |
scores | list[float] | Field(default_factory=list) |
summary | str | '' |
message | str | '' |
agentic_evidence | dict[str, Any] | Field(default_factory=dict) |
degraded | bool | False |
degradation_reason | str | '' |
request_id | str | Field(default_factory=lambda: str(uuid.uuid4())) |
task_id | str | '' |
run_id | str | Field(default_factory=lambda: str(uuid.uuid4())) |
completion_state | Literal['verified', 'qualified-draft', 'blocked-escalated'] | 'qualified-draft' |
warning_card | dict[str, Any] | Field(default_factory=dict) |
evidence | list[dict[str, Any]] | Field(default_factory=list) |
MemoryStore¶
Sync SQLite memory store with 6 tables covering all memory types.
Constructor:
| Parameter | Type | Default |
|---|---|---|
db_path | str | ':memory:' |
stm_to_ltm_threshold | int | 3 |
authoritative_statuses | frozenset[str] \| set[str] \| None | None |
Methods:
store_record(key: str, value: str, tier: str = 'any', memory_type: str = 'general', tags: list[str] | None = None, provenance: str = '') -> str¶
Upsert a record; returns the record id.
retrieve(key: str, tier: str = 'any', memory_type: str = 'any') -> dict[str, Any] | None¶
list_records(tier: str = 'any', memory_type: str = 'any', tags: list[str] | None = None, limit: int = 100) -> list[dict[str, Any]]¶
delete(key: str, tier: str = 'any', memory_type: str = 'any') -> bool¶
clear(tier: str = 'any') -> int¶
Clear memory records.
record_event(event_type: str, description: str, tags: list[str] | None = None) -> str¶
query_timeline(start_time: str = '', end_time: str = '', event_type: str = '', limit: int = 100) -> list[dict[str, Any]]¶
store_fact(subject: str, predicate: str, object_: str, tags: list[str] | None = None) -> str¶
query_graph(subject: str = '', predicate: str = '', object_: str = '', limit: int = 50) -> list[dict[str, Any]]¶
store_procedure(key: str, steps: list[str], tags: list[str] | None = None) -> str¶
retrieve_procedure(key: str) -> dict[str, Any] | None¶
list_procedures(limit: int = 100) -> list[dict[str, Any]]¶
record_run(key: str, success: bool = True) -> bool¶
set_state(key: str, value: str) -> None¶
get_state(key: str) -> str | None¶
log_interaction(agent: str, content: str) -> str¶
list_interactions(limit: int = 100) -> list[dict[str, Any]]¶
text_search(query: str, tier: str = 'any', memory_type: str = 'any', top_k: int = 5) -> tuple[list[str], list[float]]¶
Return (texts, scores) ranked by TF-IDF similarity (cached, invalidated on writes).
tag_search(tags: list[str], tier: str = 'any', limit: int = 100) -> list[dict[str, Any]]¶
Return records whose tags intersect with the given tag set.
temporal_search(start_time: str = '', end_time: str = '', limit: int = 100) -> list[dict[str, Any]]¶
Return records in an ISO timestamp range.
count_records() -> int¶
close() -> None¶
record_backend_audit(operation: str, backend: str, action: str, payload_size: int, timeout_ms: int, result_status: str, degradation: bool, fallback: str, block_reason: str) -> str¶
list_backend_audits(limit: int = 100) -> list[dict[str, Any]]¶
count_by_tier(tier: str) -> int¶
COUNT(*) of records for a given tier. Fast — no row scan.
promote_tier(key: str, new_tier: str) -> bool¶
Update the tier of a record by key. Returns True if a row was updated.
MCP Tools¶
| Operation | Source |
|---|---|
wm | memory_mcp |
stm | memory_mcp |
ltm | memory_mcp |
any | memory_mcp |
episodic | memory_mcp |
semantic | memory_mcp |
procedural | memory_mcp |
relational | memory_mcp |
general | memory_mcp |
ops | memory_mcp |
help | memory_mcp |
store | memory_mcp |
retrieve | memory_mcp |
list | memory_mcp |
delete | memory_mcp |
clear | memory_mcp |
record_event | memory_mcp |
query_timeline | memory_mcp |
summarize_events | memory_mcp |
store_fact | memory_mcp |
query_graph | memory_mcp |
link_entities | memory_mcp |
store_procedure | memory_mcp |
retrieve_procedure | memory_mcp |
evaluate_run | memory_mcp |
set_state | memory_mcp |
get_state | memory_mcp |
log_interaction | memory_mcp |
semantic_search | memory_mcp |
tag_search | memory_mcp |
temporal_search | memory_mcp |
observe | memory_mcp |
attend | memory_mcp |
recall_working | memory_mcp |
wm_status | memory_mcp |
promote | memory_mcp |
pack_context | memory_mcp |
memory_backend_capabilities | memory_mcp |
memory_backend_call | memory_mcp |
memory_extract_entities | memory_mcp |
memory_backend_search | memory_mcp |
memory_pack_context_native | memory_mcp |
recommend | memory_mcp |
list_patterns | memory_mcp |
wm | memory_mcp |
stm | memory_mcp |
ltm | memory_mcp |
any | memory_mcp |
episodic | memory_mcp |
semantic | memory_mcp |
procedural | memory_mcp |
relational | memory_mcp |
general | memory_mcp |
any | memory_mcp |