fix(18-self-improving-agents): repair AgentCore Memory setup for workshop#280
Open
agent-of-mkmeral wants to merge 2 commits into
Open
Conversation
…shop The step-3 memory setup (create_memory.py, shared by steps 3-5) failed against the current AgentCore CreateMemory API, blocking steps 3, 4, and 5: - Add required eventExpiryDuration (CreateMemory now requires it; omitting it raises 'Missing required parameter: eventExpiryDuration'). - Model facts and preferences as TWO strategy types (semanticMemoryStrategy + userPreferenceMemoryStrategy), each with a single namespace. The API caps a strategy at one namespace and one strategy per type, so the prior two-namespace single-semantic-strategy shape was rejected. This keeps the existing /facts and /preferences namespaces, so the three agents' retrieval_config stays valid (no agent.py changes needed). - Harden list_memories pagination key (memories vs memorySummaries). Also: - deploy.sh now injects BEDROCK_AGENTCORE_MODEL_ID into .env.local (step-5 agent.py reads it; without it the deployed runtime got MODEL_ID=None). - README/notebook: align model label with the model actually used (Claude Opus 4 / global.anthropic.claude-opus-4-8).
The PR's stated goal strands-agents#3 was to align model labels with the actual hardcoded MODEL_ID = global.anthropic.claude-opus-4-8 used by every agent.py. Iteration 1 only fixed 3 of the occurrences; this pass fixes the rest: - notebooks/00,01,02,04: '# Claude Sonnet 4.5' comment -> neutral SSM-param note (matching the already-fixed notebooks/03_memory.ipynb) - notebooks/00 prose: 'Claude Sonnet 4.5' -> 'Claude Opus 4' - code/step-00-hello/agent.py docstring: 'Claude 4.6 Sonnet' -> 'Claude Opus 4' Core memory fix from iteration 1 re-verified against botocore model + SDK README.
Author
🟢 Remaining finding (non-blocking, not in this diff)The rendered/pre-generated assets still display the old "Claude 4.6 Sonnet" label — these aren't editable source so they're out of scope for this surgical fix, but flagging for a future regeneration:
All source files (README, notebooks, |
|
Latest scan for commit: ✅ Security Scan Report (PR Files Only)Scanned Files
Security Scan Results
Threshold: High No security issues detected in your changes. Great job! This scan only covers files changed in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the Amazon Bedrock AgentCore Memory setup for the
python/01-learn/18-self-improving-agentsworkshop (AIM308), which is currently broken against the live AgentCoreCreateMemoryAPI. Every attendee hits a hard failure on Step 3 (memory) — which also blocks Steps 4 and 5 — becausecreate_memory.pyis missing a now-required parameter and uses a strategy/namespace shape the API no longer accepts. Also fixes a deploy-config gap and aligns the model label with the model the code actually uses.Workshop bug context (from end-to-end testing)
Steps 0, 1, 2, 4 work flawlessly. Step 3 fails at
create_memory.py:…and even after adding that, the API rejects the old single-
semanticMemoryStrategyshape that packed two namespaces (/facts+/preferences) into one strategy — the current API caps namespaces at 1 per strategy and allows one strategy per type.What changed (7 files, surgical)
create_memory.pymissing requiredeventExpiryDurationeventExpiryDuration=90(env-overridable viaAIM308_EVENT_EXPIRY_DAYS) to all 3create_memory.pycopies (steps 03/04/05).semanticMemoryStrategy(/users/{actorId}/facts) +userPreferenceMemoryStrategy(/users/{actorId}/preferences) — each with a single namespace. Satisfies the API's 1-namespace-per-strategy / 1-strategy-per-type limits while keeping both namespaces, so noagent.pychanges are needed. This matches the canonical pattern in the AgentCore SDK's own Strands integration README.list_memoriespaginator keymemorySummaries→memories(matches the botocore paginator config). Kept a.get(..., .get(...))fallback for backward compatibility.deploy.shnever injected the model IDdeploy.shnow writesBEDROCK_AGENTCORE_MODEL_IDinto.env.local(defaultglobal.anthropic.claude-opus-4-8); the deployed Step-5 runtime previously gotMODEL_ID=None.global.anthropic.claude-opus-4-8) — the model everyagent.pyactually hardcodes — across the main README, step-00 README,step-00-hello/agent.pydocstring, and notebooks 00/01/02/03/04. (Old labels said "Claude Sonnet 4.5" / "Claude 4.6 Sonnet".)Review Loop Summary
This PR went through 3 pre-PR review iterations (fresh-context reviewer chain,
task-pr-gateMode A) before being opened:eventExpiryDuration+ two-strategy model (semantic facts + userPreference preferences) keeping BOTH namespaces;list_memorieskey fix;deploy.shmodel-id injection; initial README/notebook label cleanup. Validated viapy_compile,bash -n, and botocoreParamValidator(new params PASS, old params REJECTED with the exacteventExpiryDurationerror).ParamValidator). Found & fixed 1 gap: model-label cleanup was incomplete —Sonnet 4.5/4.6labels still in notebooks 00/01/02/04 +step-00-hello/agent.pydocstring while everyagent.pyhardcodesclaude-opus-4-8. Aligned all to Opus 4.Test Plan
All validation done at the schema + SDK-doc level (live AgentCore create blocked in CI — see caveat). Re-run cold in iteration 3:
botocore
ParamValidatoragainst the liveCreateMemoryinput shape:→ Proves
eventExpiryDurationis genuinely required, the branch's new params pass, and the old params fail with the exact error attendees hit. BothsemanticMemoryStrategyanduserPreferenceMemoryStrategyare valid sibling union members.SDK README cross-check (
bedrock_agentcore/memory/integrations/strands/README.md): documents all three built-in strategies (summaryMemoryStrategy,userPreferenceMemoryStrategy,semanticMemoryStrategy) coexisting in onecreate_memory— confirming the two-strategy pattern is canonical.list_memoriespaginator result key ismemories(matches the fix).Namespace consistency:
retrieval_configin all threeagent.py(steps 03/04/05) and notebook 03 references both/users/{actorId}/factsand/users/{actorId}/preferences, exactly matching the two namespacescreate_memory.pycreates.Structural checks:
This fix has NOT been live-validated against AgentCore in this environment. The CI role (
StrandsActionRole) gets a blanketForbiddenExceptionon allbedrock-agentcore-controloperations, so a memory could not be created here. The fix is validated at the schema + SDK-documentation level only.👉 Before the workshop, someone should run
create_memory.pyonce with real AgentCore access to confirm the memory goesACTIVEend-to-end. (An earlier manual e2e run in a different environment did confirm store+recall works once the memory exists.)Remaining Findings (filed as inline review comments)
images/*.svgandcasts/*.svg/.caststill display "Claude 4.6 Sonnet". These are pre-generated/recorded artifacts (not editable source), low priority — flagged for a future regen, not blocking.