MemoryStrategy

class aws_cdk.aws_bedrock_agentcore_alpha.MemoryStrategy

Bases: object

(experimental) Factory class for creating memory strategies If you need long-term memory for context recall across sessions, you can setup memory extraction strategies to extract the relevant memory from the raw events.

Use built-in strategies for quick setup, use built-in strategies with override to specify models and prompt templates.

See:

https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies.html

Stability:

experimental

ExampleMetadata:

fixture=default infused

Example:

# Create a custom semantic memory strategy
custom_semantic_strategy = agentcore.MemoryStrategy.using_semantic(
    name="customSemanticStrategy",
    description="Custom semantic memory strategy",
    namespaces=["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
    custom_consolidation=agentcore.OverrideConfig(
        model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
        append_to_prompt="Custom consolidation prompt for semantic memory"
    ),
    custom_extraction=agentcore.OverrideConfig(
        model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
        append_to_prompt="Custom extraction prompt for semantic memory"
    )
)

# Create memory with custom strategy
memory = agentcore.Memory(self, "MyMemory",
    memory_name="my-custom-memory",
    description="Memory with custom strategy",
    expiration_duration=cdk.Duration.days(90),
    memory_strategies=[custom_semantic_strategy]
)
Stability:

experimental

Static Methods

classmethod using_built_in_semantic()

(experimental) Default strategies for organizing and extracting memory data, each optimized for specific use cases.

Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format. Extracted memory example: In-context learning = task-solving via examples, no training needed.

Return type:

ManagedMemoryStrategy

Returns:

A ManagedMemoryStrategy.

Stability:

experimental

classmethod using_built_in_summarization()

(experimental) Default strategies for organizing and extracting memory data, each optimized for specific use cases.

This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall. Extracted memory example: Users confused by cloud setup during onboarding.

Return type:

ManagedMemoryStrategy

Returns:

A ManagedMemoryStrategy.

Stability:

experimental

classmethod using_built_in_user_preference()

(experimental) Default strategies for organizing and extracting memory data, each optimized for specific use cases.

Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences. Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.

Return type:

ManagedMemoryStrategy

Returns:

A ManagedMemoryStrategy.

Stability:

experimental

classmethod using_self_managed(*, invocation_configuration, historical_context_window_size=None, trigger_conditions=None, name, description=None)

(experimental) Creates a self-managed memory strategy.

A self-managed strategy gives you complete control over your memory extraction and consolidation pipelines.

Parameters:
  • invocation_configuration (Union[InvocationConfiguration, Dict[str, Any]]) – (experimental) Invocation configuration for self managed memory strategy.

  • historical_context_window_size (Union[int, float, None]) – (experimental) Define the number of previous events to be included when processing memory. A larger history window provides more context from past conversations. Default: 4

  • trigger_conditions (Union[TriggerConditions, Dict[str, Any], None]) – (experimental) Trigger conditions for self managed memory strategy. Default: - undefined

  • name (str) – (experimental) The name for the strategy.

  • description (Optional[str]) – (experimental) The description of the strategy. Default: - No description

Return type:

SelfManagedMemoryStrategy

Returns:

A SelfManagedMemoryStrategy.

Stability:

experimental

classmethod using_semantic(*, namespaces, custom_consolidation=None, custom_extraction=None, name, description=None)

(experimental) Creates a semantic memory strategy with custom configuration.

Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format. Extracted memory example: In-context learning = task-solving via examples, no training needed.

Parameters:
  • namespaces (Sequence[str]) – (experimental) The namespaces for the strategy Represents a namespace for organizing memory data Use a hierarchical format separated by forward slashes (/). Use a hierarchical format separated by forward slashes (/) to organize namespaces logically. You can include these defined variables: - {sessionId} - the user identifier to be created in the CreateEvent API - {memoryStrategyId} - an identifier for an extraction strategy - {sessionId} - an identifier for each session Example namespace path: /strategies/{memoryStrategyId}/actions/{actionId}/sessions/{sessionId} After memory creation, this namespace might look like: /actor/actor-3afc5aa8fef9/strategy/summarization-fy5c5fwc7/session/session-qj7tpd1kvr8

  • custom_consolidation (Union[OverrideConfig, Dict[str, Any], None]) – (experimental) The configuration for the custom consolidation. This configuration provides customization to how the model identifies and extracts relevant information for memory storage. Default: - No custom extraction

  • custom_extraction (Union[OverrideConfig, Dict[str, Any], None]) – (experimental) The configuration for the custom extraction. This configuration provides customization to how the model identifies and extracts relevant information for memory storage. Default: - No custom extraction

  • name (str) – (experimental) The name for the strategy.

  • description (Optional[str]) – (experimental) The description of the strategy. Default: - No description

Return type:

ManagedMemoryStrategy

Returns:

A ManagedMemoryStrategy.

Stability:

experimental

classmethod using_summarization(*, namespaces, custom_consolidation=None, custom_extraction=None, name, description=None)

(experimental) Creates a summarization memory strategy with custom configuration.

This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall. Extracted memory example: Users confused by cloud setup during onboarding.

Parameters:
  • namespaces (Sequence[str]) – (experimental) The namespaces for the strategy Represents a namespace for organizing memory data Use a hierarchical format separated by forward slashes (/). Use a hierarchical format separated by forward slashes (/) to organize namespaces logically. You can include these defined variables: - {sessionId} - the user identifier to be created in the CreateEvent API - {memoryStrategyId} - an identifier for an extraction strategy - {sessionId} - an identifier for each session Example namespace path: /strategies/{memoryStrategyId}/actions/{actionId}/sessions/{sessionId} After memory creation, this namespace might look like: /actor/actor-3afc5aa8fef9/strategy/summarization-fy5c5fwc7/session/session-qj7tpd1kvr8

  • custom_consolidation (Union[OverrideConfig, Dict[str, Any], None]) – (experimental) The configuration for the custom consolidation. This configuration provides customization to how the model identifies and extracts relevant information for memory storage. Default: - No custom extraction

  • custom_extraction (Union[OverrideConfig, Dict[str, Any], None]) – (experimental) The configuration for the custom extraction. This configuration provides customization to how the model identifies and extracts relevant information for memory storage. Default: - No custom extraction

  • name (str) – (experimental) The name for the strategy.

  • description (Optional[str]) – (experimental) The description of the strategy. Default: - No description

Return type:

ManagedMemoryStrategy

Returns:

A ManagedMemoryStrategy.

Stability:

experimental

classmethod using_user_preference(*, namespaces, custom_consolidation=None, custom_extraction=None, name, description=None)

(experimental) Creates a user preference memory strategy with custom configuration.

Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences. Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.

Parameters:
  • namespaces (Sequence[str]) – (experimental) The namespaces for the strategy Represents a namespace for organizing memory data Use a hierarchical format separated by forward slashes (/). Use a hierarchical format separated by forward slashes (/) to organize namespaces logically. You can include these defined variables: - {sessionId} - the user identifier to be created in the CreateEvent API - {memoryStrategyId} - an identifier for an extraction strategy - {sessionId} - an identifier for each session Example namespace path: /strategies/{memoryStrategyId}/actions/{actionId}/sessions/{sessionId} After memory creation, this namespace might look like: /actor/actor-3afc5aa8fef9/strategy/summarization-fy5c5fwc7/session/session-qj7tpd1kvr8

  • custom_consolidation (Union[OverrideConfig, Dict[str, Any], None]) – (experimental) The configuration for the custom consolidation. This configuration provides customization to how the model identifies and extracts relevant information for memory storage. Default: - No custom extraction

  • custom_extraction (Union[OverrideConfig, Dict[str, Any], None]) – (experimental) The configuration for the custom extraction. This configuration provides customization to how the model identifies and extracts relevant information for memory storage. Default: - No custom extraction

  • name (str) – (experimental) The name for the strategy.

  • description (Optional[str]) – (experimental) The description of the strategy. Default: - No description

Return type:

ManagedMemoryStrategy

Returns:

A ManagedMemoryStrategy.

Stability:

experimental