Skip to content

refactor(templates): reduce strands-http-python to a barebones agent - #19

Closed
Hweinstock wants to merge 1 commit into
refactorfrom
feat/simplify-strands-python-template
Closed

refactor(templates): reduce strands-http-python to a barebones agent#19
Hweinstock wants to merge 1 commit into
refactorfrom
feat/simplify-strands-python-template

Conversation

@Hweinstock

@Hweinstock Hweinstock commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

Targets refactor. The base work this depends on has landed on refactor: aws#2170 (template rename + export-harness-python) and #20 (feat/wire-model-providers, non-Bedrock model providers on the scaffold path). This PR rebases directly onto refactor and shows only its own diff.

The base leaves agent-python-strands — the template the scaffold path (agentcore project create / add runtime) renders — rich (~715-line main.py, plus mcp_client/, skills/, model/mantle_compat.py), carrying dozens of flags no scaffold ever sets. The harness-export template was already split out into templates/export-harness-python (by aws#2170).

This PR makes agent-python-strands a barebones Strands agent:

  1. main.py → ~130 lines: a single tool, a per-session_id in-process Agent cache, prompt extraction, and the stream entrypoint. Dropped every export-only flag (tools, execution limits, truncation, gateways, remote MCP, mounts, config bundle, payments, Mantle).
  2. Deleted mcp_client/, skills/, model/mantle_compat.py from the scaffold template (they live only in export-harness-python now).
  3. Multi-provider model rendering is retained and now livemodel/load.py branches on Bedrock/Anthropic/OpenAI/Gemini/LiteLLM, and pyproject.toml pulls provider SDKs via strands-agents[<provider>] extras. With feat(runtime): support Anthropic, OpenAI, and Gemini model providers #20's provider wiring on refactor, the barebones template renders correct clients + AgentCore Identity wiring for non-Bedrock providers.
  4. Trimmed the scaffold render context in runtime.ts to the keys the barebones template uses.

Net: +80 / −1170 lines across 11 files. export harness is untouched (it renders export-harness-python, provided by aws#2170).

No-memory session retention

An agent without memory reuses one Agent per session_id (in-process LRU cache), so successive invokes on the same session keep their conversation history within a live process — the same behavior the previous template had. This is best-effort (the cache resets on cold start / isn't shared across instances); for durable, cross-instance history, add memory (the session manager), preserved here.

Spec

Problem: The strands python template has too many parameters on the refactor branch, causing the template to be difficult to read, extend, and understand.

Definition of Done:

  • the template now describes a barebones strands agent.
  • the only rendering left is name, memory, and model provider. The scaffolded is dead-simple. All other flags and templates are dropped. Memory should still use our session manager.
  • we still support codezip and containers.
  • an agent without memory should still remember previous invokes, when invoked with the same sessionId. That is, we don't create a new agent if one already exists for that session.

Verification: Create a project with a CodeZip runtime, add a Container runtime, run the dev server for each and verify local invocation, deploy to AWS and invoke via the CLI — across all 3 memory options (combined into one project).

Note on the "no-memory context" item: the spec suspected a bug where a no-memory agent lost context on the same sessionId. Investigation showed the previous template already reused one Agent per session in-process, so a warm deployed runtime does remember across same-session invokes (confirmed on AWS). It's only best-effort (resets on cold start / not shared across instances) — not a defect worth a code change. This PR keeps that same session-reuse approach and drops the "bug" framing.

Follow-ups (from review): (a) export harness kept working — the base's export-harness-python template serves it, so this PR only barebones the scaffold template; (b) alternative model providers kept in the template — now wired end-to-end since #20 landed on refactor; (c) export template stays out of scaffolding — it's structurally unreachable (no resolver key or --template enum value maps to it; only export harness renders it); (d) rebased onto refactor; (e) session-reuse matches the previous template (no bug-fix claim).

Verification

Re-run after the aws#2170 rebase, against dev account 440744214761 / us-east-1, using the compiled binary (bun run compile).

Unit tests / build

Scaffold (both build types × all 3 memory options)

One project, 6 runtimes: CodeZip + Container, each with memory = none | shortTerm | longAndShortTerm. All generated Python compiles.

Local dev (agentcore project dev --mode headless)

  • CodeZip, no memory — same session: told "Bob / teal" → asked → "Your name is Bob and your favorite color is teal."
  • Container, no memory"21 + 21? Use your tool.""The result of 21 + 21 is 42."; same-session codeword → "The codeword you gave me is ORANGE."

Deployed on AWS (agentcore project deploy + project invoke runtime)

All 6 runtimes invoked via the AWS InvokeAgentRuntime API; all retained context within a warm session ("Your name is Bob and your favorite fruit is mango.").

Durability contrast (new session id, same --user-id):

  • long-term memory"your favorite fruit is mango" (recalled across sessions via AgentCore Memory)
  • no memory"I truly do not know your favorite fruit… Each conversation I have starts fresh without memory of previous interactions."

How to reproduce

BIN=./dist/bin/agentcore-linux-x64            # from: bun run compile
D=/tmp/demo && rm -rf $D && mkdir -p $D && cd $D

$BIN project create --name demo --template agent-python-strands \
  --build CodeZip --memory none --runtime-name agentNone
cd demo
$BIN project add runtime --framework strands --language Python --build Container \
  --model-provider Bedrock --memory longAndShortTerm --name agentCtrLong

# local dev + invoke (headless binds :8080)
$BIN project dev --mode headless --agent agentNone &
curl -sN -X POST http://127.0.0.1:8080/invocations \
  -H 'Content-Type: application/json' \
  -H 'x-amzn-bedrock-agentcore-runtime-session-id: sess-000000000000000000000000000001' \
  -d '{"prompt":"My name is Bob. Remember it."}'
# invoke again on the SAME session → the warm process remembers (in-process per-session reuse)

# deploy + invoke via AWS
$BIN project deploy
$BIN project invoke runtime --name agentNone --session-id sess-... --payload '{"prompt":"Hello!"}'

Teardown

aws cloudformation delete-stack --stack-name AgentCore-demo-default --region us-east-1

@Hweinstock
Hweinstock changed the base branch from refactor to feat/rename-templates September 2, 2026 21:03
@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch from b287c2d to e366e9f Compare September 2, 2026 21:03
@Hweinstock
Hweinstock force-pushed the feat/rename-templates branch 2 times, most recently from b5d6e88 to 1425fec Compare September 2, 2026 22:10
@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch from e366e9f to 2684bec Compare September 2, 2026 22:40
@Hweinstock
Hweinstock changed the base branch from feat/rename-templates to refactor September 2, 2026 22:45
@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch from 2684bec to 802e17b Compare September 2, 2026 22:45
@Hweinstock
Hweinstock changed the base branch from refactor to feat/wire-model-providers September 2, 2026 23:35
@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch 4 times, most recently from f80c302 to 7e6e86c Compare September 3, 2026 02:59
`model/load.py` instantiates your chosen model provider.
`model/load.py` instantiates the Bedrock model provider.

The agent reuses one Strands `Agent` per `session_id`, so successive invocations that share a session keep their

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

you can remove this block.

Comment thread src/core/project/manager.test.ts Outdated
});
});

