Skip to content

feat(templates): wire in memory to the runtime templates - #2116

Open
Hweinstock wants to merge 7 commits into
aws:refactorfrom
Hweinstock:memory-in-templates
Open

feat(templates): wire in memory to the runtime templates#2116
Hweinstock wants to merge 7 commits into
aws:refactorfrom
Hweinstock:memory-in-templates

Conversation

@Hweinstock

@Hweinstock Hweinstock commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Dependent on #2099 (ignore this until that is merged)

Problem

Memory is currently hardcoded to none. The old CLI defaulted to a real memory, and allowed none | longAndShort | short options.

Solutions

  • mirror old CLI arguments for memory with the same default.
  • wire that memory through to the template resolver.
  • refactor the fsTreeNode asset resolver to accept transformations and filters for added flexibility.

Testing

created a project with the memory template then deployed, verified the project and my cdk stack included a memory. Also verified the memory code was included in the asset rendering.

 > agentcore project create --name testP --template strands-python
 ...
 > ls testP/app/strands_agent
 README.md  main.py  mcp_client  memory  model  pyproject.toml  skills  uv.lock
 [ shows the memory folder which is conditionally rendered ] 

> cat testP/agentcore/agentcore.json | jq 

{
  "name": "testP",
  "version": 1,
  "managedBy": "CDK",
  "runtimes": [
    {
      "name": "strands_agent",
      "build": "CodeZip",
      "entrypoint": "main.py",
      "codeLocation": "app/strands_agent",
      "runtimeVersion": "PYTHON_3_14",
      "protocol": "HTTP"
    }
  ],
  "memories": [
    {
      "name": "strands_agentMemory",
      "eventExpiryDuration": 30,
      "strategies": [
        {
          "type": "SEMANTIC",
          "namespaceTemplates": [
            "/users/{actorId}/facts"
          ]
        },
        {
          "type": "USER_PREFERENCE",
          "namespaceTemplates": [
            "/users/{actorId}/preferences"
          ]
        },
        {
          "type": "SUMMARIZATION",
          "namespaceTemplates": [
            "/summaries/{actorId}/{sessionId}"
          ]
        },
        {
          "type": "EPISODIC",
          "namespaceTemplates": [
            "/episodes/{actorId}/{sessionId}"
          ],
          "reflectionNamespaceTemplates": [
            "/episodes/{actorId}"
          ]
        }
      ]
    }
  ]
}

[shows the memory config]
 
> agentcore project deploy
...

went to console and invoked it, and verified the memory was created.

  • unit tests!

@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels Aug 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added agentcore-harness-reviewing AgentCore Harness review in progress claude-security-reviewing Claude Code /security-review in progress labels Aug 26, 2026
@codecov-commenter

codecov-commenter commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.24%. Comparing base (059e1a5) to head (3c10f37).

Additional details and impacted files
@@            Coverage Diff            @@
##           refactor    #2116   +/-   ##
=========================================
  Coverage     97.24%   97.24%           
=========================================
  Files           471      472    +1     
  Lines         28911    28978   +67     
=========================================
+ Hits          28114    28181   +67     
  Misses          797      797           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@agentcore-devx-automation agentcore-devx-automation Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentCore Harness Review

Verdict: Looks good

I traced through the refactor and the new strands-http-python template. The extraction into templates/{project,runtime,harness,renderer,types,fsTree}.ts is coherent, the manager's addResource rollback semantics are preserved (mutating projectSpec in place is fine because it isn't written on the error path), the new fromTextFile correctly reads Dockerfile content from disk (so getHarnessTemplateResolver matches the old copyFile behavior, minus the pre-write existence check — the error is still thrown at write time via InputValidationError), and the manifest snapshot confirms memory/ is filtered out when --memory is not set.

Two very minor observations that are not blocking:

  • mergeSpecEntries in src/core/project/templates/project.ts merges runtimes/credentials/memories but ignores harnesses, even though SpecEntries includes it. Currently unreachable since createProjectTree only invokes the runtime resolver, so the omission is harmless — worth fixing if a future template contributes harnesses at project-create time.
  • src/assets/templates/strands-http-python/main.py references a pyJsonStr helper ({{pyJsonStr inputSchema}} and {{pyJsonStr litellmAdditionalParams}}) that isn't registered in HandlebarsTemplateRenderer. Guarded behind inlineFunctionTools / litellmAdditionalParams, both of which are never set in the current runtime.ts context, so it's latent — but it will blow up the day someone flips those flags on.

Neither of these needs to hold up the merge.

