SDK Guides
Memory and Recall
Configure summarize, retrieval, and async indexing for long-running threads.
#Memory and Recall
A model on its own forgets everything once a conversation gets long enough. Memory is how mAIvn gives an agent a working recollection: it remembers what was said earlier, pulls back the parts that matter for the current question, and learns reusable lessons over time.
Concretely, memory keeps long-running conversations accurate by combining:
- summarization when thread context grows too large
- retrieval of relevant memory signals (vector, keyword, graph, skills, insights, resources)
- asynchronous post-finalize indexing and extraction
#How It Works
Each invocation can include three core stages:
- Summarize: compacts history before execution when needed.
- Retrieve: injects relevant memory context into the current turn.
- Index: persists new memory after the response is returned.
Indexing is asynchronous by design, so latency-sensitive responses are not blocked by persistence work.
#Thread Recall vs Scope-Shared Assets
Memory is intentionally split into two layers:
- Thread recall: summaries, vector hits, keyword hits, graph neighbors, and other transcript-like recall stay tied to the current
thread_id. - Scope-shared assets: skills, bound resources, and promoted insights are reusable across future threads within their sharing scope (
agent,swarm,project, ororg).
This means future threads already benefit from scoped skills and resources.
AI-generated insights are narrower by default: auto extraction only supports agent or swarm, and broader reuse happens through portal promotion to project or org.
#Memory Levels
MemoryConfig.level is the canonical control for retrieval/persistence behavior.
none: no retrieval, no persistence.glimpse: retrieval only.focus: retrieval + vector persistence.clarity: retrieval + vector + graph persistence.
Effective behavior is policy-gated within the runtime (org policy + subscription tier + runtime safety checks).
If requested settings exceed allowed limits, runtime behavior is safely downscoped.
#Quick Start
Use a stable thread_id and set scope defaults:
from maivn import ( Agent, MemoryConfig, MemoryInsightExtractionConfig, MemoryRetrievalConfig, MemorySkillExtractionConfig,)from maivn.messages import HumanMessage agent = Agent( name="memory_demo", system_prompt="Use prior context when relevant.", api_key="your-api-key", memory_config=MemoryConfig( enabled=True, level="clarity", # none | glimpse | focus | clarity summarization_enabled=True, persistence_mode="vector_plus_graph", retrieval=MemoryRetrievalConfig( top_k=4, candidate_limit=6, skills_enabled=True, insights_enabled=True, resources_enabled=True, ), skill_extraction=MemorySkillExtractionConfig( enabled=True, sharing_scope="project", ), insight_extraction=MemoryInsightExtractionConfig( enabled=True, sharing_scope="agent", ), ),) thread_id = "customer-success-q1" agent.invoke( messages=[HumanMessage(content="Store this rollout plan and owners.")], thread_id=thread_id,) result = agent.invoke( messages=[HumanMessage(content="Who owns the rollout milestones?")], thread_id=thread_id,)#Scope Memory Assets
Agent and Swarm can define memory assets directly:
skills: user-defined reusable skill payloadsresources: bound resource payloads (inline content, file, URL, or document reference)
The SDK packages these assets as typed MemoryAssetsConfig on the request rather than
requiring you to pass memory_defined_skills or memory_bound_resources through
free-form invocation metadata.
agent = Agent( name="deploy_agent", api_key="your-api-key", memory_config=MemoryConfig( level="clarity", skill_extraction=MemorySkillExtractionConfig(sharing_scope="project"), ), skills=[ { "skill_id": "deploy-checklist-v1", "name": "deploy_with_health_checks", "description": "Deploy, run health checks, then cut over traffic.", "steps": [ {"index": 1, "action": "deploy service", "tool": "deploy_service"}, {"index": 2, "action": "run health checks", "tool": "run_health_checks"}, ], } ], resources=[ { "name": "deploy-runbook.txt", "mime_type": "text/plain", "text_content": "Rollback immediately if canary validation fails.", "binding_type": "agent", "sharing_scope": "agent", "tags": ["deploy", "rollback"], } ],)#Bound Resource Versioning
Bound resources are content-hash aware. If a resource payload includes an existingresource_id plus fresh content_base64, the runtime compares the supplied bytes with the
stored content_hash:
- same hash: the existing resource is reused and rebound to the current agent or swarm scope
- different hash: a new resource version is registered, the previous active row is marked
superseded, and resource memory activity is moved to the new version
This lets SDK-deployed agents and swarms update bundled documents without requiring a separate
portal replacement step.
#Message Attachments
HumanMessage and RedactedMessage support attachments.
Attachment payloads are normalized and sent as document candidates for registration.
from maivn.messages import HumanMessage message = HumanMessage( content="Use the attached runbook for this request.", attachments=[ { "name": "runbook.txt", "mime_type": "text/plain", "text_content": "Escalate if error rate exceeds 2%.", "sharing_scope": "project", "tags": ["runbook", "ops"], } ],)Supported attachment inputs include content_base64, content_bytes, text_content, and file.
#Per-Invocation Overrides
Override scope defaults per call with memory_config:
from maivn import MemoryConfig, MemoryRetrievalConfig result = agent.invoke( messages=[HumanMessage(content="Use retrieval only for this turn.")], thread_id=thread_id, memory_config=MemoryConfig( level="glimpse", retrieval=MemoryRetrievalConfig( skills_enabled=True, insights_enabled=True, resources_enabled=True, skill_injection_max_count=3, insight_injection_max_count=2, resource_injection_max_count=2, ), ),)#Observe Memory and Resource Events
Use event streaming to inspect enrichment phases:
events = [] def on_event(event: dict) -> None: if event.get("event") != "enrichment": return payload = event.get("payload") or {} phase = payload.get("phase") if isinstance(phase, str) and ( phase.startswith("memory_") or phase.startswith("document_") ): events.append( { "phase": phase, "message": payload.get("message"), "memory": payload.get("memory"), } ) agent.events(include="enrichment", on_event=on_event).invoke( messages=[HumanMessage(content="Recall the project constraints.")], thread_id=thread_id,)Common memory phases:
memory_summarizingmemory_summarizedmemory_retrievingmemory_retrievedmemory_indexingmemory_graph_extractingmemory_indexedmemory_skill_extractingmemory_insight_extracting
Common resource phases:
resource_registeringresource_registeredresource_dedup_reusedresource_version_supersededresource_extractingresource_extracted
payload.memory can include hit counts, per-signal counts (skill_hits, insight_hits, resource_hits), latency, and effective memory level.
#Async Post-Finalize Behavior
memory_indexed, memory_skill_extracting, and memory_insight_extracting can appear after the final response event. This is expected.
For strict verification workflows:
- inspect session event history by
session_id - run a follow-up recall query and confirm
memory_retrievedwith non-zero hit counts - allow a short wait between seed and recall in automated tests
#Configuration Reference
Use MemoryConfig for public SDK memory controls.
Top-level fields:
enabledlevel(none | glimpse | focus | clarity)summarization_enabledpersistence_mode(persist_none | vector_only | vector_plus_graph)retrievalskill_extractioninsight_extraction
Nested retrieval fields:
top_kcandidate_limitskills_enabledinsights_enabledresources_enabledskill_injection_max_countinsight_injection_max_countresource_injection_max_countinsight_relevance_floor
Nested extraction fields:
skill_extraction.enabledskill_extraction.sharing_scopeskill_extraction.confidence_thresholdskill_extraction.max_countinsight_extraction.enabledinsight_extraction.sharing_scopeinsight_extraction.max_countinsight_extraction.min_relevance_score
Notes:
- Reserved memory-control keys are not allowed in invocation
metadata; usememory_config
or scope-levelskills/resources. - Prefer stable
thread_idreuse across turns. insight_extraction.sharing_scopeonly acceptsagentorswarmfor AI-generated insights.- Promote durable lessons to
projectororgfrom the Developer Portal when broader reuse is warranted. - Policy/tier constraints still apply within the runtime even when
memory_configrequests higher capability.