Skip to content

strands.memory.extraction.model_extractor

Model-backed :class:Extractor that distills messages into discrete facts.

A :class:ModelExtractor calls a language model with a fact-extraction system prompt and parses the response into :class:ExtractionResult entries. Backends that extract server-side should omit the extractor entirely.

class ModelExtractor()

Defined in: src/strands/memory/extraction/model_extractor.py:31

An :class:Extractor that calls a language model to distill messages into discrete facts.

Use for self-managed stores that hold plain text and want automatic distillation.

Example:

ExtractionConfig(
trigger=[InvocationTrigger()],
extractor=ModelExtractor(model=cheap_model, system_prompt="Extract user preferences."),
)
def __init__(model: Model | None = None,
system_prompt: str | None = None) -> None

Defined in: src/strands/memory/extraction/model_extractor.py:46

Initialize the extractor.

Arguments:

  • model - Model used to extract facts. Defaults to the agent’s own model (via :attr:ExtractorContext.default_model); set a cheaper one to cut cost.
  • system_prompt - System prompt steering what counts as a fact. Defaults to a general fact-extraction prompt.
async def extract(
messages: list[Message],
context: ExtractorContext | None = None) -> list[ExtractionResult]

Defined in: src/strands/memory/extraction/model_extractor.py:59

Extract entries from a batch of messages.

Raises:

  • ValueError - If no model is configured and no default is available.
  • RuntimeError - If the model returns no response.