@agentcore-devx-automation agentcore-devx-automation Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Aug 26, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 26, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels Aug 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 26, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 26, 2026
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels Aug 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 26, 2026
@Hweinstock
Hweinstock force-pushed the memory-in-templates branch from 1b25e3b to f07f985 Compare August 26, 2026 21:51
@github-actions github-actions Bot removed the size/xl PR size: XL label Aug 26, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@github-actions github-actions Bot added the size/xl PR size: XL label Aug 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added claude-security-reviewing Claude Code /security-review in progress and removed claude-security-reviewing Claude Code /security-review in progress labels Aug 26, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 26, 2026
@Hweinstock
Hweinstock force-pushed the memory-in-templates branch from f07f985 to 9088f13 Compare August 26, 2026 22:25
@github-actions github-actions Bot added size/xl PR size: XL and removed size/xl PR size: XL labels Aug 26, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 26, 2026
@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Aug 27, 2026
@Hweinstock
Hweinstock marked this pull request as ready for review August 27, 2026 19:37

@notgitika notgitika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty straightforward we are mostly just porting over what already exists on main so I don't wanna comment about improvements in the templates themselves that we can bring in later.

LGTM just 2 questions

Comment thread src/handlers/project/shortcuts.ts Outdated

export const MEMORY_SHORTCUTS = {
none: (_runtimeName: string) => undefined,
short: (runtimeName: string): Memory => ({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wanna point out that this renames shortTerm / longAndShortTerm that exist in CLI main, so existing CLI commands fail. was that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good catch, I actually thought this is what was on main, let me swap it to match.

export const MEMORY_SHORTCUTS = {
none: (_runtimeName: string) => undefined,
short: (runtimeName: string): Memory => ({
name: `${runtimeName}Memory`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't fully confirmed this but just wanted to make sure that when we append "Memory" here we are staying under the character limit of the service API, which is 48 chars? can we make sure the runtimeName then stays 42 chars max?

once bitten, twice shy 😊

@Hweinstock Hweinstock Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call! These are the types of edge cases that only someone who has implemented this before would know :)

@github-actions github-actions Bot added size/m PR size: M and removed size/m PR size: M labels Aug 27, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 27, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Aug 27, 2026
@github-actions github-actions Bot added size/l PR size: L and removed size/m PR size: M labels Aug 27, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 27, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

notgitika
notgitika previously approved these changes Aug 28, 2026

@notgitika notgitika left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for addressing comments :)

@github-actions github-actions Bot added size/l PR size: L and removed size/l PR size: L labels Aug 28, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Aug 28, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: the review did not analyze this PR (model took 0 turns). See the run for details; a later push or re-run is needed.

}
{{/if}}

return AgentCoreMemorySessionManager(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now since we said we don't want to make to many changes, and I know you said you would eventually like to improve the template. One thing we should change is to use the new AgentCoreMemoryManager and AgentCoreMemoryStore at some point. We should theoretically be using our own best practices.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, good callout.

f"/episodes/{actor_id}/{session_id}": RetrievalConfig(top_k=5, relevance_score=0.5),
{{/if}}
{{#if (includes memoryStrategies "SUMMARIZATION")}}
f"/summaries/{actor_id}": RetrievalConfig(top_k=3, relevance_score=0.5),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this retrieval namespace is different from the strategy being created. MEMORY_SHORTCUTS configures SUMMARIZATION as /summaries/{actorId}/{sessionId}, but the generated runtime queries /summaries/{actor_id}. That means summaries written under the configured session namespace will not be retrieved.

I think this should probablyt include session_id. I just looked and this mismatch also exists in the old template, but this PR makes that strategy part of the default memory so we may as well just make it right here.

},
{ rootDirName: input.name },
);
return { tree, spec: { runtimes: [buildRuntimeSpec(input)] } };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the custom hello-world path can silently ignore --memory. Selecting --framework none routes here, but even when scaffoldRuntimeInput.memory is set, this return only adds the Runtime and does not generate a memories[] entry in agentcore.json or the memory template files. Do you think we should reject --memory for this path for cleanliness in UX?

modelProvider: flags["model-provider"],
apiKey,
memory: flags["memory"],
memory: MEMORY_SHORTCUTS[flags["memory"] ?? "longAndShortTerm"](runtimeName),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is memory supposed to be becoming the default here? Don't have a problem with it but like it is a breaking change. In the released CLI, omitting --memory does not create a Memory resource, but this defaults to longAndShortTerm and provisions four strategies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was my intention. Since harness is also now defaulting to give customers a memory, I thought we should align and give them a memory by default as well. The runtime experience should be better with a memory attached, so I figure we should give them the best experience by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants