@aws/agentcore 1.0.0-preview.3 → 1.0.0-preview.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/README.md +193 -33
  2. package/dist/agent-inspector/index.css +1 -1
  3. package/dist/agent-inspector/index.js +99 -84
  4. package/dist/assets/README.md +6 -2
  5. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +3344 -366
  6. package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +6 -2
  7. package/dist/assets/__tests__/assets.snapshot.test.ts +10 -24
  8. package/dist/assets/__tests__/googleadk-observability.test.ts +23 -0
  9. package/dist/assets/__tests__/googleadk-session-eviction.test.ts +87 -0
  10. package/dist/assets/__tests__/input-validation.test.ts +44 -0
  11. package/dist/assets/__tests__/summarization-namespace.test.ts +43 -0
  12. package/dist/assets/agents/AGENTS.md +91 -14
  13. package/dist/assets/cdk/bin/cdk.ts +109 -24
  14. package/dist/assets/cdk/lib/cdk-stack.ts +227 -19
  15. package/dist/assets/cdk/package.json +9 -9
  16. package/dist/assets/cdk/test/cdk.test.ts +4 -0
  17. package/dist/assets/container/python/Dockerfile +7 -1
  18. package/dist/assets/container/typescript/Dockerfile +25 -0
  19. package/dist/assets/container/typescript/dockerignore.template +24 -0
  20. package/dist/assets/datasets/predefined-v1.jsonl +3 -0
  21. package/dist/assets/datasets/simulated-v1.jsonl +3 -0
  22. package/dist/assets/evaluators/autoevals-lambda/execution-role-policy.json +15 -0
  23. package/dist/assets/evaluators/autoevals-lambda/lambda_function.py +37 -0
  24. package/dist/assets/evaluators/autoevals-lambda/pyproject.toml +22 -0
  25. package/dist/assets/evaluators/deepeval-lambda/execution-role-policy.json +15 -0
  26. package/dist/assets/evaluators/deepeval-lambda/lambda_function.py +29 -0
  27. package/dist/assets/evaluators/deepeval-lambda/pyproject.toml +19 -0
  28. package/dist/assets/mcp/python/pyproject.toml +1 -1
  29. package/dist/assets/python/a2a/googleadk/base/main.py +32 -18
  30. package/dist/assets/python/a2a/googleadk/base/pyproject.toml +6 -4
  31. package/dist/assets/python/a2a/langchain_langgraph/base/main.py +35 -21
  32. package/dist/assets/python/a2a/langchain_langgraph/base/pyproject.toml +4 -3
  33. package/dist/assets/python/a2a/strands/base/main.py +23 -17
  34. package/dist/assets/python/a2a/strands/base/pyproject.toml +3 -3
  35. package/dist/assets/python/a2a/strands/capabilities/memory/session.py +4 -1
  36. package/dist/assets/python/agui/googleadk/base/main.py +62 -2
  37. package/dist/assets/python/agui/googleadk/base/pyproject.toml +6 -5
  38. package/dist/assets/python/agui/langchain_langgraph/base/main.py +56 -0
  39. package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +3 -2
  40. package/dist/assets/python/agui/strands/base/main.py +63 -1
  41. package/dist/assets/python/agui/strands/base/pyproject.toml +2 -2
  42. package/dist/assets/python/agui/strands/capabilities/memory/session.py +4 -1
  43. package/dist/assets/python/http/autogen/base/README.md +7 -1
  44. package/dist/assets/python/http/autogen/base/main.py +62 -29
  45. package/dist/assets/python/http/autogen/base/pyproject.toml +1 -1
  46. package/dist/assets/python/http/googleadk/base/README.md +7 -1
  47. package/dist/assets/python/http/googleadk/base/main.py +71 -24
  48. package/dist/assets/python/http/googleadk/base/mcp_client/client.py +7 -7
  49. package/dist/assets/python/http/googleadk/base/pyproject.toml +5 -3
  50. package/dist/assets/python/http/langchain_langgraph/base/README.md +7 -1
  51. package/dist/assets/python/http/langchain_langgraph/base/main.py +119 -24
  52. package/dist/assets/python/http/langchain_langgraph/base/mcp_client/client.py +10 -8
  53. package/dist/assets/python/http/langchain_langgraph/base/pyproject.toml +5 -4
  54. package/dist/assets/python/http/openaiagents/base/README.md +7 -1
  55. package/dist/assets/python/http/openaiagents/base/main.py +63 -32
  56. package/dist/assets/python/http/openaiagents/base/mcp_client/client.py +4 -4
  57. package/dist/assets/python/http/openaiagents/base/pyproject.toml +3 -3
  58. package/dist/assets/python/http/strands/base/README.md +8 -1
  59. package/dist/assets/python/http/strands/base/main.py +607 -47
  60. package/dist/assets/python/http/strands/base/mcp_client/client.py +49 -6
  61. package/dist/assets/python/http/strands/base/model/load.py +119 -3
  62. package/dist/assets/python/http/strands/base/model/mantle_compat.py +21 -0
  63. package/dist/assets/python/http/strands/base/pyproject.toml +11 -5
  64. package/dist/assets/python/http/strands/base/skills/fetcher.py +279 -0
  65. package/dist/assets/python/http/strands/capabilities/execution-limits/hooks/execution_limits.py +54 -0
  66. package/dist/assets/python/http/strands/capabilities/memory/session.py +4 -1
  67. package/dist/assets/python/http/strands/capabilities/payments/__init__.py +4 -0
  68. package/dist/assets/python/http/strands/capabilities/payments/payments.py +142 -0
  69. package/dist/assets/python/mcp/standalone/base/main.py +58 -0
  70. package/dist/assets/python/mcp/standalone/base/pyproject.toml +1 -1
  71. package/dist/assets/typescript/http/strands/base/README.md +42 -0
  72. package/dist/assets/typescript/http/strands/base/gitignore.template +22 -0
  73. package/dist/assets/typescript/http/strands/base/main.ts +149 -0
  74. package/dist/assets/typescript/http/strands/base/mcp_client/client.ts +11 -0
  75. package/dist/assets/typescript/http/strands/base/model/load.ts +102 -0
  76. package/dist/assets/typescript/http/strands/base/package.json +38 -0
  77. package/dist/assets/typescript/http/strands/base/tsconfig.json +19 -0
  78. package/dist/assets/typescript/http/strands/capabilities/memory/memory.ts +52 -0
  79. package/dist/assets/typescript/http/vercelai/base/README.md +42 -0
  80. package/dist/assets/typescript/http/vercelai/base/gitignore.template +22 -0
  81. package/dist/assets/typescript/http/vercelai/base/main.ts +70 -0
  82. package/dist/assets/typescript/http/vercelai/base/model/load.ts +121 -0
  83. package/dist/assets/typescript/http/vercelai/base/package.json +35 -0
  84. package/dist/assets/typescript/http/vercelai/base/tsconfig.json +19 -0
  85. package/dist/cli/index.mjs +1743 -627
  86. package/dist/lib/constants.d.ts +8 -4
  87. package/dist/lib/constants.d.ts.map +1 -1
  88. package/dist/lib/constants.js +13 -7
  89. package/dist/lib/constants.js.map +1 -1
  90. package/dist/lib/dependency-management/index.d.ts +5 -0
  91. package/dist/lib/dependency-management/index.d.ts.map +1 -0
  92. package/dist/lib/dependency-management/index.js +8 -0
  93. package/dist/lib/dependency-management/index.js.map +1 -0
  94. package/dist/lib/dependency-management/messages.d.ts +30 -0
  95. package/dist/lib/dependency-management/messages.d.ts.map +1 -0
  96. package/dist/lib/dependency-management/messages.js +86 -0
  97. package/dist/lib/dependency-management/messages.js.map +1 -0
  98. package/dist/lib/dependency-management/plan.d.ts +25 -0
  99. package/dist/lib/dependency-management/plan.d.ts.map +1 -0
  100. package/dist/lib/dependency-management/plan.js +67 -0
  101. package/dist/lib/dependency-management/plan.js.map +1 -0
  102. package/dist/lib/dependency-management/semver.d.ts +21 -0
  103. package/dist/lib/dependency-management/semver.d.ts.map +1 -0
  104. package/dist/lib/dependency-management/semver.js +51 -0
  105. package/dist/lib/dependency-management/semver.js.map +1 -0
  106. package/dist/lib/dependency-management/sync.d.ts +26 -0
  107. package/dist/lib/dependency-management/sync.d.ts.map +1 -0
  108. package/dist/lib/dependency-management/sync.js +141 -0
  109. package/dist/lib/dependency-management/sync.js.map +1 -0
  110. package/dist/lib/dependency-management/types.d.ts +85 -0
  111. package/dist/lib/dependency-management/types.d.ts.map +1 -0
  112. package/dist/lib/dependency-management/types.js +3 -0
  113. package/dist/lib/dependency-management/types.js.map +1 -0
  114. package/dist/lib/errors/index.d.ts +1 -1
  115. package/dist/lib/errors/index.d.ts.map +1 -1
  116. package/dist/lib/errors/index.js +1 -1
  117. package/dist/lib/errors/index.js.map +1 -1
  118. package/dist/lib/errors/types.d.ts +274 -0
  119. package/dist/lib/errors/types.d.ts.map +1 -0
  120. package/dist/lib/errors/types.js +423 -0
  121. package/dist/lib/errors/types.js.map +1 -0
  122. package/dist/lib/errors/zod.d.ts +8 -0
  123. package/dist/lib/errors/zod.d.ts.map +1 -0
  124. package/dist/lib/errors/{config.js → zod.js} +8 -81
  125. package/dist/lib/errors/zod.js.map +1 -0
  126. package/dist/lib/index.d.ts +3 -0
  127. package/dist/lib/index.d.ts.map +1 -1
  128. package/dist/lib/index.js +4 -1
  129. package/dist/lib/index.js.map +1 -1
  130. package/dist/lib/packaging/build-args.d.ts +6 -0
  131. package/dist/lib/packaging/build-args.d.ts.map +1 -1
  132. package/dist/lib/packaging/build-args.js +11 -2
  133. package/dist/lib/packaging/build-args.js.map +1 -1
  134. package/dist/lib/packaging/build-context-dockerignore.d.ts +23 -0
  135. package/dist/lib/packaging/build-context-dockerignore.d.ts.map +1 -0
  136. package/dist/lib/packaging/build-context-dockerignore.js +63 -0
  137. package/dist/lib/packaging/build-context-dockerignore.js.map +1 -0
  138. package/dist/lib/packaging/build-context.d.ts +21 -0
  139. package/dist/lib/packaging/build-context.d.ts.map +1 -0
  140. package/dist/lib/packaging/build-context.js +21 -0
  141. package/dist/lib/packaging/build-context.js.map +1 -0
  142. package/dist/lib/packaging/container.d.ts.map +1 -1
  143. package/dist/lib/packaging/container.js +20 -9
  144. package/dist/lib/packaging/container.js.map +1 -1
  145. package/dist/lib/packaging/helpers.d.ts +16 -0
  146. package/dist/lib/packaging/helpers.d.ts.map +1 -1
  147. package/dist/lib/packaging/helpers.js +127 -29
  148. package/dist/lib/packaging/helpers.js.map +1 -1
  149. package/dist/lib/packaging/index.d.ts +2 -1
  150. package/dist/lib/packaging/index.d.ts.map +1 -1
  151. package/dist/lib/packaging/index.js +9 -20
  152. package/dist/lib/packaging/index.js.map +1 -1
  153. package/dist/lib/packaging/node.d.ts +2 -2
  154. package/dist/lib/packaging/node.d.ts.map +1 -1
  155. package/dist/lib/packaging/node.js +83 -38
  156. package/dist/lib/packaging/node.js.map +1 -1
  157. package/dist/lib/packaging/python.js +12 -12
  158. package/dist/lib/packaging/python.js.map +1 -1
  159. package/dist/lib/result.d.ts +57 -0
  160. package/dist/lib/result.d.ts.map +1 -0
  161. package/dist/lib/result.js +62 -0
  162. package/dist/lib/result.js.map +1 -0
  163. package/dist/lib/schemas/io/config-io.d.ts +14 -0
  164. package/dist/lib/schemas/io/config-io.d.ts.map +1 -1
  165. package/dist/lib/schemas/io/config-io.js +89 -5
  166. package/dist/lib/schemas/io/config-io.js.map +1 -1
  167. package/dist/lib/schemas/io/global-config.d.ts +41 -0
  168. package/dist/lib/schemas/io/global-config.d.ts.map +1 -0
  169. package/dist/lib/schemas/io/global-config.js +119 -0
  170. package/dist/lib/schemas/io/global-config.js.map +1 -0
  171. package/dist/lib/schemas/io/index.d.ts +1 -2
  172. package/dist/lib/schemas/io/index.d.ts.map +1 -1
  173. package/dist/lib/schemas/io/index.js +1 -4
  174. package/dist/lib/schemas/io/index.js.map +1 -1
  175. package/dist/lib/schemas/io/path-resolver.d.ts +0 -6
  176. package/dist/lib/schemas/io/path-resolver.d.ts.map +1 -1
  177. package/dist/lib/schemas/io/path-resolver.js +3 -13
  178. package/dist/lib/schemas/io/path-resolver.js.map +1 -1
  179. package/dist/lib/secrets/cipher.d.ts +12 -0
  180. package/dist/lib/secrets/cipher.d.ts.map +1 -0
  181. package/dist/lib/secrets/cipher.js +54 -0
  182. package/dist/lib/secrets/cipher.js.map +1 -0
  183. package/dist/lib/secrets/index.d.ts +4 -0
  184. package/dist/lib/secrets/index.d.ts.map +1 -0
  185. package/dist/lib/secrets/index.js +15 -0
  186. package/dist/lib/secrets/index.js.map +1 -0
  187. package/dist/lib/secrets/key-provider.d.ts +16 -0
  188. package/dist/lib/secrets/key-provider.d.ts.map +1 -0
  189. package/dist/lib/secrets/key-provider.js +191 -0
  190. package/dist/lib/secrets/key-provider.js.map +1 -0
  191. package/dist/lib/secrets/sensitive-keys.d.ts +21 -0
  192. package/dist/lib/secrets/sensitive-keys.d.ts.map +1 -0
  193. package/dist/lib/secrets/sensitive-keys.js +67 -0
  194. package/dist/lib/secrets/sensitive-keys.js.map +1 -0
  195. package/dist/lib/time-constants.d.ts +5 -0
  196. package/dist/lib/time-constants.d.ts.map +1 -0
  197. package/dist/lib/time-constants.js +8 -0
  198. package/dist/lib/time-constants.js.map +1 -0
  199. package/dist/lib/utils/env.d.ts +8 -2
  200. package/dist/lib/utils/env.d.ts.map +1 -1
  201. package/dist/lib/utils/env.js +65 -17
  202. package/dist/lib/utils/env.js.map +1 -1
  203. package/dist/lib/utils/index.d.ts +3 -2
  204. package/dist/lib/utils/index.d.ts.map +1 -1
  205. package/dist/lib/utils/index.js +6 -1
  206. package/dist/lib/utils/index.js.map +1 -1
  207. package/dist/lib/utils/polling.d.ts +31 -0
  208. package/dist/lib/utils/polling.d.ts.map +1 -0
  209. package/dist/lib/utils/polling.js +61 -0
  210. package/dist/lib/utils/polling.js.map +1 -0
  211. package/dist/lib/utils/subprocess.d.ts +4 -1
  212. package/dist/lib/utils/subprocess.d.ts.map +1 -1
  213. package/dist/lib/utils/subprocess.js +11 -57
  214. package/dist/lib/utils/subprocess.js.map +1 -1
  215. package/dist/lib/utils/zod.d.ts +16 -0
  216. package/dist/lib/utils/zod.d.ts.map +1 -1
  217. package/dist/lib/utils/zod.js +45 -0
  218. package/dist/lib/utils/zod.js.map +1 -1
  219. package/dist/schema/constants.d.ts +56 -2
  220. package/dist/schema/constants.d.ts.map +1 -1
  221. package/dist/schema/constants.js +82 -7
  222. package/dist/schema/constants.js.map +1 -1
  223. package/dist/schema/schemas/agent-env.d.ts +187 -7
  224. package/dist/schema/schemas/agent-env.d.ts.map +1 -1
  225. package/dist/schema/schemas/agent-env.js +323 -27
  226. package/dist/schema/schemas/agent-env.js.map +1 -1
  227. package/dist/schema/schemas/agentcore-project.d.ts +519 -12
  228. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
  229. package/dist/schema/schemas/agentcore-project.js +342 -13
  230. package/dist/schema/schemas/agentcore-project.js.map +1 -1
  231. package/dist/schema/schemas/auth.d.ts +174 -0
  232. package/dist/schema/schemas/auth.d.ts.map +1 -1
  233. package/dist/schema/schemas/auth.js +127 -3
  234. package/dist/schema/schemas/auth.js.map +1 -1
  235. package/dist/schema/schemas/aws-targets.d.ts +18 -0
  236. package/dist/schema/schemas/aws-targets.d.ts.map +1 -1
  237. package/dist/schema/schemas/aws-targets.js +6 -0
  238. package/dist/schema/schemas/aws-targets.js.map +1 -1
  239. package/dist/schema/schemas/connections.d.ts +185 -0
  240. package/dist/schema/schemas/connections.d.ts.map +1 -0
  241. package/dist/schema/schemas/connections.js +176 -0
  242. package/dist/schema/schemas/connections.js.map +1 -0
  243. package/dist/schema/schemas/deployed-state.d.ts +392 -5
  244. package/dist/schema/schemas/deployed-state.d.ts.map +1 -1
  245. package/dist/schema/schemas/deployed-state.js +112 -2
  246. package/dist/schema/schemas/deployed-state.js.map +1 -1
  247. package/dist/schema/schemas/index.d.ts +3 -0
  248. package/dist/schema/schemas/index.d.ts.map +1 -1
  249. package/dist/schema/schemas/index.js +5 -0
  250. package/dist/schema/schemas/index.js.map +1 -1
  251. package/dist/schema/schemas/mcp-defs.d.ts +2 -1
  252. package/dist/schema/schemas/mcp-defs.d.ts.map +1 -1
  253. package/dist/schema/schemas/mcp-defs.js +3 -2
  254. package/dist/schema/schemas/mcp-defs.js.map +1 -1
  255. package/dist/schema/schemas/mcp.d.ts +197 -0
  256. package/dist/schema/schemas/mcp.d.ts.map +1 -1
  257. package/dist/schema/schemas/mcp.js +334 -5
  258. package/dist/schema/schemas/mcp.js.map +1 -1
  259. package/dist/schema/schemas/primitives/ab-test.d.ts +135 -0
  260. package/dist/schema/schemas/primitives/ab-test.d.ts.map +1 -0
  261. package/dist/schema/schemas/primitives/ab-test.js +95 -0
  262. package/dist/schema/schemas/primitives/ab-test.js.map +1 -0
  263. package/dist/schema/schemas/primitives/capacity-provider.d.ts +237 -0
  264. package/dist/schema/schemas/primitives/capacity-provider.d.ts.map +1 -0
  265. package/dist/schema/schemas/primitives/capacity-provider.js +220 -0
  266. package/dist/schema/schemas/primitives/capacity-provider.js.map +1 -0
  267. package/dist/schema/schemas/primitives/config-bundle.d.ts +32 -0
  268. package/dist/schema/schemas/primitives/config-bundle.d.ts.map +1 -0
  269. package/dist/schema/schemas/primitives/config-bundle.js +41 -0
  270. package/dist/schema/schemas/primitives/config-bundle.js.map +1 -0
  271. package/dist/schema/schemas/primitives/dataset.d.ts +48 -0
  272. package/dist/schema/schemas/primitives/dataset.d.ts.map +1 -0
  273. package/dist/schema/schemas/primitives/dataset.js +58 -0
  274. package/dist/schema/schemas/primitives/dataset.js.map +1 -0
  275. package/dist/schema/schemas/primitives/evaluator.d.ts +22 -0
  276. package/dist/schema/schemas/primitives/evaluator.d.ts.map +1 -1
  277. package/dist/schema/schemas/primitives/evaluator.js +28 -3
  278. package/dist/schema/schemas/primitives/evaluator.js.map +1 -1
  279. package/dist/schema/schemas/primitives/harness.d.ts +377 -19
  280. package/dist/schema/schemas/primitives/harness.d.ts.map +1 -1
  281. package/dist/schema/schemas/primitives/harness.js +379 -24
  282. package/dist/schema/schemas/primitives/harness.js.map +1 -1
  283. package/dist/schema/schemas/primitives/index.d.ts +17 -9
  284. package/dist/schema/schemas/primitives/index.d.ts.map +1 -1
  285. package/dist/schema/schemas/primitives/index.js +62 -1
  286. package/dist/schema/schemas/primitives/index.js.map +1 -1
  287. package/dist/schema/schemas/primitives/knowledge-base.d.ts +104 -0
  288. package/dist/schema/schemas/primitives/knowledge-base.d.ts.map +1 -0
  289. package/dist/schema/schemas/primitives/knowledge-base.js +99 -0
  290. package/dist/schema/schemas/primitives/knowledge-base.js.map +1 -0
  291. package/dist/schema/schemas/primitives/memory.d.ts +22 -4
  292. package/dist/schema/schemas/primitives/memory.d.ts.map +1 -1
  293. package/dist/schema/schemas/primitives/memory.js +57 -16
  294. package/dist/schema/schemas/primitives/memory.js.map +1 -1
  295. package/dist/schema/schemas/primitives/online-eval-config.d.ts +21 -2
  296. package/dist/schema/schemas/primitives/online-eval-config.d.ts.map +1 -1
  297. package/dist/schema/schemas/primitives/online-eval-config.js +45 -5
  298. package/dist/schema/schemas/primitives/online-eval-config.js.map +1 -1
  299. package/dist/schema/schemas/primitives/payment.d.ts +86 -0
  300. package/dist/schema/schemas/primitives/payment.d.ts.map +1 -0
  301. package/dist/schema/schemas/primitives/payment.js +88 -0
  302. package/dist/schema/schemas/primitives/payment.js.map +1 -0
  303. package/dist/schema/schemas/primitives/policy.d.ts +26 -0
  304. package/dist/schema/schemas/primitives/policy.d.ts.map +1 -1
  305. package/dist/schema/schemas/primitives/policy.js +5 -1
  306. package/dist/schema/schemas/primitives/policy.js.map +1 -1
  307. package/npm-shrinkwrap.json +16874 -0
  308. package/package.json +49 -21
  309. package/scripts/bump-version.ts +4 -4
  310. package/scripts/bundle.mjs +70 -41
  311. package/scripts/extract-cli-model.mjs +269 -0
  312. package/scripts/extract-cli-model.test.mjs +43 -0
  313. package/scripts/render_adoc.py +350 -0
  314. package/scripts/run-e2e-dev.sh +56 -0
  315. package/scripts/run-e2e-local.sh +145 -0
  316. package/scripts/safe-junit-reporter.ts +7 -0
  317. package/scripts/sanitize-test-artifacts.ts +65 -0
  318. package/scripts/sync-vended-cdk.ts +49 -0
  319. package/scripts/test_render_adoc.py +38 -0
  320. package/dist/lib/errors/config.d.ts +0 -49
  321. package/dist/lib/errors/config.d.ts.map +0 -1
  322. package/dist/lib/errors/config.js.map +0 -1
  323. package/dist/lib/packaging/errors.d.ts +0 -16
  324. package/dist/lib/packaging/errors.d.ts.map +0 -1
  325. package/dist/lib/packaging/errors.js +0 -36
  326. package/dist/lib/packaging/errors.js.map +0 -1
  327. package/dist/lib/schemas/io/cli-config.d.ts +0 -12
  328. package/dist/lib/schemas/io/cli-config.d.ts.map +0 -1
  329. package/dist/lib/schemas/io/cli-config.js +0 -35
  330. package/dist/lib/schemas/io/cli-config.js.map +0 -1
