Agent Memory
This page presents the concrete Oracle AI Agent Memory implementation.
Oracle Agent Memory
Note: OracleAgentMemory.delete_thread() is the
supported path for thread-scoped cascading cleanup. It removes the thread
together with associated messages, durable memories, and managed retrieval
data. This is broader than OracleThread.delete_message(), which deletes
only the raw message row. Before deleting the thread, it waits for earlier
accepted background extraction already known to this client for that thread.
It does not serialize every concurrent operation for the same thread while
deletion is in progress.
class oracleagentmemory.core.OracleAgentMemory
Bases: IAgentMemory
Agent-memory client backed by Oracle DB or a caller-provided store.
Create a memory client.
- Parameters:
- store
OracleMemoryStore– Optional preconfigured store instance. When provided, the client uses this store directly instead of instantiating its own store. This is useful when callers need store configuration beyond the constructor options exposed byOracleAgentMemory. - connection
object– Optional Oracle DB connection/pool. When provided, the DB store is used. Passing a raw connection enables single-session mode for this client instance, so concurrent requests should use a connection pool instead. When omitted, callers must pass an explicitstore. - embedder
IEmbedder | str– Embedder implementation instance, or a LiteLLM embedding model identifier. When omitted, no embedder is attached. Vector-only DB search then requires precomputed vectors through lower-level store APIs, while keyword DB search can run directly from query text. Hybrid DB search requires anOracleDBEmbedderinstance so the managed hybrid index and the main embedder use the same in-database model. - llm
ILlm– Optional LLM adapter used by threads for memory extraction and/or context summarization. By default, threads created or loaded from this client require an LLM so recent messages can be mined for durable memories. Pass anllmhere, provide one later increate_thread, or disable automatic extraction withmemory_extraction_config=MemoryExtractionConfig(extract_memories=False). - memory_extraction_config
MemoryExtractionConfig– Optional client-level memory extraction configuration. Use it to control automatic memory extraction settings such as extraction mode, summary behavior, and extraction limits. Omitted fields use SDK defaults. - schema_policy
SchemaPolicy | str– DB schema setup policy used only when constructing a DB store fromconnection. Defaults toSchemaPolicy.REQUIRE_EXISTING. UseSchemaPolicy.CREATE_IF_NECESSARYwhen first enabling keyword or hybrid search on an existing schema, or when opening a supported older released managed schema, so the SDK can apply non-destructive schema upgrades and add the needed text-search objects. Development or partially updated schemas that already claim the current release shape should be recreated instead. - memory_store_id
str– Stable ID for the managed DB memory store used only when constructing a DB store fromconnection. Reuse the same ID to reopen the same managed store. The ID is joined to managed DB object names with an underscore, so it must start with a letter, contain only letters, numbers, and underscores, and be at most 16 characters. Pass either this ortable_name_prefix, not both. If omitted, the DB store usestable_name_prefixor the unprefixed default whentable_name_prefixis also omitted. -
table_name_prefix
str–Optional DB table/index prefix used only when constructing a DB store from
connection. Pass either this ormemory_store_id, not both.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_store_idinstead. - search_strategy
SearchStrategy–SearchStrategyvalue that selects the DB-search backend when constructing a DB store fromconnection. UseSearchStrategy.VECTOR(default) for vector-only retrieval,SearchStrategy.HYBRIDto query the managed Oracle hybrid vector index over the stored search text, orSearchStrategy.KEYWORDto rank by keyword/text matching over the stored search text without vector fusion.KEYWORDdoes not require an embedder.HYBRIDrequiresembedderto be anOracleDBEmbedder. Client startup fails when an incompatible strategy is used with an existing schema because that schema may not contain the stored search state the strategy needs. - search_index_sync
SearchIndexSyncMode–SearchIndexSyncModevalue that selects the managed search-index refresh behavior forSearchStrategy.HYBRIDandSearchStrategy.KEYWORD.SearchIndexSyncMode.ON_COMMITis the default and makes records searchable as soon as the write transaction commits.SearchIndexSyncMode.MANUALleaves refresh to an explicit database-side sync operation.SearchIndexSyncMode.AUTOlets Oracle refresh the managed hybrid index asynchronously and is supported only withSearchStrategy.HYBRID; keyword search rejectsAUTO. -
extract_memories
bool–When
True, threads created or loaded by this client require an LLM and automatic memory extraction remains enabled. Set toFalseto disable automatic memory extraction and allow those threads to operate without an LLM. Defaults toTrueso missing extraction LLMs fail fast.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_custom_instructions
str–Optional custom instructions appended to the automatic memory extraction system prompt for threads created or loaded by this client. Per-thread values passed to
create_thread,get_thread, orupdate_threadtake precedence.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. - memory_retention_config
MemoryRetentionConfig– Optional memory retention configuration used only when constructing a DB store fromconnection.MemoryRetentionConfig.default_ttl_daysis applied to new messages and memories whose write call omitsttl_days.MemoryRetentionConfig.max_ttl_daysclamps explicit per-record durations above the configured maximum with a warning and, when set, makesttl_days=Noneuse that maximum instead of creating non-expiring records. WithSchemaPolicy.CREATE_IF_NECESSARY, an explicit configuration refreshes the stored metadata on an existing up-to-date managed schema, but it does not update the existing expiration dates; omitting it keeps the existing setting. If an explicit configuration leavesdefault_ttl_daysormax_ttl_daysatNOT_SET_MARKER, the SDK resolves that attribute to its default value (None) before comparing or storing schema metadata. Choose this configuration based on the expected information stored in records, why the application retains it, and any application or regulatory retention commitments.
- store
Warning: SchemaPolicy.CREATE_IF_NECESSARY can be more expensive than normal
client startup because it may apply managed schema DDL and best-effort
data rewrites before initialization succeeds. Plan the first open of
an older managed schema as a migration or maintenance operation when
that schema may contain many rows.
If schema setup must create the managed expired-record purge job but
the database user lacks the scheduler-job privilege, initialization
warns and continues. Expired messages and memories stay hidden from
reads and search, but they are not physically purged until the job is
created by a user with CREATE JOB or an equivalent scheduler
privilege.
When SchemaPolicy.CREATE_IF_NECESSARY first creates a managed
hybrid index over an existing schema, Oracle scans the stored search
text and builds the managed hybrid-index state from the configured
in-database model. Client startup waits for that DDL to finish, so plan
the first hybrid upgrade as a migration or maintenance operation for
large schemas. SearchIndexSyncMode controls ongoing maintenance
after the index exists; it does not make the first index build
asynchronous.
- Raises:
ValueError – If conflicting store configuration is provided, such as passing
both
storeandconnection, DB-specific options without a DB connection, or omitting bothstoreandconnection. - Parameters:
- store
OracleMemoryStore - connection
object - embedder
IEmbedder | str - llm
ILlm - memory_extraction_config
MemoryExtractionConfig - schema_policy
SchemaPolicy | str - memory_store_id
str - table_name_prefix
str - search_strategy
SearchStrategy - search_index_sync
SearchIndexSyncMode - extract_memories
bool - memory_extraction_custom_instructions
str - memory_retention_config
MemoryRetentionConfig
- store
Examples
from oracleagentmemory.core import (
MemoryExtractionConfig,
SearchIndexSyncMode,
OracleAgentMemory,
SchemaPolicy,
SearchStrategy,
)
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
read_only_client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
memory_extraction_config=MemoryExtractionConfig(extract_memories=False),
)
Use an in-DB embedding model to exploit Oracle hybrid index search:
from oracleagentmemory.core.embedders import OracleDBEmbedder
db_embedder = OracleDBEmbedder(
connection=db_pool,
model="DOC_MODEL",
embedding_dimension=768,
)
hybrid_client = OracleAgentMemory(
connection=db_pool,
embedder=db_embedder,
schema_policy=SchemaPolicy.CREATE_IF_NECESSARY,
search_strategy=SearchStrategy.HYBRID,
search_index_sync=SearchIndexSyncMode.ON_COMMIT,
)
method add_agent
Add an agent profile record to the store.
- Parameters:
- agent_id
str– Agent identifier. - information
str– Free-form information about the agent. - metadata
dict[str, Any] | None– Optional metadata mapping stored on the agent profile row.
- agent_id
- Returns: Identifier of the stored agent profile.
- Return type: str
Notes
Agent profile records are stored in the client-level store and are
intentionally unscoped. The returned record identifier is the same
public identifier the application uses as agent_id.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
client.add_agent(
"a1",
"Support assistant",
metadata={"source": "catalog"},
)
'a1'
method add_memory
Add a memory in the memory system, attributed to the indicated user, agent and thread.
- Parameters:
- content
str– Memory content to persist. - memory_type
Literal['memory', 'guideline', 'fact', 'preference'] | ~oracleagentmemory._notset._NotSetMarker– Memory category to store. Supported values are"memory","fact","guideline", and"preference". When omitted, the content is stored as a general"memory". - user_id
str– Optional scope identifiers associated with the stored memory. - agent_id
str– Optional scope identifiers associated with the stored memory. - thread_id
str– Optional scope identifiers associated with the stored memory. - memory_id
str– Optional caller-provided stable identifier for this memory row. - metadata
dict[str, Any] | None– Optional metadata to persist with the stored memory. - timestamp
str | None– Optional timestamp to save for this memory. It represents when the memory was created. When omitted orNone, the store uses the current time. Whenttl_anchorisTimeToLiveAnchor.TIMESTAMP, ISO-8601 timestamps without a timezone are treated as UTC. - ttl_days
int | None– Optional time-to-live duration in days. Omit this argument to use the schema default time-to-live duration. PassNoneto useMemoryRetentionConfig.max_ttl_dayswhen the retention configuration sets one, or to store a non-expiring memory when it does not. Values aboveMemoryRetentionConfig.max_ttl_daysare clamped to that maximum with a warning. - ttl_anchor
TimeToLiveAnchor– Optional time-to-live anchor. UseTimeToLiveAnchor.CREATED_ATfor the database creation time orTimeToLiveAnchor.TIMESTAMPfor the memory timestamp. ISO-8601 timestamps without a timezone are treated as UTC. - **store_kwargs (Any) – Store-specific write options forwarded to the backing store.
- content
- Returns: Identifier of the inserted memory record.
- Return type: str
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
memory_id = client.add_memory("User likes pizza", memory_id="mem-1")
memory_id
'mem-1'
method add_memory_async (async)
Asynchronously add a memory record to the client.
- Parameters:
- content
str– Text content to store as a memory. - memory_type
Literal['memory', 'guideline', 'fact', 'preference'] | ~oracleagentmemory._notset._NotSetMarker– Memory category to store. Supported values are"memory","fact","guideline", and"preference". When omitted, the content is stored as a general"memory". - user_id
str– Optional user identifier to associate with the memory. - agent_id
str– Optional agent identifier to associate with the memory. - thread_id
str– Optional thread identifier to associate with the memory. - memory_id
str– Optional caller-provided stable identifier. When omitted, stores generate one. - metadata
dict[str, Any] | None– Optional metadata to persist with the memory row. - timestamp
str | None– Optional timestamp to save for this memory. It represents when the memory was created. When omitted orNone, the store uses the current time. - ttl_days
int | None– Optional time-to-live duration in days. Omit this argument to use the schema default time-to-live duration. PassNoneto store a memory that does not expire. - ttl_anchor
TimeToLiveAnchor– Optional time-to-live anchor. UseTimeToLiveAnchor.CREATED_ATfor the database creation time orTimeToLiveAnchor.TIMESTAMPfor the memory timestamp. - **store_kwargs (Any) – Implementation-specific write options forwarded to the backing store.
- content
- Returns: Identifier of the inserted memory record.
- Return type: str
method add_user
Add a user profile record to the store.
- Parameters:
- user_id
str– User identifier. - information
str– Free-form information about the user. - metadata
dict[str, Any] | None– Optional metadata mapping stored on the user profile row.
- user_id
- Returns: Identifier of the stored user profile.
- Return type: str
Notes
User profile records are stored in the client-level store and are
intentionally unscoped. The returned record identifier is the same
public identifier the application uses as user_id.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
client.add_user(
"u1",
"Prefers concise answers.",
metadata={"source": "crm"},
)
'u1'
method close
Close the agent memory component.
Closing stops accepting new background extraction work and waits for
pending background memory extraction to finish up to the configured
timeout. If that timeout expires, close() returns even if some
background extraction work is still unfinished. The method is idempotent.
- Parameters:
timeout
float | None– Optional maximum number of seconds to wait for accepted background extraction work to finish. Defaults to300. PassNoneto wait indefinitely. - Return type: None
Examples
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
schema_policy=SchemaPolicy.CREATE_IF_NECESSARY,
memory_extraction_config=MemoryExtractionConfig(extract_memories=False),
)
client.close()
method close_async (async)
Asynchronously close the agent memory component.
This method follows the same shutdown behavior as close(). If the
timeout expires, it can return while background extraction work is
still running.
- Parameters:
timeout
float | None– Optional maximum number of seconds to wait for accepted background extraction work to finish. Defaults to300. PassNoneto wait indefinitely. - Return type: None
Examples
await client.close_async()
method create_thread
Create and register a thread.
- Parameters:
- thread_id
str– Thread identifier. If omitted, a new one is generated. - user_id
str– User identifier attached to this thread record. If omitted, a new one is generated. - agent_id
str– Agent identifier attached to this thread record. If omitted, a new one is generated. - metadata
dict[str, Any] | None– Optional JSON-like metadata persisted with the conversation thread. - llm
ILlm– Optional LLM override for this thread. If omitted, the client-level LLM configured at construction time is used. By default, either the client or the thread must provide an LLM so automatic memory extraction can run. Setmemory_extraction_config=MemoryExtractionConfig(extract_memories=False)here or on the client to opt out of that requirement. - max_message_token_length
int– Maximum prompt-time message size before truncation or summarization during memory extraction and context-summary updates. Stored message content remains unchanged. When omitted, defaults to15_000tokens. - message_shortening_input_token_limit
int– Maximum size, in tokens, of the message excerpt sent to the LLM when shortening oversized prompt-time message copies. When omitted, defaults to30_000tokens. - memory_extraction_config
MemoryExtractionConfig– Optional per-thread memory extraction configuration. Omitted fields inherit from the agent memory component. The resolved config is stored with the thread so later loads preserve the create-time behavior. - context_card_token_limit
int– Maximum input token budget for the LLM prompt used to build the summary and topic list included in the context card. When omitted, defaults to100_000. - context_card_type_search_concurrency
int– Maximum number of memory-like record searches to run concurrently when building a context card withmin_relevant_results_by_type. When omitted, defaults to5. -
extract_memories
bool–Optional per-thread override for automatic memory extraction. When
True, this thread requires an LLM so automatic extraction can run. Set toFalseto disable automatic extraction for this thread and allow operation without an LLM. When omitted, the client-levelextract_memoriessetting is used.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_window
int–Number of recent messages to include during memory extraction. Set to
-1to perform one extraction peradd_messagescall using the full batch of newly added messages. When omitted, defaults to-1.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
context_summary_update_frequency
int–Frequency of context-summary refreshes. Set to
-1to perform one summary update peradd_messagescall using the full batch of newly added messages. When omitted, defaults to-1.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_frequency
int–Frequency of memory extraction updates. Set to
-1to perform one extraction peradd_messagescall using the full batch of newly added messages. When omitted, defaults to-1.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_token_limit
int–Maximum size, in tokens, of the LLM prompts used for memory extraction and running summary updates. When omitted, defaults to
100_000.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_custom_instructions
str–Optional custom instructions appended to the memory extraction system prompt for this thread. When provided, the resolved value is persisted with the thread runtime configuration.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_inherit_message_metadata
bool | Sequence[str]–Optional per-thread override for metadata copied from source messages onto automatically extracted memories.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
enable_context_summary
bool–Whether to keep a running context summary for this thread.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. - **kwargs (Any) – Additional implementation-specific thread options.
- thread_id
- Returns:
An
OracleThreadinstance. - Return type: OracleThread
- Raises:
ValueError – If no LLM is available for automatic memory extraction and the
thread and client were not configured with
memory_extraction_config=MemoryExtractionConfig(extract_memories=False).
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
thread = client.create_thread(thread_id="c1", user_id="u1")
thread.thread_id
'c1'
method delete_agent
Delete an agent profile record by identifier.
- Parameters:
- agent_id
str– Agent identifier whose profile should be removed. - cascade
bool– WhenTrue(default), also delete records scoped to this agent. This includes deleting owned threads themselves, the messages and memory-like records removed with those threads, and any remaining directly agent-scoped records such as messages, memories, guidelines, facts, or preferences. This scoped cleanup still runs when the matching agent-profile row is already absent. Set toFalseto remove only the profile record.
- agent_id
- Returns:
Number of deleted agent-profile rows (
0or1). This may still be0when scoped rows were removed during cascade cleanup. - Return type: int
- Raises: TimeoutError – Raised when earlier accepted background extraction for already- known owned threads does not finish before the internal delete wait times out.
Notes
Cascading deletes are planned and executed inside the backing store so the profile delete and all scoped child deletes happen in one store operation. Before the cascade delete runs, this method waits for earlier background extraction already accepted for the owned threads known at that time through this agent memory component. It does not wait for work accepted after that wait begins or for work started by another agent memory component or process. Concurrent actor-scoped use while deletion is in progress is unsupported.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
client.add_agent("a-delete", "Support assistant")
'a-delete'
client.delete_agent("a-delete")
1
method delete_memory
Delete a memory-like record (e.g., a memory, fact, preference, or guideline) by identifier.
- Parameters:
memory_id
str– Memory identifier. The identifier may refer to a storedmemory,guideline,fact, orpreferencerecord. - Returns:
Number of deleted memory-like rows (
0or1). - Return type: int
Examples
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
memory_id = client.add_memory("Temporary memory", memory_id="mem-delete")
client.delete_memory(memory_id)
1
method delete_memory_async (async)
Asynchronously delete a memory-like record (e.g., a memory, fact, preference, or guideline) by identifier.
- Parameters:
memory_id
str– Identifier of the memory-like record to remove. - Returns: Number of deleted memory-like records.
- Return type: int
method delete_thread
Delete all records associated with a thread identifier.
- Parameters:
thread_id
str– Thread identifier to delete. - Returns:
Number of deleted conversation threads (
0or1). - Return type: int
- Raises: TimeoutError – Raised when earlier accepted background extraction for this thread does not finish before the internal delete wait times out.
Notes
Use this operation when you need retention-complete removal of a
thread. The backing store deletes the thread together with associated
thread-scoped messages, durable memories, and managed retrieval data.
This differs from OracleThread.delete_message(), which removes only
the raw message record and does not cascade to derived memories created
from that message. Before deleting the thread, this method waits for
earlier background extraction already accepted for that thread through
this agent memory component. It does not wait for background work
accepted after that wait begins or for work started by another agent
memory component or process. Concurrent use of the same thread while
deletion is in progress is unsupported.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
thread = client.create_thread(thread_id="c-delete")
client.delete_thread(thread.thread_id)
1
method delete_user
Delete a user profile record by identifier.
- Parameters:
- user_id
str– User identifier whose profile should be removed. - cascade
bool– WhenTrue(default), also delete records scoped to this user. This includes deleting owned threads themselves, the messages and memory-like records removed with those threads, and any remaining directly user-scoped records such as messages, memories, guidelines, facts, or preferences. This scoped cleanup still runs when the matching user-profile row is already absent. Set toFalseto remove only the profile record.
- user_id
- Returns:
Number of deleted user-profile rows (
0or1). This may still be0when scoped rows were removed during cascade cleanup. - Return type: int
- Raises: TimeoutError – Raised when earlier accepted background extraction for already- known owned threads does not finish before the internal delete wait times out.
Notes
Cascading deletes are planned and executed inside the backing store so the profile delete and all scoped child deletes happen in one store operation. Before the cascade delete runs, this method waits for earlier background extraction already accepted for the owned threads known at that time through this agent memory component. It does not wait for work accepted after that wait begins or for work started by another agent memory component or process. Concurrent actor-scoped use while deletion is in progress is unsupported.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
client.add_user("u-delete", "Prefers concise answers.")
'u-delete'
client.delete_user("u-delete")
1
method get_thread
Retrieve a previously created thread.
- Parameters:
- thread_id
str– Identifier used when creating the thread. - llm
ILlm– Optional LLM override for the reopened thread. When omitted, the client-level LLM configured at construction time is used. - max_message_token_length
int– Optional override for the maximum prompt-time message size before truncation or summarization during memory extraction and context-summary updates. Stored message content remains unchanged. - message_shortening_input_token_limit
int– Optional override for the maximum size, in tokens, of the message excerpt sent to the LLM when shortening oversized prompt-time message copies. - memory_extraction_config
MemoryExtractionConfig– Optional grouped extraction config for the returnedOracleThreadinstance. Omitted fields inherit from the stored thread config and agent memory component. The override applies only to the returnedOracleThreadinstance and is not written back to the stored conversation thread config. - context_card_token_limit
int– Optional override for the returnedOracleThreadinstance. It sets the input token budget of the LLM prompt used to build the summary and topic list included in the context card. - context_card_type_search_concurrency
int– Optional override for the returnedOracleThreadinstance. It sets the number of memory-like record searches to run concurrently when building a context card withmin_relevant_results_by_type. -
extract_memories
bool–Optional override for automatic memory extraction on the reopened thread. When omitted, the client-level
extract_memoriessetting is used.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_window
int–Optional override for the number of recent messages used during memory extraction.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
context_summary_update_frequency
int–Optional override for the frequency of context-summary refreshes.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_frequency
int–Optional override for the frequency of memory extraction updates.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_token_limit
int–Optional override for the maximum size, in tokens, of the LLM prompts used for memory extraction and running summary updates.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_custom_instructions
str | None–Optional override for custom memory extraction instructions. Passing
Noneclears thread-level custom instructions for the returnedOracleThreadinstance without updating the stored conversation thread config; a client-level default still applies when configured.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_inherit_message_metadata
bool | Sequence[str]–Optional override for metadata copied from source messages onto automatically extracted memories. The override applies only to the returned
OracleThreadinstance.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
enable_context_summary
bool–Optional override for whether the reopened thread should keep a running context summary.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead.
- thread_id
- Returns:
An
OracleThreadinstance reconstructed from store metadata. - Return type: OracleThread
- Raises:
- KeyError – If the thread id is unknown to this client instance.
- ValueError – If no LLM is available for automatic memory extraction and the
client was not configured with
memory_extraction_config=MemoryExtractionConfig(extract_memories=False).
Notes
Explicit per-call overrides take precedence. When runtime overrides are omitted, reopened threads use persisted runtime config when available before falling back to SDK defaults.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
created = client.create_thread(thread_id="c1", user_id="u1")
loaded = client.get_thread("c1")
loaded.user_id
'u1'
method search
Search synchronously for records relevant to a query.
- Parameters:
- query
str– Natural-language query string. - user_id
str | None– User identifier filter. OracleAgentMemory client searches require an explicit user scope unlessscopeis provided with one. Pass a concreteuser_idto target that user, or passNoneto target only unscoped user records. - agent_id
str | None– Optional agent identifier filter. Ignored whenscopeis provided. - thread_id
str | None– Optional thread identifier filter. Ignored whenscopeis provided. - exact_user_match
bool– Whether user matching should be strict. OracleAgentMemory client searches require exact user matching and rejectFalse. Ignored whenscopeis provided. - exact_agent_match
bool– Whether agent matching should be strict. Ignored whenscopeis provided. - exact_thread_match
bool– Whether thread matching should be strict. Ignored whenscopeis provided. - max_results
int– Optional maximum number of results to return. When provided, it must be at least1. Omitting this argument uses the default value of10. This is an upper bound: the call may return fewer thanmax_resultsresults when filters are too restrictive, when fewer non-expired matching records exist, or because of implementation-specific search behavior. - record_types
list[str]– Optional list of record types to include, such as"memory"or"message". -
metadata_filter
dict[str, Any] | None–Optional metadata filter mapping used as an additional filter after scope and record-type filtering. Entries in
metadata_filterare combined with AND semantics. Entries whose value is not a field-level operator dictionary use exact-match semantics: the requested key must exist in the stored record metadata. Nested dictionaries match nested metadata objects recursively. Scalar and list values must match exactly; list order and length must also match. Omit this argument, or passNone, to search without metadata filtering. Examples includemetadata_filter={"source": "profile_import"}for a scalar field,metadata_filter={"prefs": {"category": "travel"}}for a nested field, andmetadata_filter={"tags": ["survey", "travel"]}for an exact list match. Combine conditions to require all of them:metadata_filter={ "source": "profile_import", "prefs": {"category": "travel"}, "tags": ["survey", "travel"], }To test array membership, use a field-level operator dictionary.
"$array_contains"matches one value, or all values in a list."$array_contains_any"matches at least one value from a list."$not"negates another field-level expression at the same field, including an operator dictionary or raw exact-match value. Negated expressions match when the positive expression would fail, including missing fields; negated array membership also matches non-array fields:metadata_filter={ "source": "profile_import", "tags": { "$array_contains": "travel", "$not": {"$array_contains": "archived"}, }, } - scope
SearchScope– Optional prebuilt search scope. Provide eitherscopeor the explicit identifier and exact-match arguments, not both. OracleAgentMemory client searches require the resolved scope to include an explicituser_idwithexact_user_match=True. Useuser_id=Noneto target only unscoped user records.
- query
- Returns:
Search results ordered by decreasing relevance. The list may
contain fewer than
max_resultsentries. - Return type: list[SearchResult]
- Raises:
ValueError – If
scopeis combined with explicit identifier or exact-match arguments, ifmax_resultsis less than1, ifmetadata_filteris neither a dictionary norNone, or if the implementation rejects the resolved client search scope. OracleAgentMemory client searches reject omitted user scope and rejectexact_user_match=False.
Notes
Explicit None scope values still follow the resolved exact-match
rules: exact_*_match=False leaves that dimension unconstrained,
while exact_*_match=True matches only records unscoped on that
dimension.
method search_async (async)
Search asynchronously for records relevant to a query.
- Parameters:
- query
str– Natural-language query string. - user_id
str | None– User identifier filter. OracleAgentMemory client searches require an explicit user scope unlessscopeis provided with one. Pass a concreteuser_idto target that user, or passNoneto target only unscoped user records. - agent_id
str | None– Optional agent identifier filter. Ignored whenscopeis provided. - thread_id
str | None– Optional thread identifier filter. Ignored whenscopeis provided. - exact_user_match
bool– Whether user matching should be strict. OracleAgentMemory client searches require exact user matching and rejectFalse. Ignored whenscopeis provided. - exact_agent_match
bool– Whether agent matching should be strict. Ignored whenscopeis provided. - exact_thread_match
bool– Whether thread matching should be strict. Ignored whenscopeis provided. - max_results
int– Optional maximum number of results to return. When provided, it must be at least1. Omitting this argument uses the default value of10. - record_types
list[str]– Optional list of record types to include, such as"memory"or"message". -
metadata_filter
dict[str, Any] | None–Optional metadata filter mapping used as an additional filter after scope and record-type filtering. Entries in
metadata_filterare combined with AND semantics. Entries whose value is not a field-level operator dictionary use exact-match semantics: the requested key must exist in the stored record metadata. Nested dictionaries match nested metadata objects recursively. Scalar and list values must match exactly; list order and length must also match. Omit this argument, or passNone, to search without metadata filtering. Examples includemetadata_filter={"source": "profile_import"}for a scalar field,metadata_filter={"prefs": {"category": "travel"}}for a nested field, andmetadata_filter={"tags": ["survey", "travel"]}for an exact list match. Combine conditions to require all of them:metadata_filter={ "source": "profile_import", "prefs": {"category": "travel"}, "tags": ["survey", "travel"], }To test array membership, use a field-level operator dictionary.
"$array_contains"matches one value, or all values in a list."$array_contains_any"matches at least one value from a list."$not"negates another field-level expression at the same field, including an operator dictionary or raw exact-match value. Negated expressions match when the positive expression would fail, including missing fields; negated array membership also matches non-array fields:metadata_filter={ "source": "profile_import", "tags": { "$array_contains": "travel", "$not": {"$array_contains": "archived"}, }, } - scope
SearchScope– Optional prebuilt search scope. Provide eitherscopeor the explicit identifier and exact-match arguments, not both. OracleAgentMemory client searches require the resolved scope to include an explicituser_idwithexact_user_match=True. Useuser_id=Noneto target only unscoped user records.
- query
- Returns: Search results ordered by decreasing relevance.
- Return type: list[SearchResult]
- Raises:
ValueError – If
scopeis combined with explicit identifier or exact-match arguments, ifmax_resultsis less than1, ifmetadata_filteris neither a dictionary norNone, or if the implementation rejects the resolved client search scope. OracleAgentMemory client searches reject omitted user scope and rejectexact_user_match=False.
Notes
Explicit None scope values still follow the resolved exact-match
rules: exact_*_match=False leaves that dimension unconstrained,
while exact_*_match=True matches only records unscoped on that
dimension.
method update_memory
Update a stored memory-like record by identifier.
- Parameters:
- memory_id
str– Identifier of the memory-like record to update. - content
str– Optional replacement content. Provide a string to replace the stored content. When omitted, the stored content is preserved. PassingNoneis not supported; omitcontentto keep the current value, or usedelete_memory()to remove the record. - metadata
dict[str, Any] | None– Optional replacement metadata mapping. When omitted, the stored metadata is preserved. When provided, it replaces the stored metadata object; this API does not deep-merge metadata. - timestamp
str | None– Optional new timestamp for this memory. It represents when the memory was created. When omitted, the stored timestamp is preserved. PassNoneto clear the saved timestamp and use the time the record was created in the store. Whenttl_anchorisTimeToLiveAnchor.TIMESTAMP, ISO-8601 timestamps without a timezone are treated as UTC. - ttl_days
int | None– Optional expiration refresh in days. Omit this argument to leave the current expiration unchanged unlessttl_anchoris provided. PassNoneto useMemoryRetentionConfig.max_ttl_dayswhen the retention configuration sets one, or to clear expiration when it does not. Values aboveMemoryRetentionConfig.max_ttl_daysare clamped to that maximum with a warning. Expired memories are unavailable to this client API and cannot be refreshed. - ttl_anchor
TimeToLiveAnchor– Optional time-to-live anchor for an expiration refresh. UseTimeToLiveAnchor.CREATED_ATfor the memory creation time orTimeToLiveAnchor.TIMESTAMPfor the replacementtimestampsupplied in the same update, or the stored event timestamp whentimestampis omitted. Providingttl_anchorwithoutttl_daysuses the schema default time-to-live duration. Whenttl_anchoris omitted during a refresh, the client usesTimeToLiveAnchor.CREATED_AT. ISO-8601 timestamps without a timezone are treated as UTC. - **kwargs (Any) – Unexpected keyword arguments are rejected.
- memory_id
- Returns: Identifier of the updated memory-like record.
- Return type: str
Notes
Omitted fields are preserved from the stored record. Stored scope remains unchanged. Metadata replacement is whole-object replacement, not recursive JSON merge.
method update_memory_async (async)
Asynchronously update a stored memory-like record by identifier.
- Parameters:
- memory_id
str– Identifier of the memory-like record to update. - content
str– Optional replacement content. Provide a string to replace the stored content. When omitted, the stored content is preserved. PassingNoneis not supported; omitcontentto keep the current value, or usedelete_memory()to remove the record. - metadata
dict[str, Any] | None– Optional replacement metadata mapping. When omitted, the stored metadata is preserved. When provided, it replaces the stored metadata object; this API does not deep-merge metadata. - timestamp
str | None– Optional new timestamp for this memory. It represents when the memory was created. When omitted, the stored timestamp is preserved. PassNoneto clear the saved timestamp and use the time the record was created in the store. - ttl_days
int | None– Optional expiration refresh in days. Omit this argument together withttl_anchorto leave the current expiration unchanged. PassNoneto clear expiration. - ttl_anchor
TimeToLiveAnchor– Optional time-to-live anchor for an expiration refresh. UseTimeToLiveAnchor.CREATED_ATfor the memory creation time orTimeToLiveAnchor.TIMESTAMPfor the replacementtimestampsupplied in the same update, or the stored event timestamp whentimestampis omitted. Providingttl_anchorwithoutttl_daysuses the schema default time-to-live duration. Whenttl_anchoris omitted during a refresh, stores useTimeToLiveAnchor.CREATED_AT. - **kwargs (Any) – Unexpected keyword arguments are rejected.
- memory_id
- Returns: Identifier of the updated memory-like record.
- Return type: str
Notes
Omitted fields remain unchanged. Scope updates are not supported by this API. Metadata replacement is whole-object replacement, not recursive JSON merge.
method update_thread
Persist thread metadata and durable runtime configuration updates.
- Parameters:
- thread_id
str– Identifier of the thread to update. - metadata
dict[str, Any] | None– Optional metadata update for the conversation thread. When omitted, the stored metadata is left unchanged. PassingNoneexplicitly clears stored metadata. When a mapping is provided, it replaces the stored metadata object. - llm
ILlm– Optional LLM override for the returnedOracleThreadinstance. This is not persisted, but it participates in the same validation rules asget_threadandcreate_thread. -
extract_memories
bool–Optional durable override for automatic memory extraction.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. - max_message_token_length
int– Optional durable override for the maximum prompt-time message size used during extraction and summarization. - message_shortening_input_token_limit
int– Optional durable override for the maximum excerpt size sent to the LLM when shortening oversized messages. -
memory_extraction_window
int–Optional durable override for the extraction window size.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
context_summary_update_frequency
int–Optional durable override for how many appended messages trigger a context-summary refresh.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_frequency
int–Optional durable override for how many appended messages trigger automatic memory extraction.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_token_limit
int–Optional durable override for extraction and running-summary prompt budgets.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. - context_card_token_limit
int– Optional durable override for the input token budget of the LLM prompt used to build the summary and topic list included in the context card. -
enable_context_summary
bool–Optional durable override for whether running context summaries stay enabled.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_custom_instructions
str | None–Optional durable custom instructions appended to the memory extraction system prompt. Passing
Noneclears any stored thread-level custom instructions; a client-level default still applies when configured.Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. -
memory_extraction_inherit_message_metadata
bool | Sequence[str]–Optional durable override for metadata copied from source messages onto automatically extracted memories.
Info: Deprecated since version 26.6.0: This parameter was deprecated in 26.6.0 and will be removed in 27.1. Please use
memory_extraction_configinstead. - memory_extraction_config
MemoryExtractionConfig– Optional grouped durable extraction config update. Provided fields are written to the stored thread config and used by later loadedOracleThreadinstances and later background extraction jobs. - **kwargs (Any) – Additional implementation-specific options.
OracleAgentMemorycurrently rejects unknown keyword arguments.
- thread_id
- Returns:
Updated
OracleThreadinstance reflecting the persisted metadata and runtime configuration. - Return type: OracleThread
- Raises:
- KeyError – If the thread id is unknown to this client instance.
- ValueError – If no LLM is available for automatic memory extraction after resolving the effective runtime configuration.
Notes
Runtime configuration is resolved from the stored conversation thread plus the
explicit overrides passed to this call, matching get_thread
semantics before persisting the result. Omitted metadata and runtime
config updates are resolved from stored data, not from any
previously loaded OracleThread instance, and only explicitly provided metadata
updates or durable runtime-config overrides are written back.
Metadata replacement is whole-object replacement, not recursive JSON
merge. Thread ownership is not mutable through this API, so
user_id and agent_id remain unchanged. Mutable runtime state,
such as extraction counters, is left untouched.
Examples
from oracleagentmemory.core import OracleAgentMemory
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
llm=llm,
)
updated = client.update_thread(
"c1",
metadata={"flags": {"vip": True}},
message_shortening_input_token_limit=12_000,
)
updated.message_shortening_input_token_limit
12000
method wait_for_memory_extraction
Wait for earlier background memory extraction started by this client.
This method waits for background extraction already started through
this OracleAgentMemory instance, across all threads owned by this
agent memory component. It does not wait for extraction started after
this wait begins, for extraction started by another agent memory
component, or for extraction running in another process. Extraction
failures count as finished for this wait.
- Parameters:
timeout
float | None– Optional maximum number of seconds to wait. Defaults to300. PassNoneto wait until this agent memory component has no pending extraction. - Raises: TimeoutError – Raised when the timeout expires before the earlier background extraction finishes.
- Return type: None
Examples
client = OracleAgentMemory(
connection=db_pool,
embedder=embedder,
memory_extraction_config=MemoryExtractionConfig(extract_memories=False),
)
client.wait_for_memory_extraction(timeout=10)
method wait_for_memory_extraction_async (async)
Asynchronously wait for earlier background memory extraction.
This method follows the same behavior as
wait_for_memory_extraction().
- Parameters:
timeout
float | None– Optional maximum number of seconds to wait. Defaults to300. PassNoneto wait indefinitely. - Raises: TimeoutError – Raised when the timeout expires before the earlier background extraction finishes.
- Return type: None
Examples
await client.wait_for_memory_extraction_async(timeout=10)
Memory Extraction
class oracleagentmemory.core.MemoryExtractionConfig
Bases: object
Grouped settings for automatic memory extraction.
Pass this object to OracleAgentMemory, create_thread,
get_thread, or update_thread to configure automatic extraction.
Omitted fields inherit from the next broader setting. For example, a
thread created without memory_extraction_frequency uses the agent
memory component default, and the component default falls back to the SDK
default.
- Parameters:
- memory_extraction_window
int– Recent-message window used for extraction prompts.-1means the extraction prompt uses only the newly added messages. Omit this field to inherit the value. - context_summary_update_frequency
int– Number of appended messages between running context-summary refreshes. Values below0refresh after every append. Omit this field to inherit the value. - memory_extraction_frequency
int– Number of appended messages between memory extraction runs. Values below0extract after every append. Omit this field to inherit the value. - memory_extraction_token_limit
int– Input token budget for extraction and summary prompts. Values below1disable the prompt budget limit. Omit this field to inherit the value. - extract_memories
bool– Whether automatic memory extraction is enabled. Set toFalseto disable automatic extraction and allow operation without an extraction LLM. Omit this field to inherit the value. - enable_context_summary
bool– Whether extraction prompts maintain and use a running context summary. Omit this field to inherit the value. - memory_extraction_custom_instructions
str | None– Optional caller instructions appended to the extraction system prompt. PassNoneonupdate_threadto clear stored thread-level instructions. Omit this field to inherit the value. - memory_extraction_inherit_message_metadata
bool | collections.abc.Sequence[str]– Controls metadata copied from source messages onto extracted memories.Truecopies all source-message metadata,Falsecopies none, and a sequence copies only matching top-level metadata keys. Omit this field to inherit the value. - extraction_mode
oracleagentmemory.core.extractors.memoryextractionconfig.MemoryExtractionMode–MemoryExtractionMode.INLINEruns automatic extraction before the write method returns.MemoryExtractionMode.BACKGROUNDreturns after the raw write succeeds and due extraction work is attempted in the background. In background mode, derived memories may appear later, may be temporarily stale, or may never be written if the background work cannot complete. For example,update_message()can return before a later memory read reflects the updated message content. Omit this field to inherit the value. When no broader value is configured, the effective mode isINLINE. - background_extraction_queue_full_behavior
oracleagentmemory.core.extractors.memoryextractionconfig.BackgroundExtractionQueueFullBehavior– In background mode, controls what happens when automatic extraction cannot queue immediately.DROPlogs a warning and continues without waiting.WAIT_THEN_DROPwaits for queue capacity up to the configured timeout, then logs a warning and continues.WAIT_THEN_RAISEwaits for queue capacity up to the configured timeout, then raisesTimeoutErrorafter the raw write succeeds. Omit this field to inherit the value. When no broader value is configured, the effective default isDROP. - background_extraction_queue_put_timeout_seconds
float– In background mode, maximum number of seconds automatic extraction waits for queue capacity whenbackground_extraction_queue_full_behaviorisWAIT_THEN_DROPorWAIT_THEN_RAISE. Omit this field to inherit the value. When no broader value is configured, the effective default is300.0seconds.
- memory_extraction_window
Examples
from oracleagentmemory.core import MemoryExtractionConfig, MemoryExtractionMode
config = MemoryExtractionConfig(
extract_memories=True,
extraction_mode=MemoryExtractionMode.BACKGROUND,
)
class oracleagentmemory.core.MemoryExtractionMode
Bases: str, Enum
Controls when automatic memory extraction work runs.
INLINE runs automatic extraction before the write method returns.
BACKGROUND returns after the raw write succeeds and due extraction
work is attempted in the background. Background extraction is best
effort: derived memories may appear later, or may never be written
if the background work cannot complete.
BACKGROUND = ‘BACKGROUND’
Return after raw message persistence and run best-effort extraction in background work.
INLINE = ‘INLINE’
Run extraction before the write method returns.
class oracleagentmemory.core.BackgroundExtractionQueueFullBehavior
Bases: str, Enum
Controls what happens when background extraction cannot queue in time.
DROP = ‘DROP’
Log a warning and continue immediately when queue capacity is unavailable.
WAIT_THEN_DROP = ‘WAIT_THEN_DROP’
Wait for queue capacity up to the configured timeout, then log a warning and continue.
WAIT_THEN_RAISE = ‘WAIT_THEN_RAISE’
Wait for queue capacity up to the configured timeout, then raise TimeoutError.