Skip to main content
These endpoints power Agent Memory’s retrieval layer — use them to search past observations with hybrid BM25 + vector + graph ranking, generate context blocks ready to inject into prompts, enrich file paths with related memories and known bugs, and traverse the knowledge graph. All retrieval results are session-diversified (at most 3 results per session) and ranked with Reciprocal Rank Fusion (RRF, k=60).

POST /agentmemory/smart-search

Runs a hybrid three-stream search across all memories and observations. This is the primary search endpoint — it combines keyword matching (BM25), semantic similarity (vector), and entity-linked knowledge graph traversal, then fuses the ranked results.
You must provide either a query string or an expandIds array. Providing both is allowed — expandIds expands the context around specific observations while query runs the full retrieval pipeline.

Request

string
Natural language search query. Agent Memory tokenizes this for BM25, embeds it for vector similarity, and extracts named entities for graph traversal — all in a single call.
array
Array of observation IDs (strings or { obsId, sessionId } objects) to expand context around. Used internally by the viewer and MCP tools to fetch neighbouring observations.
string
Scope the search to a specific project. Omit to search across all projects.
number
Maximum number of results to return (default 10). Must be a positive integer.
boolean
When true, also searches the lessons store (crystallized learnings from past sessions) and merges them into the results.
string
Override the agent scope for this search. Useful when routing queries on behalf of a specific agent in multi-agent setups. You can also pass ?agentId=<id> as a query parameter.
string
Bias results toward observations from a specific session.

Response

CompactSearchResult[]
Ranked array of matching observations. Each result includes obsId, sessionId, title, type, score (combined RRF score), and timestamp.
For the full observation detail (facts, narrative, files, concepts), call GET /agentmemory/observations?sessionId=<id> and filter by obsId. The compact response keeps payload sizes small for fast recall.

POST /agentmemory/search

A lower-level search endpoint that gives you more control over output format and token budget. Returns observations in one of three formats.
string
required
Search query string. Must be non-empty.
number
Max results to return. Must be a positive integer.
string
Scope to a project.
string
Working directory — biases results toward files under this path.
string
Output format. One of:
  • full — complete observation objects
  • compact — titles and scores only
  • narrative — prose summary of results
number
Maximum tokens for the response. When set, Agent Memory trims results to fit within the budget.

POST /agentmemory/context

Generates a formatted context block ready to inject directly into an agent prompt. Unlike raw search, this endpoint applies token budgeting, deduplication, and formatting so the output is immediately usable.

Request

string
required
The current session ID. Agent Memory uses this to avoid including observations from the current session in the recalled context.
string
required
Project name to recall context for.
number
Maximum token budget for the returned context block (default 2000). Must be a positive integer. Agent Memory ranks and trims memories to fit within this budget.

Response

string
Formatted context block as a markdown string. Inject this into the agent’s first turn or system prompt.
number
Approximate token count of the returned context.

POST /agentmemory/enrich

Enriches one or more file paths with related memories, past edit history, observed bugs, and relevant concepts. Use this to give the agent deep context about a specific file before it reads or edits it.

Request

string
required
Current session ID.
string[]
required
Array of file paths to enrich. Must be non-empty. All paths must be strings.
string[]
Additional search terms to broaden the enrichment query beyond the file path itself.
string
The tool that triggered this enrichment (e.g. "Read", "Edit"). Used for diagnostic tracing.
string
Project name for scoped recall.

Response

The response includes per-file summaries, related memories, past edit history from observations, known issues, and matched concepts.

POST /agentmemory/file-context

Returns a focused context block for specific files within a session. Lighter than /enrich — returns raw observation context for the given files without the full enrichment pass.

POST /agentmemory/graph/query

Traverses the knowledge graph starting from a node, querying by node type, or running a text search across node names. Returns matching nodes and their edges up to the specified depth.
This endpoint requires GRAPH_EXTRACTION_ENABLED=true in your config and a configured LLM provider. Without it, the endpoint returns 503 with instructions on how to enable the feature.

Request

string
ID of the graph node to start traversal from. Returns all nodes reachable within maxDepth hops.
string
Filter results to a specific node type. One of: file, function, concept, error, decision, pattern, library, person, project, preference, location, organization, event.
string
Text query matched against node names.
number
Maximum traversal depth from the start node (default 2).
number
Maximum number of nodes to return.
number
Pagination offset.

Response

GraphNode[]
Matching graph nodes. Each node has an id, type, name, properties, sourceObservationIds (for provenance tracing), and createdAt.
GraphEdge[]
Edges connecting the returned nodes. Edge types include: uses, imports, modifies, causes, fixes, depends_on, related_to, prefers, blocked_by, rejected, avoids, optimizes_for, and more.
boolean
true when the result was capped by limit. Use offset to page through the rest.
boolean
true when the response was served from the precomputed top-degree snapshot rather than a live graph enumeration. Snapshots are rebuilt via POST /agentmemory/graph/snapshot-rebuild.

Graph Management


GET /agentmemory/config/flags

Returns the current runtime feature flags, LLM provider kind, and embedding provider. Use this to check which optional features are active before calling feature-gated endpoints.

Response

string
The running Agent Memory version.
string
Detected LLM provider kind (anthropic, openai, gemini, openrouter, minimax, noop).
string
"embeddings" if an embedding provider is configured, "none" if BM25-only mode is active.
FeatureFlag[]
Array of feature flag objects. Each flag includes key, label, enabled (current state), needsLlm (whether an LLM provider is required), and enableHow (exact instruction to turn it on).

POST /agentmemory/timeline

Returns a chronological slice of observations centred on a given anchor timestamp or observation ID. Useful for replaying what happened around a specific point in time.
string
required
ISO timestamp or observation ID to centre the timeline around.
string
Scope to a project.
number
Number of observations to include before the anchor.
number
Number of observations to include after the anchor.

POST /agentmemory/patterns

Detects recurring patterns across all sessions for a project — common code idioms, repeated workflows, and frequently co-occurring concepts.

GET /agentmemory/diagnostics/followup

Returns a directional signal for the follow-up query rate — the proportion of searches followed by another search within a short window. High follow-up rates may indicate recall quality issues.
The follow-up rate is a directional signal only — it overcounts on legitimate query refinement (when you intentionally narrow a search). Tune the window with AGENTMEMORY_FOLLOWUP_WINDOW_SECONDS.