Amazon Bedrock AgentCore now supports a structured approach to pruning and consolidating the memories that long‑running agents accumulate. By introducing a nightly workflow that scores, merges, and expires records, engineers can keep agents’ context fresh, avoid compliance pitfalls, and reduce unnecessary compute.
Memory taxonomy for AgentCore
Before applying any policy, it helps to classify what the agent stores. The blog defines three categories:
- Episodic memory – raw conversation logs tied to a session, stored as
SummaryorEpisodicentries. High volume and short‑lived; they should be the first candidates for removal. - Semantic memory – distilled facts or preferences extracted from interactions. Low volume, high value, and suitable for long‑term retention or consolidation.
- Procedural memory – learned workflows and tool‑use patterns, stored as reflections linked to episodic records. Small in number but critical for agent behavior; they merit the most cautious pruning.
Three complementary lifecycle policies
The solution bundles three policies that run in sequence each night.
Policy 1 – TTL‑based expiration
A hard time‑to‑live limit removes stale entries regardless of perceived usefulness. The default is 90 days for episodic records, with shorter windows for summaries and longer windows for semantic data. Procedural memories can be left without a TTL.
AgentCore does not auto‑expire records, but it exposes a timestamp field (x-amz-agentcore-memory-createdAt) that can be filtered with BEFORE. The pruning step queries records older than the cutoff and deletes them.
cutoff = (now - timedelta(days=ttl_days)).isoformat()
response = client.list_memory_records(
memoryId=memory_id,
namespace=agent_id,
metadataFilters=[{
"left": {"metadataKey": "x-amz-agentcore-memory-createdAt"},
"operator": "BEFORE",
"right": {"metadataValue": {"dateTimeValue": cutoff}}
}]
)
Policy 2 – Scoring and prioritization
After TTL removal, remaining records are scored based on recency, access frequency, and relevance signals (e.g., whether a memory contributed to a successful response). High‑score items are retained for the next step; low‑score items are flagged for possible deletion.
Policy 3 – Consolidation of semantic facts
Multiple episodic observations that describe the same fact are merged into a single semantic entry. This reduces storage, improves lookup speed, and creates a canonical source of truth for preferences such as region choices.
Operational architecture
The workflow is orchestrated with AWS Step Functions. A nightly state machine invokes Lambda functions that perform the three policies in order, using the Bedrock SDK to list, filter, and delete memory records. The CDK stack provisions the Step Functions definition, the required IAM role, and the Lambda functions. Because the process runs off‑peak, it minimizes impact on latency‑sensitive request paths.
Security and compliance considerations
Explicit TTL enforcement helps meet data‑retention mandates and GDPR‑style deletion requirements. Since the pruning logic runs with the same permissions as the agent, it is essential to scope the IAM role to the specific memoryId and namespace of the target agent, avoiding broader access to other agents’ memories. Auditing can be added by logging each delete operation to CloudWatch or an S3 audit trail.
Related CloudNinjas coverage: AWS.
What This Means For Practitioners
Implementing the described lifecycle workflow gives you deterministic control over AgentCore’s knowledge base, preventing stale context from degrading response quality and reducing compliance risk. Engineers should provision the CDK stack, tune the memoryTtlDays and scoring thresholds for their workload, and monitor delete logs to verify that only intended records are removed. Ongoing evaluation of retention periods and consolidation rules will keep the agent’s memory footprint aligned with business and regulatory needs.


