@aws/agentcore 0.21.1 → 0.23.0
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 +17 -17
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +261 -84
- package/dist/assets/__tests__/googleadk-session-eviction.test.ts +87 -0
- package/dist/assets/__tests__/summarization-namespace.test.ts +43 -0
- package/dist/assets/agents/AGENTS.md +1 -1
- package/dist/assets/python/a2a/strands/capabilities/memory/session.py +1 -1
- package/dist/assets/python/agui/strands/capabilities/memory/session.py +1 -1
- package/dist/assets/python/http/autogen/base/main.py +33 -10
- package/dist/assets/python/http/googleadk/base/main.py +45 -8
- package/dist/assets/python/http/langchain_langgraph/base/main.py +46 -7
- package/dist/assets/python/http/openaiagents/base/main.py +19 -8
- package/dist/assets/python/http/strands/base/main.py +23 -26
- package/dist/assets/python/http/strands/capabilities/memory/session.py +1 -1
- package/dist/assets/typescript/http/strands/base/main.ts +48 -18
- package/dist/assets/typescript/http/vercelai/base/main.ts +42 -2
- package/dist/cli/index.mjs +521 -520
- package/dist/lib/errors/types.d.ts +25 -0
- package/dist/lib/errors/types.d.ts.map +1 -1
- package/dist/lib/errors/types.js +40 -1
- package/dist/lib/errors/types.js.map +1 -1
- package/dist/lib/schemas/io/config-io.d.ts +8 -0
- package/dist/lib/schemas/io/config-io.d.ts.map +1 -1
- package/dist/lib/schemas/io/config-io.js +12 -0
- package/dist/lib/schemas/io/config-io.js.map +1 -1
- package/dist/lib/secrets/cipher.d.ts +12 -0
- package/dist/lib/secrets/cipher.d.ts.map +1 -0
- package/dist/lib/secrets/cipher.js +54 -0
- package/dist/lib/secrets/cipher.js.map +1 -0
- package/dist/lib/secrets/index.d.ts +4 -0
- package/dist/lib/secrets/index.d.ts.map +1 -0
- package/dist/lib/secrets/index.js +15 -0
- package/dist/lib/secrets/index.js.map +1 -0
- package/dist/lib/secrets/key-provider.d.ts +16 -0
- package/dist/lib/secrets/key-provider.d.ts.map +1 -0
- package/dist/lib/secrets/key-provider.js +191 -0
- package/dist/lib/secrets/key-provider.js.map +1 -0
- package/dist/lib/secrets/sensitive-keys.d.ts +21 -0
- package/dist/lib/secrets/sensitive-keys.d.ts.map +1 -0
- package/dist/lib/secrets/sensitive-keys.js +67 -0
- package/dist/lib/secrets/sensitive-keys.js.map +1 -0
- package/dist/lib/utils/env.d.ts +4 -2
- package/dist/lib/utils/env.d.ts.map +1 -1
- package/dist/lib/utils/env.js +57 -27
- package/dist/lib/utils/env.js.map +1 -1
- package/dist/schema/constants.d.ts +26 -0
- package/dist/schema/constants.d.ts.map +1 -1
- package/dist/schema/constants.js +34 -1
- package/dist/schema/constants.js.map +1 -1
- package/dist/schema/schemas/agent-env.d.ts +4 -2
- package/dist/schema/schemas/agent-env.d.ts.map +1 -1
- package/dist/schema/schemas/agent-env.js +23 -5
- package/dist/schema/schemas/agent-env.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +23 -11
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/agentcore-project.js +19 -6
- package/dist/schema/schemas/agentcore-project.js.map +1 -1
- package/dist/schema/schemas/auth.d.ts +2 -3
- package/dist/schema/schemas/auth.d.ts.map +1 -1
- package/dist/schema/schemas/auth.js +8 -7
- package/dist/schema/schemas/auth.js.map +1 -1
- package/dist/schema/schemas/mcp.d.ts +27 -18
- package/dist/schema/schemas/mcp.d.ts.map +1 -1
- package/dist/schema/schemas/mcp.js +28 -175
- package/dist/schema/schemas/mcp.js.map +1 -1
- package/dist/schema/schemas/primitives/config-bundle.d.ts +1 -0
- package/dist/schema/schemas/primitives/config-bundle.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/config-bundle.js +3 -0
- package/dist/schema/schemas/primitives/config-bundle.js.map +1 -1
- package/dist/schema/schemas/primitives/harness.d.ts +1 -0
- package/dist/schema/schemas/primitives/harness.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/harness.js +16 -0
- package/dist/schema/schemas/primitives/harness.js.map +1 -1
- package/npm-shrinkwrap.json +223 -0
- package/package.json +4 -1
|
@@ -1,22 +1,62 @@
|
|
|
1
1
|
import { BedrockAgentCoreApp } from 'bedrock-agentcore/runtime';
|
|
2
|
-
import { streamText } from 'ai';
|
|
2
|
+
import { streamText, type ModelMessage } from 'ai';
|
|
3
3
|
import { loadModel } from './model/load.js';
|
|
4
4
|
|
|
5
5
|
const SYSTEM_PROMPT = `You are a helpful assistant.`;
|
|
6
6
|
|
|
7
|
+
const HISTORY_LIMIT = 128;
|
|
8
|
+
|
|
9
|
+
// Keeps one message history per sessionId so each session remembers its own
|
|
10
|
+
// turns (best-effort; resets on cold start). A Map preserves insertion order,
|
|
11
|
+
// so it doubles as an LRU bounded to 128 sessions — a local dev process serving
|
|
12
|
+
// many sessions cannot leak history between them or grow without bound. On
|
|
13
|
+
// AgentCore Runtime each microVM serves a single session, so this holds one
|
|
14
|
+
// entry. For durable history, persist messages to an external store.
|
|
15
|
+
const histories = new Map<string, ModelMessage[]>();
|
|
16
|
+
|
|
17
|
+
function getHistory(sessionId: string): ModelMessage[] {
|
|
18
|
+
const existing = histories.get(sessionId);
|
|
19
|
+
if (existing) {
|
|
20
|
+
histories.delete(sessionId);
|
|
21
|
+
histories.set(sessionId, existing);
|
|
22
|
+
return existing;
|
|
23
|
+
}
|
|
24
|
+
if (histories.size >= HISTORY_LIMIT) {
|
|
25
|
+
const oldest = histories.keys().next().value;
|
|
26
|
+
if (oldest !== undefined) histories.delete(oldest);
|
|
27
|
+
}
|
|
28
|
+
const fresh: ModelMessage[] = [];
|
|
29
|
+
histories.set(sessionId, fresh);
|
|
30
|
+
return fresh;
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
const app = new BedrockAgentCoreApp({
|
|
8
34
|
invocationHandler: {
|
|
9
35
|
async *process(payload: any, context: any) {
|
|
36
|
+
const sessionId = context?.sessionId ?? 'default-session';
|
|
37
|
+
const history = getHistory(sessionId);
|
|
38
|
+
const userMessage: ModelMessage = { role: 'user', content: payload.prompt ?? '' };
|
|
39
|
+
|
|
10
40
|
const model = await loadModel();
|
|
11
41
|
const result = streamText({
|
|
12
42
|
model,
|
|
13
43
|
system: SYSTEM_PROMPT,
|
|
14
|
-
|
|
44
|
+
messages: [...history, userMessage],
|
|
15
45
|
});
|
|
16
46
|
|
|
47
|
+
let assistant = '';
|
|
17
48
|
for await (const chunk of result.textStream) {
|
|
49
|
+
assistant += chunk;
|
|
18
50
|
yield { data: chunk };
|
|
19
51
|
}
|
|
52
|
+
|
|
53
|
+
// Commit the exchange to history only after a non-empty reply. On a failed
|
|
54
|
+
// or empty stream the turn is dropped instead of leaving a dangling user
|
|
55
|
+
// (or empty assistant) message — consecutive same-role or empty-content
|
|
56
|
+
// messages would otherwise be rejected on the next turn for this session.
|
|
57
|
+
if (assistant.length > 0) {
|
|
58
|
+
history.push(userMessage, { role: 'assistant', content: assistant });
|
|
59
|
+
}
|
|
20
60
|
},
|
|
21
61
|
},
|
|
22
62
|
});
|