Agent memory reference v7

Reference for agent memory functions, views, and configuration parameters. For guide-style documentation, see Agent memory.

Catalog views

aidb_memory.namespaces

Lists the available agent memory namespaces.

ColumnDescription
idUnique identifier for the namespace.
nameName of the namespace.
agentmemory_specConfiguration for the agent memory runtime associated with the namespace.
model_specConfiguration for the models used by the namespace.
storage_specConfiguration for the storage backend used by the namespace.
stateLifecycle state of the namespace. Valid values: ACTIVE, INACTIVE.
created_atWhen the namespace was created.
updated_atWhen the namespace was last updated.

aidb_memory.events

Lists the ingestion events created when applications call aidb_memory.add. Query this view to audit submitted conversation turns, trace asynchronous processing, correlate retries through idempotency keys, and check whether each event was accepted, processed, made ready, or failed.

ColumnDescription
event_idUnique internal identifier for the event.
public_idExternal identifier returned to callers and used to reference the event outside the database.
correlation_idIdentifier that correlates the database event with Agent Memory Server logs, background processing, and related downstream operations.
namespace_idThe namespace that owns the event and supplies its model, server, and storage configuration.
actor_idIdentifier of the user, tenant, device, or other subject whose turns were submitted.
agent_idIdentifier of the agent or application component that submitted the event.
session_idIdentifier of the conversation, ticket, workflow, or run associated with the turns.
turn_countNumber of message turns in the payload passed to aidb_memory.add.
ingestion_statusProcessing state of the event. Valid values: ACCEPTED, PROCESSING, READY, SKIPPED, FAILED.
idempotency_keyCaller-provided key that deduplicates retries of the same event.
occurred_atWhen the source conversation event occurred in the application or agent workflow.
recorded_atWhen AIDB recorded the event for asynchronous ingestion.
metadataAdditional JSON metadata captured with the event, such as source system details or tracing information.
created_atWhen the event row was created.
updated_atWhen the event row was last updated, typically as the ingestion status changes.

aidb_memory.messages

Stores the ordered message history generated from memory events, including the actor and session context, role, content, and timestamps.

ColumnDescription
idUnique internal identifier for the message.
event_idThe event that generated this message.
namespace_idThe namespace that owns the event.
actor_idThe actor associated with the message.
session_idThe conversation or session that groups related messages.
ordinalSequence number that preserves message order within the event or session.
roleRole of the message author, such as user or assistant.
contentMessage body captured from the event for replay, retrieval, or audit.
created_atWhen the message row was created.
updated_atWhen the message row was last updated.

aidb_memory.sessions

One row per conversation, created lazily by session_start, session_end, or a compacting session_get. The aidb_users role can't read this view directly.

ColumnDescription
idInternal identifier for the session row.
namespace_idThe namespace that owns the session.
session_idCaller-supplied conversation identifier, unique within a namespace.
actor_idThe actor that opened the session. This is the tenancy key for every session read.
agent_idThe agent taking part. NULL until a session_start call supplies one.
started_atWhen the session was first opened or written to.
closed_atWhen session_end closed it. NULL while the session is open.
high_water_event_idNewest event covered by a summary. NULL before the first compaction.
handoffSet at close: {notes, compacted_entries, stats}. Returned as the next session's prev_handoff.
statsSet at close: {turns, content_chars} over the whole conversation.

aidb_memory.session_compactions

Summaries that stand in for the turns a session has compacted, ordered per session by seq. Written only by a compacting session_get, one row per compaction.

ColumnDescription
idInternal identifier for the summary row.
namespace_idThe namespace that owns the session.
session_pkThe aidb_memory.sessions.id that this summary belongs to.
seqPosition among the session's summaries, oldest first.
covers_through_event_idNewest event this summary covers. Informational.
contentThe generated summary text.
model_refThe model that produced the summary, recorded for audit.
created_atWhen the summary was written.

Functions

aidb_memory.init

Initializes a namespace and prepares it to store and retrieve memories. Run it once before any other aidb_memory function, so that the LLM, embedding configuration, and Agent Memory Server are set up. Call it once during setup or before the first memory operation. If the namespace already exists, the function returns it without changing it.

aidb_memory.init(name TEXT, config JSONB)
ParameterTypeDescription
nameTEXTName of the namespace. The namespace supplies the model, server, and storage configuration for later calls.
configJSONBConfiguration for the namespace: the model spec, the agent memory provider spec, and the storage spec. See Initializing a namespace.

Returns a row that describes the namespace:

ColumnTypeDescription
namespaceTEXTName of the namespace.
statusTEXTState of the namespace.
created_atTIMESTAMPTZWhen the namespace was created.
model_specJSONBConfiguration for the models that the namespace uses.
agentmemory_specJSONBConfiguration for the agent memory runtime.
storage_specJSONBConfiguration for the storage backend.
sessionmemory_specsJSONBConfiguration for session memory.

