strands.memory.extraction.types
Primitive types for the memory extraction subsystem.
ExtractionResult
Section titled “ExtractionResult”@dataclassclass ExtractionResult()Defined in: src/strands/memory/extraction/types.py:39
A discrete entry produced by an :class:Extractor, ready to write via add.
ExtractorContext
Section titled “ExtractorContext”@dataclassclass ExtractorContext()Defined in: src/strands/memory/extraction/types.py:47
Context passed to :meth:Extractor.extract.
Attributes:
default_model- The agent’s model, supplied so an extractor can default to it.
Extractor
Section titled “Extractor”class Extractor(Protocol)Defined in: src/strands/memory/extraction/types.py:58
Transforms conversation messages into discrete, searchable entries.
Optional on a store’s :class:ExtractionConfig: when absent, the manager
passes messages straight to the store’s add_messages (the no-extractor
passthrough), which is the right path for backends that extract server-side.
extract
Section titled “extract”async def extract( messages: list[Message], context: ExtractorContext | None = None) -> list[ExtractionResult]Defined in: src/strands/memory/extraction/types.py:66
Extract entries from a batch of messages.
MemoryMessageFilter
Section titled “MemoryMessageFilter”@dataclassclass MemoryMessageFilter()Defined in: src/strands/memory/extraction/types.py:72
Filters content blocks out of messages before extraction.
Blocks whose kind is in :attr:exclude are stripped; a message left with no
content is dropped. Defaults to excluding tool traffic (toolUse /
toolResult).
ExtractionTriggerContext
Section titled “ExtractionTriggerContext”@dataclassclass ExtractionTriggerContext()Defined in: src/strands/memory/extraction/types.py:88
Context handed to :meth:ExtractionTrigger.attach.
Attributes:
agent- The agent the trigger attaches its hooks to.fire- Save this store’s unsaved messages now. Runs in the background and returns immediately. To await completion, seeMemoryManager.flush.
ExtractionTrigger
Section titled “ExtractionTrigger”class ExtractionTrigger(ABC)Defined in: src/strands/memory/extraction/types.py:101
Controls when a store’s :class:ExtractionConfig runs.
A trigger is a self-attaching value object: :meth:attach wires the agent
hooks it needs and calls :attr:ExtractionTriggerContext.fire when extraction
should happen. Subclass for custom triggering logic. A trigger that never
fires never extracts; for a guaranteed final write, use
MemoryManager.flush.
Attributes:
name- Stable identifier for this trigger kind, used in logging.
attach
Section titled “attach”@abstractmethoddef attach(context: ExtractionTriggerContext) -> NoneDefined in: src/strands/memory/extraction/types.py:117
Wire this trigger into the agent lifecycle.
Called once per store during MemoryManager initialization. Register
hooks on context.agent and call context.fire() when extraction
should run.
ExtractionConfig
Section titled “ExtractionConfig”class ExtractionConfig(TypedDict)Defined in: src/strands/memory/extraction/types.py:127
Per-store automatic-extraction configuration.
Attributes:
trigger- When to run extraction. A single trigger or a list; multiple triggers compose (extraction runs whenever any fires). Omit to default to every 5 turns; an explicit empty list is rejected at construction.extractor- How to turn messages into entries. When set, the store must implementadd. When omitted, the default depends on the store’s write methods: a store implementing onlyadddefaults to a :class:~strands.memory.extraction.model_extractor.ModelExtractorthat distills facts client-side, while a store implementingadd_messagesuses server-side extraction (the manager hands the filtered messages straight toadd_messages, no model call).filter- Content blocks to strip before extraction. Defaults to :data:DEFAULT_MEMORY_MESSAGE_FILTER(excludestoolUse/toolResult). PassMemoryMessageFilter(exclude=[])to keep tool blocks.