test("no scaffold shortcut renders the export-only strands template", async () => {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

delete this test, it should exist in the handlers not here.

@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch from 7e6e86c to d5a248c Compare September 3, 2026 03:17
await expect(run(flags)).rejects.toThrow(pattern);
});

test("scaffolds a strands runtime without the export-only harness template files", async () => {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

this test looks uselsss, remove it.

@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch from d5a248c to 4c321ec Compare September 3, 2026 04:04
return LiteLLMModel(
client_args=client_args,
model_id="{{#if modelId}}{{modelId}}{{else}}bedrock/us.anthropic.claude-sonnet-4-5-20250514-v1:0{{/if}}",
params=params,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

imo templating in params here for litellm is unnecessary complexity. If a customer wants to user liteLLM I think its easier to take this default as the scaffolding and adjust from there rather than passing on command line.

@Hweinstock
Hweinstock changed the base branch from feat/wire-model-providers to refactor September 3, 2026 15:13
@Hweinstock
Hweinstock force-pushed the feat/simplify-strands-python-template branch from 4c321ec to 187fc5d Compare September 3, 2026 15:13
@Hweinstock Hweinstock closed this Sep 3, 2026
@Hweinstock
Hweinstock deleted the feat/simplify-strands-python-template branch September 3, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant