@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.
- package/README.md +1 -7
- package/dist/agent-inspector/index.css +1 -1
- package/dist/agent-inspector/index.js +60 -60
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +273 -15
- package/dist/assets/cdk/bin/cdk.ts +2 -8
- package/dist/assets/python/http/strands/base/main.py +13 -3
- package/dist/assets/python/http/strands/base/mcp_client/client.py +4 -1
- package/dist/assets/python/http/strands/base/model/load.py +116 -0
- package/dist/assets/python/http/strands/base/model/mantle_compat.py +21 -0
- package/dist/assets/python/http/strands/base/pyproject.toml +3 -0
- package/dist/assets/typescript/http/strands/base/main.ts +48 -0
- package/dist/assets/typescript/http/strands/base/package.json +3 -2
- package/dist/assets/typescript/http/strands/capabilities/memory/memory.ts +52 -0
- package/dist/cli/index.mjs +572 -606
- package/dist/schema/constants.d.ts +3 -2
- package/dist/schema/constants.d.ts.map +1 -1
- package/dist/schema/constants.js +7 -4
- package/dist/schema/constants.js.map +1 -1
- package/dist/schema/schemas/agent-env.d.ts +43 -0
- package/dist/schema/schemas/agent-env.d.ts.map +1 -1
- package/dist/schema/schemas/agent-env.js +11 -0
- package/dist/schema/schemas/agent-env.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +43 -0
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/connections.d.ts +185 -0
- package/dist/schema/schemas/connections.d.ts.map +1 -0
- package/dist/schema/schemas/connections.js +176 -0
- package/dist/schema/schemas/connections.js.map +1 -0
- package/dist/schema/schemas/index.d.ts +1 -0
- package/dist/schema/schemas/index.d.ts.map +1 -1
- package/dist/schema/schemas/index.js +1 -0
- package/dist/schema/schemas/index.js.map +1 -1
- package/dist/schema/schemas/primitives/harness.d.ts +42 -0
- package/dist/schema/schemas/primitives/harness.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/harness.js +4 -0
- package/dist/schema/schemas/primitives/harness.js.map +1 -1
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -3
- package/scripts/bundle.mjs +12 -60
- 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
|
-
"@
|
|
24
|
-
"
|
|
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
|
+
}
|