aidb_memory.add

Persists agent turns as an event so that they can be retrieved later as memory. Typically used to store a user's conversation with an agent.

aidb_memory.add(
  turns JSONB,
  namespace TEXT,
  actor_id TEXT,
  agent_id TEXT DEFAULT NULL,
  session_id TEXT DEFAULT NULL,
  idempotency_key TEXT DEFAULT NULL,
  metadata JSONB DEFAULT '{}'
)
ParameterTypeDefaultDescription
turnsJSONBRequiredThe ordered message turns exchanged during the interaction, from the user and the assistant. Each turn has a role and content.
namespaceTEXTRequiredThe namespace that owns the event.
actor_idTEXTRequiredIdentifier of the actor associated with the turns.
agent_idTEXTNULLIdentifier of the agent that took part in or generated the turns.
session_idTEXTNULLIdentifier of the conversation or session that groups related messages.
idempotency_keyTEXTNULLKey that prevents duplicate processing and keeps retries from creating duplicate records.
metadataJSONB{}Additional metadata to store with the event. Must be a JSON object.

Returns:

TypeDescription
UUIDThe ID of the add operation. Pass it to aidb_memory.status as id to check progress.

aidb_memory.status

Reports the status of a memory event: ACCEPTED, PROCESSING, READY, SKIPPED, or FAILED. Use it to confirm that an event is ready for retrieval, or to diagnose a failed memory formation.

