Skip to content

refactor(templates): simplify agent-typescript-strands to a barebones agent - #23

Closed
Hweinstock wants to merge 2 commits into
refactorfrom
feat/simplify-strands-ts
Closed

refactor(templates): simplify agent-typescript-strands to a barebones agent#23
Hweinstock wants to merge 2 commits into
refactorfrom
feat/simplify-strands-ts

Conversation

@Hweinstock

Copy link
Copy Markdown
Owner

Spec

Problem: The agent-typescript-strands template has too many parameters on the refactor branch, making it hard to read, extend, and understand.

Definition of done:

  • The template describes a barebones Strands agent.
  • The only rendering left is name, memory, and model provider. All other flags/templates are dropped. Memory still uses our session manager.
  • We still support CodeZip and Container.

Verification (spec): create a CodeZip runtime + add a Container runtime, run dev for each and invoke locally, deploy to AWS and invoke via the CLI/AWS CLI; do both across the memory options; and verify a non-Bedrock (Gemini) provider works. This is the TypeScript analog of the merged Python PR aws#2179.

Changes

1. refactor: reduce agent-typescript-strands to a barebones agent — mirrors aws#2179 for TypeScript.

  • Removed the MCP client scaffolding: deleted mcp_client/client.ts, stripped the MCP import/usage from main.ts, dropped @modelcontextprotocol/sdk from package.json.template, updated the manager.test.ts snapshot.
  • The TS resolver in runtime.ts was already minimal — it never carried the gateway/payment/VPC/filesystem context that refactor(templates): simplify strands python agent to barebones agent aws/agentcore-cli#2179 stripped from the Python resolver — so no runtime.ts change was needed. The template now renders only name, memory (+ strategies), and modelProvider (+ identity providers). Memory continues to use the AgentCore MemoryManager session manager.

2. fix: pass the workload identity token to non-Bedrock providers — discovered during the Gemini deploy verification; a pre-existing bug in the non-Bedrock deploy path (not caused by the simplification).

  • Deployed non-Bedrock runtimes previously failed with workloadIdentityToken not provided and no context available. The template relied on withApiKey's implicit getContext() fallback, which is unreliable inside a streamed async generator; and the pinned bedrock-agentcore ~0.3.0 read only the legacy WAT header.
  • Fix: thread context.workloadAccessToken from the handler in main.tsgetOrCreateAgentloadModel(workloadIdentityToken)withApiKey({ providerName, workloadIdentityToken }) (all four provider branches; Bedrock accepts and ignores the param), and bump the SDK pin to ~0.4.3 (reads the current WAT header). Deployed non-Bedrock providers must be invoked with a runtime user id (--user-id), which triggers the runtime to mint & deliver the WAT.

How to test

bun run compile:linux-x64
BIN=./dist/bin/agentcore-linux-x64

# barebones scaffold — CodeZip + Bedrock + longAndShortTerm (default)
$BIN project create --name simpleTsStrands --template agent-typescript-strands
cd simpleTsStrands
# add a Container runtime (memory none) and a Gemini runtime (memory none)
$BIN project add runtime --name tsContainer --template agent-typescript-strands --build Container --memory none
$BIN project add runtime --name tsGemini --template agent-typescript-strands --model-provider gemini --api-key file://<gemini.key> --memory none

# local dev (headless) then invoke each
$BIN project dev --mode headless --no-traces &
for P in <ports>; do curl -s -X POST localhost:$P/invocations \
  -H 'accept: text/event-stream' -H 'content-type: application/json' \
  -H "x-amzn-bedrock-agentcore-runtime-session-id: local-session-000000000000000000000001" \
  -d '{"prompt":"Say hello in exactly 3 words"}'; done

# deploy + invoke on AWS (Gemini needs --user-id to receive a workload token)
$BIN project deploy
$BIN project invoke runtime --name agent_typescript_strands --accept text/event-stream --payload '{"prompt":"hi"}'
$BIN project invoke runtime --name tsContainer          --accept text/event-stream --payload '{"prompt":"hi"}'
$BIN project invoke runtime --name tsGemini --user-id demo-user --accept text/event-stream --payload '{"prompt":"hi"}'

Verification evidence (dev account, us-east-1)

Barebones scaffold — generated source is just main.ts, memory/memory.ts, model/load.ts, package.json, tsconfig.json (+ README/.gitignore); no mcp_client/, no @modelcontextprotocol/sdk.

Memory options (TS): none and longAndShortTerm scaffold, deploy, and invoke. shortTerm is rejected with a clear, pre-existing validation error (the TS SDK's createAgentCoreMemoryStores requires ≥1 long-term namespace):

$ agentcore project add runtime --name tsShort --template agent-typescript-strands --memory shortTerm
Error: the agent-typescript-strands template does not support short-term-only memory; add long-term strategies or use --memory none

Local dev (final template, all three invokable):

port 8087 (Gemini/none):            "Hello there" "! Hi."
port 8088 (Bedrock CodeZip/L&S):    "Hello to" " you!"
port 8089 (Bedrock Container/none): "Hello to" " you!"

AWS deploy: stack AgentCore-simpleTsStrands-defaultCREATE_COMPLETE (3 runtimes + AgentCore Memory + Gemini credential provider).

Deployed invoke (all HTTP 200):

codezip/Bedrock  (agentcore invoke):  "Hi there" "!"      status=200
codezip/Bedrock  (raw aws bedrock-agentcore invoke-agent-runtime):  "Hi there!"  statusCode 200
container/Bedrock:                     "Hi" " there!"     status=200
codezip/Gemini   (--user-id):          "Hi" " there!"     status=200

Notes

  • Kept the change un-generalized per the spec: the TS template mirrors the Python one rather than unifying them.
  • The pre-commit hook mis-fires on assets-only commits (oxlint --fix → "No files found to lint" because template/snapshot paths are oxlint-ignored); committed with --no-verify after running typecheck / lint:check / format:check / full bun test (2824 pass) on the whole tree. CI re-runs them.

@Hweinstock Hweinstock closed this Sep 3, 2026
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