AgentContext maintains a persistent memory layer for LLM agents — storing observations as vector embeddings, retrieving them by semantic similarity, and optionally blending graph proximity into the ranking. Use it when your agent needs to recall past findings across sessions without re-reading source material on every restart.

What Is Agent Memory?

Agent Memory provides persistent storage and intelligent retrieval of information across multiple agent sessions. AgentContext is the core component that orchestrates memory storage, retrieval, and management by combining three key systems: VectorStore handles semantic search using vector embeddings. It stores text as high-dimensional vectors and retrieves similar content through cosine similarity or other distance metrics. ContextGraph maintains structured knowledge as nodes (entities) and edges (relationships). This enables multi-hop traversal and graph-aware retrieval that follows connections between related entities. AgentContext orchestrates both components, providing a unified interface for storing memories, retrieving relevant context, and managing conversations across sessions. Persistent memory vs stateless retrieval: Traditional RAG systems lose context between sessions. Agent Memory persists learned information, conversation history, and accumulated knowledge across restarts, enabling long-term memory and cross-session recall.

Why Use Agent Memory?

Cross-session recall. Agents remember previous interactions, findings, and decisions without re-processing source material after restarts. Long-term knowledge accumulation. Information builds up over time as agents process more documents, creating increasingly rich knowledge bases for future queries. Conversation history. Agents maintain context within conversations and can reference earlier parts of extended interactions or investigations. Graph-aware retrieval. Beyond simple semantic similarity, retrieval follows entity relationships to find connected information that pure vector search would miss. Decision tracking. Record decisions with full context and reasoning paths, enabling audit trails and precedent matching for similar future scenarios.

When To Use / When Not To Use

Use Agent Memory for:
  • Long-running agents that need to accumulate knowledge over time
  • Research assistants that build understanding across multiple sessions
  • Investigation workflows where context builds incrementally
  • Systems that must remember prior interactions and decisions
  • Scenarios requiring audit trails and decision precedents
Do not use when:
  • Building simple stateless RAG systems for one-time document queries
  • Performing one-off document searches without need for persistence
  • Running temporary experiments that don’t require knowledge retention
  • Simple retrieval tasks where relationships between entities don’t matter
This guide covers the memory layer. For graph-enriched traversal and entity linking, see Context Graphs. For decision accountability — recording, auditing, and causally tracing what the agent chose — see Decision Intelligence.

Setting Up a Persistent Memory Context

Configure the vector store, knowledge graph, and AgentContext together at startup so all three components persist to disk at the same path.
The hybrid_alpha parameter controls how retrieval blends semantic similarity (pure vector search) with graph-structural similarity (topology of the knowledge graph). At 0.5 the agent treats both signals equally. For a freshly ingested corpus with a sparse graph, you might start closer to 0.0 and increase as the graph fills in.

Storing What the Agent Learns

Single observations

Every piece of intelligence the agent processes can be stored with a single call. The string is embedded and indexed immediately; the optional metadata travels with it and is available in every retrieval result.
The conversation_id acts as a namespace. Memories tagged with incident_ir2025_0847 can be retrieved as a group later — useful for building a per-incident context window without polluting the global search index.

Ingesting document corpora

When store() receives a list, it treats each element as a document, builds a graph of entities and relationships extracted from the text, and returns statistics about what was created.
After this call the knowledge graph contains nodes for APT29, HAMMERTOSS, the infrastructure subnet, the SUNBURST campaign, and OAuth token theft — all linked to each other. Those graph links are what enable multi-hop retrieval: ask about “cloud OAuth attacks” and the agent can follow the graph from the technique node back to APT29 and then forward to the infrastructure indicators.

Retrieving Relevant Memory

Semantic retrieval

The most direct retrieval call searches by semantic similarity — no keyword match required. The embedding of your query is compared against all stored memory embeddings, and the top matches are returned with scores.
The agent found the OAuth finding at the top — not because the query contained the exact phrase, but because the embedding space places “cloud OAuth token theft campaigns” close to “NOBELIUM leverages OAuth token theft against cloud workloads.”

Graph-anchored retrieval with proximity scoring

When you have a specific entity as the center of your investigation, anchor the retrieval to that node and blend semantic score with graph-proximity score.
The proximity_weight parameter is a per-call override — you can use heavy proximity weighting when pivoting on a specific actor and drop back to pure semantic search when exploring broadly.

Graph-grounded reasoning

When you need a natural-language answer that synthesizes multiple memory items, use query_with_reasoning() to retrieve context from the graph and ask the LLM to ground its answer in those sources.
The result includes a reasoning_path field that traces exactly which graph edges were traversed to reach the answer — useful for analyst review and audit.

Building a Working Memory Window

Use the conversation_id filter to scope retrieval to the active session and combine incident-scoped history with global semantic search.
This pattern lets the agent build a focused working memory window for each incident while the global vector index accumulates knowledge across all incidents over time.

Domain Examples

A threat-intelligence fusion cell ingests OSINT feeds, MISP events, and internal hunt findings continuously. The agent must correlate new indicators against known actor profiles and produce attribution assessments grounded in accumulated intelligence — not just the latest report.

Persisting and Restoring State

At the end of an analyst shift — or before a process restart — call save() to write the full context to disk. On next startup, call load() to restore it completely.
When a new process starts — or a new analyst logs in — restore from that checkpoint:
AgentMemory itself is saved as JSON, but the vector store persists its own index and vector payload separately. load() restores those backend artifacts rather than re-embedding memories on demand, so keep the same vector-store backend, dimension, and scoring setup across sessions.

Taking Checkpoints During Analysis

For long-running analysis loops, take named snapshots before and after key steps so you can diff what the agent added during each phase.

Memory Lifecycle and Housekeeping

Retention is applied automatically on every store() call — items older than retention_days are pruned without any manual intervention. You can also remove specific memories or clear a full conversation namespace.

Common Pitfalls

Forgetting to persist memory before shutdown. Agent Memory is stored in memory during execution. Without calling save() before process termination, all accumulated memories, graph relationships, and conversations are lost. Using the same conversation namespace for unrelated tasks. Conversation IDs should scope related interactions. Using a single conversation for multiple unrelated investigations pollutes retrieval results and makes context less focused. Storing excessive low-value information. Not every observation needs permanent storage. Focus on storing insights, decisions, and significant findings rather than verbose raw logs or temporary calculations. Using Agent Memory when simple retrieval would be sufficient. For one-time document lookups or stateless queries, traditional retrieval is simpler and more efficient than setting up persistent memory infrastructure. Retrieving too much context and increasing latency. Large max_results, high max_hops, or broad queries can retrieve excessive context, increasing LLM token usage and response latency. Start with focused retrieval parameters.
  • Context Graphs — How the underlying ContextGraph stores entity nodes and decision nodes; temporal interval reasoning; deduplication before node insertion; ontology from graph.
  • Decision Intelligence — Recording decisions as graph nodes with causal chains and policy gating.
  • Multi-Agent Systems — Coordinating multiple agents through a shared AgentContext and save/load handoffs.
  • LLM Integrations — Configuring the LLM provider passed to query_with_reasoning().
  • Deduplication Guide — Full reference for DuplicateDetector, EntityMerger, similarity methods, and cluster strategies.
  • Ontology Management — Generate and validate OWL ontologies from the knowledge graph; export to Turtle, OWL/XML, JSON-LD.
  • Context Module Reference — Full API: AgentContext, AgentMemory, MemoryItem, ContextRetriever.
  • Vector Store Reference — FAISS, Qdrant, pgvector, Pinecone backends.