aidb_memory.status(
  namespace TEXT,
  id UUID DEFAULT NULL,
  actor_id TEXT DEFAULT NULL,
  session_id TEXT DEFAULT NULL,
  agent_id TEXT DEFAULT NULL,
  limit INTEGER DEFAULT 100,
  offset INTEGER DEFAULT 0
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace that owns the event.
idUUIDNULLIdentifier of the event to check. If omitted, the query isn't limited to a specific event.
actor_idTEXTNULLIdentifier of the actor.
session_idTEXTNULLFilters results to a session.
agent_idTEXTNULLFilters results to an agent.
limitINTEGER100Maximum number of results to return.
offsetINTEGER0Number of results to skip before returning. Use with limit for large result sets.

Returns a row for each matching event:

ColumnTypeDescription
idUUIDThe ID of the event.
namespaceTEXTThe namespace that owns the event.
statusTEXTState of the event: ACCEPTED, PROCESSING, READY, SKIPPED, or FAILED.
actor_idTEXTThe actor associated with the event.
session_idTEXTThe session associated with the event.
agent_idTEXTThe agent associated with the event.
error_detailTEXTDetails about the error if the event failed. NULL otherwise.

aidb_memory.search

Searches the stored memories and returns the entries that match a natural-language query. Use it to retrieve information that was saved with aidb_memory.add.

aidb_memory.search(
  namespace TEXT,
  actor_id TEXT,
  query TEXT,
  limit INTEGER DEFAULT 10,
  session_id TEXT DEFAULT NULL,
  agent_id TEXT DEFAULT NULL
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace to search.
actor_idTEXTRequiredIdentifier of the actor whose memories to search.
queryTEXTRequiredA natural-language query that describes the information the agent needs.
limitINTEGER10Maximum number of memories to return.
session_idTEXTNULLRestricts results to memories from a session.
agent_idTEXTNULLRestricts results to memories created or used by an agent.

Returns a row for each matching memory:

ColumnTypeDescription
idUUIDThe ID of the memory.
contentTEXTThe text of the memory.
scoreREALRelevance score for the match.
metadataJSONBMetadata stored with the memory.

aidb_memory.list_memories

Lists the memories stored in agent memory. Use it to inspect saved context, audit memories, debug memory behavior, or verify that expected records exist.

aidb_memory.list_memories(
  namespace TEXT,
  actor_id TEXT,
  session_id TEXT DEFAULT NULL,
  agent_id TEXT DEFAULT NULL,
  limit INTEGER DEFAULT 100
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace to list.
actor_idTEXTRequiredIdentifier of the actor whose memories to list.
session_idTEXTNULLFilters results by session.
agent_idTEXTNULLFilters results by agent.
limitINTEGER100Maximum number of memories to return.

Returns a row for each memory:

ColumnTypeDescription
idUUIDThe ID of the memory.
contentTEXTThe text of the memory.
agent_idTEXTThe agent that the memory is associated with.
session_idTEXTThe session that the memory is associated with.

aidb_memory.delete

Removes memories when they must be deleted for compliance, privacy, or retention reasons. Deleted memories no longer appear in searches or listings.

aidb_memory.delete(
  namespace TEXT,
  actor_id TEXT,
  selector JSONB,
  reason TEXT,
  session_id TEXT DEFAULT NULL,
  agent_id TEXT DEFAULT NULL
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace that owns the memories.
actor_idTEXTRequiredIdentifier of the actor whose memories are deleted or evaluated by the selector.
selectorJSONBRequiredWhich memories to remove. Set scope to session, agent, or actor to delete at that level, for example {"scope": "session"}. Alternatively, list specific memories, for example {"memory_ids": ["<memory-uuid>"]}.
reasonTEXTRequiredWhy the memories are deleted. Recorded for auditing and operational tracking.
session_idTEXTNULLLimits the deletion to memories from a session.
agent_idTEXTNULLLimits the deletion to memories from an agent.

Returns:

TypeDescription
BIGINTThe number of memories deleted.

aidb_memory.session_start

Opens a conversation, or resumes one, and returns the handoff left by the previous conversation in the same scope. Makes no model call and is idempotent.

aidb_memory.session_start(
  namespace TEXT,
  actor_id TEXT,
  agent_id TEXT,
  session_id TEXT DEFAULT NULL
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace that owns the session.
actor_idTEXTRequiredThe user, tenant, or other subject the conversation belongs to.
agent_idTEXTRequiredThe agent taking part. Required positionally, but can be NULL.
session_idTEXTNULLConversation identifier. NULL creates a UUID and returns it.

Returns:

ColumnTypeDescription
session_idTEXTThe conversation identifier.
prev_handoffJSONBThe last closed session's handoff in the same (namespace, actor_id, agent_id) scope, or NULL.
started_atTIMESTAMPTZWhen the session was first opened.
closed_atTIMESTAMPTZNULL while the session is open. Non-NULL if this call re-opened an already closed session, which reports its close time.

aidb_memory.session_get

Returns a conversation's history in order, within an optional character budget. When the budget is exceeded, it summarizes the oldest part of the history. It isn't exposed as an agent tool, because an agent must not choose its own history.

aidb_memory.session_get(
  namespace TEXT,
  actor_id TEXT,
  session_id TEXT,
  limit_chars BIGINT DEFAULT NULL,
  fallback_model TEXT DEFAULT NULL
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace that owns the session.
actor_idTEXTRequiredThe actor whose session is read.
session_idTEXTRequiredThe conversation to read.
limit_charsBIGINTNULLCharacter budget over turn content. NULL returns everything and never compacts. Must be NULL or non-negative.
fallback_modelTEXTNULLA registered model to summarize with when the namespace names no LLM.

Returns:

ColumnTypeDescription
itemsJSONBA JSONB array of turns in order, summaries first. Each has event_id, ordinal, role, name, content, kind, tool_call_id, meta, and occurred_at. Summaries appear with role set to system, name set to compaction_summary, and kind set to summary.
overflow_charsBIGINTCharacters of raw history left out to fit the budget.
compacted_entriesINTEGERNumber of summaries included.
warningsTEXT[]Codes for anything the caller should notice. Empty on a clean read. See Keeping long conversations within budget.

aidb_memory.session_end

Closes a conversation and stores a handoff that describes it. Makes no model call and is idempotent: a repeated close returns the stored handoff without overwriting it.

aidb_memory.session_end(
  namespace TEXT,
  actor_id TEXT,
  session_id TEXT,
  notes TEXT DEFAULT NULL
)
ParameterTypeDefaultDescription
namespaceTEXTRequiredThe namespace that owns the session.
actor_idTEXTRequiredThe actor whose session is closed.
session_idTEXTRequiredThe conversation to close.
notesTEXTNULLFree text carried into the handoff for the next conversation.

Returns:

ColumnTypeDescription
session_idTEXTThe conversation identifier.
ended_atTIMESTAMPTZWhen the session was closed.
handoffJSONBThe stored handoff, as {notes, compacted_entries, stats}, where stats is {turns, content_chars} over the whole conversation.

Configuration parameters

Agent memory exposes Postgres configuration parameters in the aidb.agent_memory_* namespace. For examples, see Configuring advanced settings.

Changes to these parameters don't require a Postgres restart. If you change them in postgresql.conf, reload the configuration for the change to take effect.

Users can set both parameters for their own sessions. You set the Agent Memory Server address in the namespace, using agentmemory_spec.config.base_url, not in a parameter.

ParameterDefaultDescription
aidb.agent_memory_enable_workeroffWhether the agent memory worker runs for this database. Set it to on to enable the worker, or off to disable it. Use lowercase, because values are case-sensitive.
aidb.agent_memory_worker_batch_size2The number of agent memory records the worker processes in each batch. The maximum is 50.