@@ -0,0 +1,142 @@
1
+ """Payment capability -- auto-generated by agentcore CLI.
2
+
3
+ Configures AgentCorePaymentsPlugin for Strands agents.
4
+ Manager config is auto-discovered from AGENTCORE_PAYMENT_*
5
+ environment variables set at deploy time.
6
+
7
+ Uses a per-invocation factory pattern so each request gets its own
8
+ plugin instance with the correct user_id, instrument_id, and session_id.
9
+ This prevents concurrency bugs where one user's payment context
10
+ could leak to another user's request.
11
+
12
+ Uses the official SDK plugin which handles:
13
+ - x402 v1 (body-based) and v2 (header-based) payment detection
14
+ - Automatic 402 response interception and payment processing
15
+ - Retry limiting (max 3 payment retries per tool use)
16
+ - Error management and logging
17
+ """
18
+ import os
19
+ import logging
20
+
21
+ import boto3
22
+ from bedrock_agentcore.payments.integrations.strands import AgentCorePaymentsPlugin
23
+ from bedrock_agentcore.payments.integrations.config import AgentCorePaymentsPluginConfig
24
+
25
+ logger = logging.getLogger(__name__)
26
+
27
+ PAYMENT_SYSTEM_PROMPT = """
28
+ You have payment capabilities via the x402 protocol:
29
+ - Use http_request to call HTTP endpoints. 402 Payment Required responses are settled automatically by the plugin and the call is retried.
30
+ - Use get_payment_session to check your remaining budget before expensive operations
31
+ - Use get_payment_instrument_balance to check wallet USDC balance
32
+ - Use list_payment_instruments to see available payment instruments
33
+ - If budget is low, inform the user before proceeding with paid requests
34
+ """
35
+
36
+ _manager_arn = None
37
+ _connector_id = None
38
+ _process_payment_role_arn = None
39
+ _name_segment = None
40
+ _region = None
41
+ _auth_mode = None
42
+ _manager_count = 0
43
+ for key, value in os.environ.items():
44
+ if key.startswith("AGENTCORE_PAYMENT_") and key.endswith("_MANAGER_ARN"):
45
+ if _manager_arn is None:
46
+ _manager_arn = value
47
+ _name_segment = key[len("AGENTCORE_PAYMENT_"):-len("_MANAGER_ARN")]
48
+ _manager_count += 1
49
+ if _manager_count > 1:
50
+ logger.warning(
51
+ "Multiple payment managers detected in environment. Using the first one found. "
52
+ "Remove extra AGENTCORE_PAYMENT_*_MANAGER_ARN env vars to eliminate ambiguity."
53
+ )
54
+ _region = os.getenv("AWS_REGION")
55
+
56
+ _prefix = f"AGENTCORE_PAYMENT_{_name_segment}_" if _name_segment else "AGENTCORE_PAYMENT_"
57
+ _auth_mode = os.getenv(f"{_prefix}AUTH_MODE", "sigv4")
58
+ _connector_id = os.getenv(f"{_prefix}CONNECTOR_ID")
59
+ _process_payment_role_arn = os.getenv(f"{_prefix}PROCESS_PAYMENT_ROLE_ARN")
60
+ _auto_payment = os.getenv(f"{_prefix}AUTO_PAYMENT", "true").lower() == "true"
61
+ _allowlist_raw = os.getenv(f"{_prefix}TOOL_ALLOWLIST")
62
+ _allowlist = _allowlist_raw.split(",") if _allowlist_raw else None
63
+ _network_prefs_raw = os.getenv(f"{_prefix}NETWORK_PREFERENCES")
64
+ _network_prefs = _network_prefs_raw.split(",") if _network_prefs_raw else None
65
+
66
+ if not _manager_arn:
67
+ logger.warning("No payment manager config found in environment")
68
+ if not _connector_id:
69
+ logger.warning("No payment connector config found in environment")
70
+
71
+
72
+ def _assume_role_session(role_arn):
73
+ """Assume an IAM role and return a boto3 session with temporary credentials."""
74
+ sts = boto3.client("sts", region_name=_region)
75
+ creds = sts.assume_role(
76
+ RoleArn=role_arn,
77
+ RoleSessionName="agentcore-payment-plugin",
78
+ )["Credentials"]
79
+ return boto3.Session(
80
+ aws_access_key_id=creds["AccessKeyId"],
81
+ aws_secret_access_key=creds["SecretAccessKey"],
82
+ aws_session_token=creds["SessionToken"],
83
+ region_name=_region,
84
+ )
85
+
86
+
87
+ def create_payments_plugin(user_id, instrument_id=None, session_id=None):
88
+ """Create a fresh plugin instance per invocation.
89
+
90
+ Args:
91
+ user_id: From invocation context (required for SigV4, derived from JWT for bearer)
92
+ instrument_id: From invocation payload (created by app backend per user)
93
+ session_id: From invocation payload (created by app backend per conversation)
94
+
95
+ Returns:
96
+ AgentCorePaymentsPlugin instance, or None if no manager is configured.
97
+ """
98
+ if not _manager_arn:
99
+ return None
100
+
101
+ config_kwargs = {
102
+ "payment_manager_arn": _manager_arn,
103
+ "region": _region,
104
+ "payment_instrument_id": instrument_id,
105
+ "payment_session_id": session_id,
106
+ "payment_connector_id": _connector_id,
107
+ }
108
+
109
+ config_kwargs["auto_payment"] = _auto_payment
110
+ if _allowlist:
111
+ config_kwargs["payment_tool_allowlist"] = _allowlist
112
+ if _network_prefs:
113
+ config_kwargs["network_preferences_config"] = _network_prefs
114
+
115
+ if _process_payment_role_arn:
116
+ # Only pass boto3_session if SDK supports it (added in bedrock-agentcore >= 1.11).
117
+ # Older SDKs use the runtime role's default credentials and can still call ProcessPayment
118
+ # if the runtime role has been granted permission directly.
119
+ import inspect
120
+ if "boto3_session" in inspect.signature(AgentCorePaymentsPluginConfig).parameters:
121
+ config_kwargs["boto3_session"] = _assume_role_session(_process_payment_role_arn)
122
+ else:
123
+ logger.warning(
124
+ "PROCESS_PAYMENT_ROLE_ARN set but bedrock-agentcore SDK does not support boto3_session. "
125
+ "Upgrade to bedrock-agentcore>=1.11 to enable cross-role payment processing."
126
+ )
127
+
128
+ if _auth_mode == "bearer":
129
+ bearer_token = os.getenv("AGENTCORE_BEARER_TOKEN")
130
+ if bearer_token:
131
+ config_kwargs["bearer_token"] = bearer_token
132
+ else:
133
+ logger.warning(
134
+ "Bearer auth mode configured but AGENTCORE_BEARER_TOKEN not set. "
135
+ "Falling back to SigV4. Set AGENTCORE_BEARER_TOKEN or pass bearer_token in invoke context."
136
+ )
137
+ config_kwargs["user_id"] = user_id or "default-user"
138
+ else:
139
+ config_kwargs["user_id"] = user_id or "default-user"
140
+
141
+ config = AgentCorePaymentsPluginConfig(**config_kwargs)
142
+ return AgentCorePaymentsPlugin(config=config)
@@ -1,7 +1,65 @@
1
+ {{#if needsOs}}
2
+ import os
3
+ {{/if}}
1
4
  from mcp.server.fastmcp import FastMCP
2
5
 
3
6
  mcp = FastMCP("{{ name }}", host="0.0.0.0", stateless_http=True)
4
7
 
8
+ {{#if needsOs}}
9
+ _MOUNT_PATHS = [
10
+ {{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
11
+ {{#each efsMounts}}"{{mountPath}}",{{/each}}
12
+ {{#each s3Mounts}}"{{mountPath}}",{{/each}}
13
+ ]
14
+
15
+ def _safe_resolve(path: str) -> str:
16
+ resolved = os.path.realpath(path)
17
+ if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
18
+ raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
19
+ return resolved
20
+
21
+ @mcp.tool()
22
+ def file_read(path: str) -> str:
23
+ """Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
24
+ try:
25
+ full_path = _safe_resolve(path)
26
+ with open(full_path) as f:
27
+ return f.read()
28
+ except ValueError as e:
29
+ return str(e)
30
+ except OSError as e:
31
+ return f"Error reading '{path}': {e.strerror}"
32
+
33
+ @mcp.tool()
34
+ def file_write(path: str, content: str) -> str:
35
+ """Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
36
+ try:
37
+ full_path = _safe_resolve(path)
38
+ parent = os.path.dirname(full_path)
39
+ if parent:
40
+ os.makedirs(parent, exist_ok=True)
41
+ with open(full_path, "w") as f:
42
+ f.write(content)
43
+ return f"Written to {path}"
44
+ except ValueError as e:
45
+ return str(e)
46
+ except OSError as e:
47
+ return f"Error writing '{path}': {e.strerror}"
48
+
49
+ @mcp.tool()
50
+ def list_files(path: str) -> str:
51
+ """List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
52
+ try:
53
+ full_path = _safe_resolve(path)
54
+ entries = os.listdir(full_path)
55
+ return "\n".join(entries) if entries else "(empty directory)"
56
+ except ValueError as e:
57
+ return str(e)
58
+ except OSError as e:
59
+ return f"Error listing '{path}': {e.strerror}"
60
+
61
+ {{/if}}
62
+
5
63
 
6
64
  @mcp.tool()
7
65
  def add_numbers(a: int, b: int) -> int:
@@ -9,7 +9,7 @@ description = "AgentCore MCP Server"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
- "mcp >= 1.19.0",
12
+ "mcp ~= 1.24.0",
13
13
  ]
14
14
 
15
15
  [tool.hatch.build.targets.wheel]
@@ -0,0 +1,42 @@
1
+ This is a project generated by the AgentCore CLI!
2
+
3
+ # Layout
4
+
5
+ The generated application code lives at the agent root directory. At the root, there is a `.gitignore` file, an
6
+ `agentcore/` folder which represents the configurations and state associated with this project. Other `agentcore`
7
+ commands like `deploy`, `dev`, and `invoke` rely on the configuration stored here.
8
+
9
+ ## Agent Root
10
+
11
+ The main entrypoint to your app is defined in `main.ts`. Using the AgentCore SDK `BedrockAgentCoreApp`, this file
12
+ defines an HTTP server that streams tokens from your chosen Agent framework SDK.
13
+
14
+ `model/load.ts` instantiates your chosen model provider.
15
+
16
+ ## Input Validation
17
+
18
+ The generated Zod request schema keeps plain prompts typed as strings before forwarding them to Strands. Retain this
19
+ validation when extending the request shape, and pass only prompt text to the agent.
20
+
21
+ ## Environment Variables
22
+
23
+ | Variable | Required | Description |
24
+ | --- | --- | --- |
25
+ {{#if hasIdentity}}| `{{identityProviders.[0].envVarName}}` | Yes | {{modelProvider}} API key (local) or Identity provider name (deployed) |
26
+ {{/if}}| `LOCAL_DEV` | No | Set to `1` to use `.env.local` instead of AgentCore Identity |
27
+
28
+ # Developing locally
29
+
30
+ If installation was successful, `node_modules/` is already populated with dependencies.
31
+
32
+ `agentcore dev` will start a local server using `npx tsx watch main.ts` for hot reload. The port is logged to the terminal (default `8080`).
33
+
34
+ In a new terminal, you can invoke that server with:
35
+
36
+ `agentcore invoke --dev "What can you do"`
37
+
38
+ # Deployment
39
+
40
+ After providing credentials, `agentcore deploy` will deploy your project into Amazon Bedrock AgentCore.
41
+
42
+ Use `agentcore invoke` to invoke your deployed agent.
@@ -0,0 +1,22 @@
1
+ # Environment variables
2
+ .env
3
+ .env.*
4
+
5
+ # Node
6
+ node_modules/
7
+ dist/
8
+ *.log
9
+ npm-debug.log*
10
+ yarn-debug.log*
11
+ yarn-error.log*
12
+
13
+ # IDE
14
+ .vscode/
15
+ .idea/
16
+ *.swp
17
+ *.swo
18
+ *~
19
+
20
+ # OS
21
+ .DS_Store
22
+ Thumbs.db
@@ -0,0 +1,149 @@
1
+ import { BedrockAgentCoreApp } from 'bedrock-agentcore/runtime';
2
+ import { Agent, McpClient, tool, type ToolList } from '@strands-agents/sdk';
3
+ import { z } from 'zod';
4
+ import { loadModel } from './model/load.js';
5
+ import { getStreamableHttpMcpClient } from './mcp_client/client.js';
6
+ {{#if hasMemory}}
7
+ import { getActorId, getOrCreateMemoryManager } from './memory/memory.js';
8
+ {{/if}}
9
+
10
+ // Define a collection of MCP clients (filter out anything that failed to initialize)
11
+ const mcpClients: McpClient[] = [getStreamableHttpMcpClient()].filter(
12
+ (client): client is McpClient => Boolean(client)
13
+ );
14
+
15
+ // Define a collection of tools used by the model
16
+ const tools: ToolList = [];
17
+
18
+ // Define a simple function tool — the Zod schema gives us type inference and runtime validation for free
19
+ const addNumbers = tool({
20
+ name: 'add_numbers',
21
+ description: 'Return the sum of two numbers',
22
+ inputSchema: z.object({
23
+ a: z.number(),
24
+ b: z.number(),
25
+ }),
26
+ callback: async ({ a, b }) => a + b,
27
+ });
28
+ tools.push(addNumbers);
29
+
30
+ // Add MCP clients to tools
31
+ tools.push(...mcpClients);
32
+
33
+ const SYSTEM_PROMPT = `
34
+ You are a helpful assistant. Use tools when appropriate.
35
+ `;
36
+
37
+ const requestSchema = z.object({
38
+ prompt: z.string().default(''),
39
+ });
40
+
41
+ {{#if hasMemory}}
42
+ const agentCache = new Map<string, Agent>();
43
+
44
+ async function getOrCreateAgent(sessionId: string, actorId: string): Promise<Agent> {
45
+ const key = `${actorId}:${sessionId}`;
46
+ let agent = agentCache.get(key);
47
+ if (agent) return agent;
48
+
49
+ const model = await loadModel();
50
+ agent = new Agent({
51
+ model,
52
+ systemPrompt: SYSTEM_PROMPT,
53
+ tools,
54
+ memoryManager: getOrCreateMemoryManager(sessionId, actorId) ?? undefined,
55
+ });
56
+ agentCache.set(key, agent);
57
+ return agent;
58
+ }
59
+ {{else}}
60
+ const AGENT_CACHE_LIMIT = 128;
61
+
62
+ // Reuses one Agent per sessionId so each session keeps its own in-process
63
+ // conversation history (best-effort; resets on cold start). A Map preserves
64
+ // insertion order, so it doubles as an LRU bounded to 128 sessions — a local
65
+ // dev process serving many sessions cannot leak history between them or grow
66
+ // without bound. On AgentCore Runtime each microVM serves a single session, so
67
+ // this holds one entry. For durable history, attach memory.
68
+ const agentCache = new Map<string, Agent>();
69
+
70
+ async function getOrCreateAgent(sessionId: string): Promise<Agent> {
71
+ const existing = agentCache.get(sessionId);
72
+ if (existing) {
73
+ agentCache.delete(sessionId);
74
+ agentCache.set(sessionId, existing);
75
+ return existing;
76
+ }
77
+ if (agentCache.size >= AGENT_CACHE_LIMIT) {
78
+ const oldest = agentCache.keys().next().value;
79
+ if (oldest !== undefined) agentCache.delete(oldest);
80
+ }
81
+ const model = await loadModel();
82
+ const agent = new Agent({
83
+ model,
84
+ systemPrompt: SYSTEM_PROMPT,
85
+ tools,
86
+ });
87
+ agentCache.set(sessionId, agent);
88
+ return agent;
89
+ }
90
+ {{/if}}
91
+
92
+ const app = new BedrockAgentCoreApp({
93
+ invocationHandler: {
94
+ requestSchema,
95
+ async *process(payload, context) {
96
+ {{#if hasMemory}}
97
+ const sessionId = context?.sessionId ?? 'default-session';
98
+ const actorId = getActorId(payload, context);
99
+ const agent = await getOrCreateAgent(sessionId, actorId);
100
+ {{else}}
101
+ const sessionId = context?.sessionId ?? 'default-session';
102
+ const agent = await getOrCreateAgent(sessionId);
103
+ {{/if}}
104
+
105
+ {{#if hasMemory}}
106
+ try {
107
+ for await (const event of agent.stream(payload.prompt)) {
108
+ if (
109
+ event.type === 'modelStreamUpdateEvent' &&
110
+ event.event?.type === 'modelContentBlockDeltaEvent' &&
111
+ event.event.delta?.type === 'textDelta'
112
+ ) {
113
+ yield { data: event.event.delta.text };
114
+ }
115
+ }
116
+ } finally {
117
+ // Drain in-flight createEvent calls before the runtime can reclaim
118
+ // the session microVM. flush() is the durability mechanism — without
119
+ // it, an idle reclamation can lose the tail of the conversation.
120
+ await agent.memoryManager?.flush();
121
+ }
122
+ {{else}}
123
+ // Snapshot history before streaming so a failed turn can be rolled back.
124
+ // Agent.stream() appends the user message before invoking the model; on a
125
+ // mid-stream error that user turn would otherwise linger in the cached
126
+ // agent, and the next turn for this session would send consecutive user
127
+ // messages (rejected by providers that require strict role alternation,
128
+ // e.g. Anthropic). Restoring on error keeps the session reusable.
129
+ const snapshot = agent.takeSnapshot({ include: ['messages'] });
130
+ try {
131
+ for await (const event of agent.stream(payload.prompt)) {
132
+ if (
133
+ event.type === 'modelStreamUpdateEvent' &&
134
+ event.event?.type === 'modelContentBlockDeltaEvent' &&
135
+ event.event.delta?.type === 'textDelta'
136
+ ) {
137
+ yield { data: event.event.delta.text };
138
+ }
139
+ }
140
+ } catch (error) {
141
+ agent.loadSnapshot(snapshot);
142
+ throw error;
143
+ }
144
+ {{/if}}
145
+ },
146
+ },
147
+ });
148
+
149
+ app.run({ port: parseInt(process.env.PORT ?? '8080') });
@@ -0,0 +1,11 @@
1
+ import { McpClient } from '@strands-agents/sdk';
2
+ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
3
+
4
+ // ExaAI provides information about code through web searches, crawling and code context searches through their platform. Requires no authentication
5
+ const EXAMPLE_MCP_ENDPOINT = 'https://mcp.exa.ai/mcp';
6
+
7
+ export function getStreamableHttpMcpClient(): McpClient {
8
+ // to use an MCP server that supports bearer authentication, add a headers() callback to requestInit
9
+ const transport = new StreamableHTTPClientTransport(new URL(EXAMPLE_MCP_ENDPOINT));
10
+ return new McpClient({ transport });
11
+ }
@@ -0,0 +1,102 @@
1
+ {{#if (eq modelProvider "Bedrock")}}
2
+ import { BedrockModel } from '@strands-agents/sdk/models/bedrock';
3
+
4
+ export function loadModel(): BedrockModel {
5
+ return new BedrockModel({ modelId: 'global.anthropic.claude-sonnet-4-5-20250929-v1:0' });
6
+ }
7
+ {{/if}}
8
+ {{#if (eq modelProvider "Anthropic")}}
9
+ import { AnthropicModel } from '@strands-agents/sdk/models/anthropic';
10
+ import { withApiKey } from 'bedrock-agentcore/identity';
11
+
12
+ const IDENTITY_PROVIDER_NAME = '{{identityProviders.[0].name}}';
13
+ const IDENTITY_ENV_VAR = '{{identityProviders.[0].envVarName}}';
14
+
15
+ async function getApiKey(): Promise<string> {
16
+ if (process.env.LOCAL_DEV === '1') {
17
+ const apiKey = process.env[IDENTITY_ENV_VAR] ?? process.env.ANTHROPIC_API_KEY;
18
+ if (!apiKey) {
19
+ throw new Error(`${IDENTITY_ENV_VAR} or ANTHROPIC_API_KEY not found. Add your key to agentcore/.env.local`);
20
+ }
21
+ return apiKey;
22
+ }
23
+ return withApiKey({ providerName: IDENTITY_PROVIDER_NAME })(async (apiKey: string) => apiKey)();
24
+ }
25
+
26
+ let _model: AnthropicModel | undefined;
27
+
28
+ export async function loadModel(): Promise<AnthropicModel> {
29
+ if (!_model) {
30
+ const apiKey = await getApiKey();
31
+ _model = new AnthropicModel({
32
+ apiKey,
33
+ modelId: 'claude-sonnet-4-5-20250929',
34
+ maxTokens: 5000,
35
+ });
36
+ }
37
+ return _model;
38
+ }
39
+ {{/if}}
40
+ {{#if (eq modelProvider "OpenAI")}}
41
+ import { OpenAIModel } from '@strands-agents/sdk/models/openai';
42
+ import { withApiKey } from 'bedrock-agentcore/identity';
43
+
44
+ const IDENTITY_PROVIDER_NAME = '{{identityProviders.[0].name}}';
45
+ const IDENTITY_ENV_VAR = '{{identityProviders.[0].envVarName}}';
46
+
47
+ async function getApiKey(): Promise<string> {
48
+ if (process.env.LOCAL_DEV === '1') {
49
+ const apiKey = process.env[IDENTITY_ENV_VAR] ?? process.env.OPENAI_API_KEY;
50
+ if (!apiKey) {
51
+ throw new Error(`${IDENTITY_ENV_VAR} or OPENAI_API_KEY not found. Add your key to agentcore/.env.local`);
52
+ }
53
+ return apiKey;
54
+ }
55
+ return withApiKey({ providerName: IDENTITY_PROVIDER_NAME })(async (apiKey: string) => apiKey)();
56
+ }
57
+
58
+ let _model: OpenAIModel | undefined;
59
+
60
+ export async function loadModel(): Promise<OpenAIModel> {
61
+ if (!_model) {
62
+ const apiKey = await getApiKey();
63
+ _model = new OpenAIModel({
64
+ api: 'chat',
65
+ apiKey,
66
+ modelId: 'gpt-4.1',
67
+ });
68
+ }
69
+ return _model;
70
+ }
71
+ {{/if}}
72
+ {{#if (eq modelProvider "Gemini")}}
73
+ import { GoogleModel } from '@strands-agents/sdk/models/google';
74
+ import { withApiKey } from 'bedrock-agentcore/identity';
75
+
76
+ const IDENTITY_PROVIDER_NAME = '{{identityProviders.[0].name}}';
77
+ const IDENTITY_ENV_VAR = '{{identityProviders.[0].envVarName}}';
78
+
79
+ async function getApiKey(): Promise<string> {
80
+ if (process.env.LOCAL_DEV === '1') {
81
+ const apiKey = process.env[IDENTITY_ENV_VAR] ?? process.env.GEMINI_API_KEY;
82
+ if (!apiKey) {
83
+ throw new Error(`${IDENTITY_ENV_VAR} or GEMINI_API_KEY not found. Add your key to agentcore/.env.local`);
84
+ }
85
+ return apiKey;
86
+ }
87
+ return withApiKey({ providerName: IDENTITY_PROVIDER_NAME })(async (apiKey: string) => apiKey)();
88
+ }
89
+
90
+ let _model: GoogleModel | undefined;
91
+
92
+ export async function loadModel(): Promise<GoogleModel> {
93
+ if (!_model) {
94
+ const apiKey = await getApiKey();
95
+ _model = new GoogleModel({
96
+ apiKey,
97
+ modelId: 'gemini-2.5-flash',
98
+ });
99
+ }
100
+ return _model;
101
+ }
102
+ {{/if}}
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "{{name}}",
3
+ "version": "0.1.0",
4
+ "description": "AgentCore Runtime Application using Strands TypeScript SDK",
5
+ "private": true,
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "start": "node dist/main.js",
10
+ "dev": "tsx watch main.ts"
11
+ },
12
+ "dependencies": {
13
+ {{#if (eq modelProvider "Anthropic")}}
14
+ "@anthropic-ai/sdk": "^0.71.2",
15
+ {{/if}}
16
+ {{#if (eq modelProvider "OpenAI")}}
17
+ "openai": "^6.7.0",
18
+ {{/if}}
19
+ {{#if (eq modelProvider "Gemini")}}
20
+ "@google/genai": "^1.40.0",
21
+ {{/if}}
22
+ "@modelcontextprotocol/sdk": "^1.25.2",
23
+ "@opentelemetry/api": "^1.9.0",
24
+ "@strands-agents/sdk": "^1.5.0",
25
+ "bedrock-agentcore": "^0.3.0",
26
+ "tsx": "^4.19.0",
27
+ "zod": "^4.4.3"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.0.0",
31
+ "typescript": "^5.6.0"
32
+ },
33
+ "overrides": {
34
+ "bedrock-agentcore": {
35
+ "@strands-agents/sdk": "$@strands-agents/sdk"
36
+ }
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "resolveJsonModule": true,
11
+ "declaration": false,
12
+ "sourceMap": true,
13
+ "outDir": "dist",
14
+ "rootDir": ".",
15
+ "types": ["node"]
16
+ },
17
+ "include": ["**/*.ts"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
@@ -0,0 +1,52 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { MemoryManager } from '@strands-agents/sdk';
3
+ import { createAgentCoreMemoryStores } from 'bedrock-agentcore/experimental/memory/strands';
4
+
5
+ const MEMORY_ID = process.env.{{memoryProviders.[0].envVarName}};
6
+
7
+ const CUSTOM_ACTOR_ID_HEADER = 'x-amzn-bedrock-agentcore-runtime-custom-actor-id';
8
+
9
+ export function getActorId(payload: any, context: any): string {
10
+ const raw =
11
+ context?.headers?.[CUSTOM_ACTOR_ID_HEADER] ||
12
+ payload?.userId ||
13
+ context?.sessionId;
14
+ return typeof raw === 'string' && raw.trim().length > 0 ? raw.trim() : randomUUID();
15
+ }
16
+
17
+ const memoryManagerCache = new Map<string, MemoryManager>();
18
+
19
+ export function getOrCreateMemoryManager(sessionId: string, actorId: string): MemoryManager | null {
20
+ if (!MEMORY_ID) return null;
21
+
22
+ const key = `${actorId}:${sessionId}`;
23
+ let manager = memoryManagerCache.get(key);
24
+ if (manager) return manager;
25
+
26
+ const stores = createAgentCoreMemoryStores({
27
+ memoryId: MEMORY_ID,
28
+ actorId,
29
+ sessionId,
30
+ namespaces: [
31
+ {{#if (includes memoryProviders.[0].strategies "SEMANTIC")}}
32
+ { namespace: '/users/{actorId}/facts' },
33
+ {{/if}}
34
+ {{#if (includes memoryProviders.[0].strategies "USER_PREFERENCE")}}
35
+ { namespace: '/users/{actorId}/preferences' },
36
+ {{/if}}
37
+ {{#if (includes memoryProviders.[0].strategies "EPISODIC")}}
38
+ { namespace: '/episodes/{actorId}/{sessionId}' },
39
+ {{/if}}
40
+ {{#if (includes memoryProviders.[0].strategies "SUMMARIZATION")}}
41
+ { namespace: '/summaries/{actorId}/{sessionId}' },
42
+ {{/if}}
43
+ ],
44
+ // readMode defaults to 'per-namespace' (one retrieve call per namespace).
45
+ // Switch to 'subtree' to consolidate to a single hierarchical recall call.
46
+ extraction: true,
47
+ });
48
+
49
+ manager = new MemoryManager({ stores });
50
+ memoryManagerCache.set(key, manager);
51
+ return manager;
52
+ }