@aws/agentcore 1.0.0-preview.16 → 1.0.0-preview.18

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 (40) hide show
  1. package/README.md +1 -7
  2. package/dist/agent-inspector/index.css +1 -1
  3. package/dist/agent-inspector/index.js +60 -60
  4. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +273 -15
  5. package/dist/assets/cdk/bin/cdk.ts +2 -8
  6. package/dist/assets/python/http/strands/base/main.py +13 -3
  7. package/dist/assets/python/http/strands/base/mcp_client/client.py +4 -1
  8. package/dist/assets/python/http/strands/base/model/load.py +116 -0
  9. package/dist/assets/python/http/strands/base/model/mantle_compat.py +21 -0
  10. package/dist/assets/python/http/strands/base/pyproject.toml +3 -0
  11. package/dist/assets/typescript/http/strands/base/main.ts +48 -0
  12. package/dist/assets/typescript/http/strands/base/package.json +3 -2
  13. package/dist/assets/typescript/http/strands/capabilities/memory/memory.ts +52 -0
  14. package/dist/cli/index.mjs +572 -606
  15. package/dist/schema/constants.d.ts +3 -2
  16. package/dist/schema/constants.d.ts.map +1 -1
  17. package/dist/schema/constants.js +7 -4
  18. package/dist/schema/constants.js.map +1 -1
  19. package/dist/schema/schemas/agent-env.d.ts +43 -0
  20. package/dist/schema/schemas/agent-env.d.ts.map +1 -1
  21. package/dist/schema/schemas/agent-env.js +11 -0
  22. package/dist/schema/schemas/agent-env.js.map +1 -1
  23. package/dist/schema/schemas/agentcore-project.d.ts +43 -0
  24. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
  25. package/dist/schema/schemas/connections.d.ts +185 -0
  26. package/dist/schema/schemas/connections.d.ts.map +1 -0
  27. package/dist/schema/schemas/connections.js +176 -0
  28. package/dist/schema/schemas/connections.js.map +1 -0
  29. package/dist/schema/schemas/index.d.ts +1 -0
  30. package/dist/schema/schemas/index.d.ts.map +1 -1
  31. package/dist/schema/schemas/index.js +1 -0
  32. package/dist/schema/schemas/index.js.map +1 -1
  33. package/dist/schema/schemas/primitives/harness.d.ts +42 -0
  34. package/dist/schema/schemas/primitives/harness.d.ts.map +1 -1
  35. package/dist/schema/schemas/primitives/harness.js +4 -0
  36. package/dist/schema/schemas/primitives/harness.js.map +1 -1
  37. package/npm-shrinkwrap.json +6 -6
  38. package/package.json +2 -3
  39. package/scripts/bundle.mjs +12 -60
  40. package/scripts/run-e2e-local.sh +0 -5
@@ -3,6 +3,9 @@ import { Agent, McpClient, tool, type ToolList } from '@strands-agents/sdk';
3
3
  import { z } from 'zod';
4
4
  import { loadModel } from './model/load.js';
5
5
  import { getStreamableHttpMcpClient } from './mcp_client/client.js';
6
+ {{#if hasMemory}}
7
+ import { getActorId, getOrCreateMemoryManager } from './memory/memory.js';
8
+ {{/if}}
6
9
 
7
10
  // Define a collection of MCP clients (filter out anything that failed to initialize)
8
11
  const mcpClients: McpClient[] = [getStreamableHttpMcpClient()].filter(
@@ -31,6 +34,25 @@ const SYSTEM_PROMPT = `
31
34
  You are a helpful assistant. Use tools when appropriate.
32
35
  `;
33
36
 
37
+ {{#if hasMemory}}
38
+ const agentCache = new Map<string, Agent>();
39
+
40
+ async function getOrCreateAgent(sessionId: string, actorId: string): Promise<Agent> {
41
+ const key = `${actorId}:${sessionId}`;
42
+ let agent = agentCache.get(key);
43
+ if (agent) return agent;
44
+
45
+ const model = await loadModel();
46
+ agent = new Agent({
47
+ model,
48
+ systemPrompt: SYSTEM_PROMPT,
49
+ tools,
50
+ memoryManager: getOrCreateMemoryManager(sessionId, actorId) ?? undefined,
51
+ });
52
+ agentCache.set(key, agent);
53
+ return agent;
54
+ }
55
+ {{else}}
34
56
  let cachedAgent: Agent | null = null;
35
57
 
36
58
  async function getOrCreateAgent(): Promise<Agent> {
@@ -44,12 +66,37 @@ async function getOrCreateAgent(): Promise<Agent> {
44
66
  }
45
67
  return cachedAgent;
46
68
  }
69
+ {{/if}}
47
70
 
48
71
  const app = new BedrockAgentCoreApp({
49
72
  invocationHandler: {
50
73
  async *process(payload: any, context: any) {
74
+ {{#if hasMemory}}
75
+ const sessionId = context?.sessionId ?? 'default-session';
76
+ const actorId = getActorId(payload, context);
77
+ const agent = await getOrCreateAgent(sessionId, actorId);
78
+ {{else}}
51
79
  const agent = await getOrCreateAgent();
80
+ {{/if}}
52
81
 
82
+ {{#if hasMemory}}
83
+ try {
84
+ for await (const event of agent.stream(payload.prompt ?? '')) {
85
+ if (
86
+ event.type === 'modelStreamUpdateEvent' &&
87
+ event.event?.type === 'modelContentBlockDeltaEvent' &&
88
+ event.event.delta?.type === 'textDelta'
89
+ ) {
90
+ yield { data: event.event.delta.text };
91
+ }
92
+ }
93
+ } finally {
94
+ // Drain in-flight createEvent calls before the runtime can reclaim
95
+ // the session microVM. flush() is the durability mechanism — without
96
+ // it, an idle reclamation can lose the tail of the conversation.
97
+ await agent.memoryManager?.flush();
98
+ }
99
+ {{else}}
53
100
  for await (const event of agent.stream(payload.prompt ?? '')) {
54
101
  if (
55
102
  event.type === 'modelStreamUpdateEvent' &&
@@ -59,6 +106,7 @@ const app = new BedrockAgentCoreApp({
59
106
  yield { data: event.event.delta.text };
60
107
  }
61
108
  }
109
+ {{/if}}
62
110
  },
63
111
  },
64
112
  });
@@ -20,8 +20,9 @@
20
20
  "@google/genai": "^1.40.0",
21
21
  {{/if}}
22
22
  "@modelcontextprotocol/sdk": "^1.25.2",
23
- "@strands-agents/sdk": "1.0.0-rc.4",
24
- "bedrock-agentcore": "^0.2.4",
23
+ "@opentelemetry/api": "^1.9.0",
24
+ "@strands-agents/sdk": "^1.5.0",
25
+ "bedrock-agentcore": "^0.3.0",
25
26
  "tsx": "^4.19.0",
26
27
  "zod": "^4.4.3"
27
28
  },
@@ -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
+ }