# ManagedMemoryStrategy

Managed memory strategy that handles both built-in and override configurations.

This strategy can be used for quick setup with built-in defaults or customized
with specific models and prompt templates.

Implements: [IMemoryStrategy](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.IMemoryStrategy.html)
Obtainable from: [MemoryStrategy.usingBuiltInEpisodic](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingbuiltinepisodic), [MemoryStrategy.usingBuiltInSemantic](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingbuiltinsemantic), [MemoryStrategy.usingBuiltInSummarization](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingbuiltinsummarization), [MemoryStrategy.usingBuiltInUserPreference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingbuiltinuserpreference), [MemoryStrategy.usingEpisodic](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingepisodic), [MemoryStrategy.usingSemantic](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingsemantic), [MemoryStrategy.usingSummarization](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usingsummarization), [MemoryStrategy.usingUserPreference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategy.html#usinguserpreference)

- Source: [`aws-bedrockagentcore/lib/memory/strategies/managed-strategy.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-bedrockagentcore/lib/memory/strategies/managed-strategy.ts#L118)
- Type last changed: v2.255.0 · 19 May 2026

## Example

TypeScript:

```ts
// Create a custom semantic memory strategy
const customSemanticStrategy = agentcore.MemoryStrategy.usingSemantic({
  strategyName: "customSemanticStrategy",
  description: "Custom semantic memory strategy",
  namespaces: ["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
  customConsolidation: {
    model: bedrock.FoundationModel.fromFoundationModelId(this, 'ConsolidationModel',
      bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0,
    ),
    appendToPrompt: "Custom consolidation prompt for semantic memory",
  },
  customExtraction: {
    model: bedrock.FoundationModel.fromFoundationModelId(this, 'ExtractionModel',
      bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0,
    ),
    appendToPrompt: "Custom extraction prompt for semantic memory",
  },
});

// Create memory with custom strategy
const memory = new agentcore.Memory(this, "MyMemory", {
  memoryName: "my-custom-memory",
  description: "Memory with custom strategy",
  expirationDuration: cdk.Duration.days(90),
  memoryStrategies: [customSemanticStrategy],
});
```

Python:

```python
# Create a custom semantic memory strategy
custom_semantic_strategy = agentcore.MemoryStrategy.using_semantic(
    strategy_name="customSemanticStrategy",
    description="Custom semantic memory strategy",
    namespaces=["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
    custom_consolidation=agentcore.OverrideConfig(
        model=bedrock.FoundationModel.from_foundation_model_id(self, "ConsolidationModel", bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0),
        append_to_prompt="Custom consolidation prompt for semantic memory"
    ),
    custom_extraction=agentcore.OverrideConfig(
        model=bedrock.FoundationModel.from_foundation_model_id(self, "ExtractionModel", bedrock.FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_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]
)
```

Java:

```java
// Create a custom semantic memory strategy
ManagedMemoryStrategy customSemanticStrategy = MemoryStrategy.usingSemantic(ManagedStrategyProps.builder()
        .strategyName("customSemanticStrategy")
        .description("Custom semantic memory strategy")
        .namespaces(List.of("/custom/strategies/{memoryStrategyId}/actors/{actorId}"))
        .customConsolidation(OverrideConfig.builder()
                .model(FoundationModel.fromFoundationModelId(this, "ConsolidationModel", FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0))
                .appendToPrompt("Custom consolidation prompt for semantic memory")
                .build())
        .customExtraction(OverrideConfig.builder()
                .model(FoundationModel.fromFoundationModelId(this, "ExtractionModel", FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0))
                .appendToPrompt("Custom extraction prompt for semantic memory")
                .build())
        .build());

// Create memory with custom strategy
Memory memory = Memory.Builder.create(this, "MyMemory")
        .memoryName("my-custom-memory")
        .description("Memory with custom strategy")
        .expirationDuration(Duration.days(90))
        .memoryStrategies(List.of(customSemanticStrategy))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// Create a custom semantic memory strategy
var customSemanticStrategy = MemoryStrategy.UsingSemantic(new ManagedStrategyProps {
    StrategyName = "customSemanticStrategy",
    Description = "Custom semantic memory strategy",
    Namespaces = new [] { "/custom/strategies/{memoryStrategyId}/actors/{actorId}" },
    CustomConsolidation = new OverrideConfig {
        Model = FoundationModel.FromFoundationModelId(this, "ConsolidationModel", FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0),
        AppendToPrompt = "Custom consolidation prompt for semantic memory"
    },
    CustomExtraction = new OverrideConfig {
        Model = FoundationModel.FromFoundationModelId(this, "ExtractionModel", FoundationModelIdentifier.ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0),
        AppendToPrompt = "Custom extraction prompt for semantic memory"
    }
});

// Create memory with custom strategy
var memory = new Memory(this, "MyMemory", new MemoryProps {
    MemoryName = "my-custom-memory",
    Description = "Memory with custom strategy",
    ExpirationDuration = Duration.Days(90),
    MemoryStrategies = new [] { customSemanticStrategy }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Create a custom semantic memory strategy
customSemanticStrategy := agentcore.MemoryStrategy_UsingSemantic(&ManagedStrategyProps{
	StrategyName: jsii.String("customSemanticStrategy"),
	Description: jsii.String("Custom semantic memory strategy"),
	Namespaces: []*string{
		jsii.String("/custom/strategies/{memoryStrategyId}/actors/{actorId}"),
	},
	CustomConsolidation: &OverrideConfig{
		Model: bedrock.FoundationModel_FromFoundationModelId(this, jsii.String("ConsolidationModel"), bedrock.FoundationModelIdentifier_ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0()),
		AppendToPrompt: jsii.String("Custom consolidation prompt for semantic memory"),
	},
	CustomExtraction: &OverrideConfig{
		Model: bedrock.FoundationModel_*FromFoundationModelId(this, jsii.String("ExtractionModel"), bedrock.FoundationModelIdentifier_ANTHROPIC_CLAUDE_3_5_SONNET_20241022_V2_0()),
		AppendToPrompt: jsii.String("Custom extraction prompt for semantic memory"),
	},
})

// Create memory with custom strategy
memory := agentcore.NewMemory(this, jsii.String("MyMemory"), &MemoryProps{
	MemoryName: jsii.String("my-custom-memory"),
	Description: jsii.String("Memory with custom strategy"),
	ExpirationDuration: cdk.Duration_Days(jsii.Number(90)),
	MemoryStrategies: []IMemoryStrategy{
		customSemanticStrategy,
	},
})
```

## Initializer

TypeScript:

```ts
new ManagedMemoryStrategy(strategyType: MemoryStrategyType, props: ManagedStrategyProps)
```

Python:

```python
ManagedMemoryStrategy(strategy_type: MemoryStrategyType, props: ManagedStrategyProps)
```

Java:

```java
new ManagedMemoryStrategy(MemoryStrategyType strategyType, ManagedStrategyProps props)
```

C# / .NET:

```csharp
new ManagedMemoryStrategy(MemoryStrategyType strategyType, ManagedStrategyProps props)
```

Golang:

```go
NewManagedMemoryStrategy(StrategyType MemoryStrategyType, Props ManagedStrategyProps)
```

## Properties

- `consolidationOverride`: [OverrideConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.OverrideConfig.html) — The configuration for the custom consolidation.

- `description`: string — The description of the memory strategy.

- `extractionOverride`: [OverrideConfig](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.OverrideConfig.html) — The configuration for the custom extraction.

- `namespaces`: string[] — The namespaces for the strategy.

- `reflectionConfiguration`: [EpisodicReflectionConfiguration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.EpisodicReflectionConfiguration.html) — The configuration for episodic reflection.

- `strategyName`: string — The name of the memory strategy.

- `strategyType`: [MemoryStrategyType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.MemoryStrategyType.html) — The type of memory strategy.

## Methods

- `grant(grantee: IGrantable): Grant` — Grants the necessary permissions to the role.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The grantee to grant permissions to.

  **Returns:** The Grant object for chaining

- `render(): CfnMemory.MemoryStrategyProperty` — Renders the network configuration as a CloudFormation property.

  **Returns:** The CloudFormation property for the memory strategy.
