@aws/agentcore 1.0.0-preview.24 → 1.0.0-preview.26

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 (45) hide show
  1. package/dist/assets/README.md +6 -2
  2. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +119 -16
  3. package/dist/assets/__tests__/input-validation.test.ts +44 -0
  4. package/dist/assets/agents/AGENTS.md +4 -4
  5. package/dist/assets/evaluators/autoevals-lambda/execution-role-policy.json +15 -0
  6. package/dist/assets/evaluators/autoevals-lambda/lambda_function.py +37 -0
  7. package/dist/assets/evaluators/autoevals-lambda/pyproject.toml +22 -0
  8. package/dist/assets/evaluators/deepeval-lambda/execution-role-policy.json +15 -0
  9. package/dist/assets/evaluators/deepeval-lambda/lambda_function.py +29 -0
  10. package/dist/assets/evaluators/deepeval-lambda/pyproject.toml +19 -0
  11. package/dist/assets/python/http/autogen/base/README.md +5 -0
  12. package/dist/assets/python/http/autogen/base/main.py +2 -0
  13. package/dist/assets/python/http/googleadk/base/README.md +5 -0
  14. package/dist/assets/python/http/googleadk/base/main.py +2 -0
  15. package/dist/assets/python/http/langchain_langgraph/base/README.md +5 -0
  16. package/dist/assets/python/http/langchain_langgraph/base/main.py +4 -0
  17. package/dist/assets/python/http/openaiagents/base/README.md +5 -0
  18. package/dist/assets/python/http/openaiagents/base/main.py +2 -0
  19. package/dist/assets/python/http/strands/base/README.md +6 -0
  20. package/dist/assets/python/http/strands/base/main.py +40 -4
  21. package/dist/assets/typescript/http/strands/base/README.md +5 -0
  22. package/dist/assets/typescript/http/strands/base/main.ts +8 -3
  23. package/dist/assets/typescript/http/vercelai/base/README.md +5 -0
  24. package/dist/assets/typescript/http/vercelai/base/main.ts +8 -2
  25. package/dist/cli/index.mjs +1010 -858
  26. package/dist/lib/schemas/io/config-io.d.ts +6 -0
  27. package/dist/lib/schemas/io/config-io.d.ts.map +1 -1
  28. package/dist/lib/schemas/io/config-io.js +68 -2
  29. package/dist/lib/schemas/io/config-io.js.map +1 -1
  30. package/dist/schema/schemas/agentcore-project.d.ts +8 -0
  31. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
  32. package/dist/schema/schemas/index.d.ts +2 -0
  33. package/dist/schema/schemas/index.d.ts.map +1 -1
  34. package/dist/schema/schemas/index.js +4 -0
  35. package/dist/schema/schemas/index.js.map +1 -1
  36. package/dist/schema/schemas/primitives/evaluator.d.ts +14 -0
  37. package/dist/schema/schemas/primitives/evaluator.d.ts.map +1 -1
  38. package/dist/schema/schemas/primitives/evaluator.js +12 -3
  39. package/dist/schema/schemas/primitives/evaluator.js.map +1 -1
  40. package/dist/schema/schemas/primitives/index.d.ts +2 -2
  41. package/dist/schema/schemas/primitives/index.d.ts.map +1 -1
  42. package/dist/schema/schemas/primitives/index.js +4 -2
  43. package/dist/schema/schemas/primitives/index.js.map +1 -1
  44. package/npm-shrinkwrap.json +201 -253
  45. package/package.json +11 -8
@@ -184,6 +184,8 @@ async def invoke(payload, context):
184
184
 
185
185
  # Process the user prompt
186
186
  prompt = payload.get("prompt", "What can you help me with?")
187
+ if not isinstance(prompt, str):
188
+ raise ValueError("prompt must be a string")
187
189
  session_id = getattr(context, "session_id", "default-session")
188
190
  session = get_session(session_id)
189
191
 
@@ -13,6 +13,12 @@ file defines a Starlette ASGI app with the chosen Agent framework SDK running wi
13
13
 
14
14
  `model/load.py` instantiates your chosen model provider.
15
15
 
16
+ ## Input Validation
17
+
18
+ Validate invocation input before forwarding it to Strands. Keep plain prompts typed as strings. If the app accepts a
19
+ caller-supplied message history, retain `strip_trailing_tool_use()`, which normalizes the history tail before
20
+ invoking the agent.
21
+
16
22
  ## Environment Variables
17
23
 
18
24
  | Variable | Required | Description |
@@ -481,17 +481,53 @@ get_or_create_agent = agent_factory()
481
481
  {{/if}}
482
482
 
483
483
 
484
+ def strip_trailing_tool_use(messages: Any) -> list[dict]:
485
+ """Strip toolUse blocks from the tail until the last message has none."""
486
+ if not isinstance(messages, list):
487
+ raise ValueError("messages must be a list")
488
+
489
+ messages = list(messages)
490
+ while messages:
491
+ last = messages[-1]
492
+ if not isinstance(last, dict):
493
+ raise ValueError("each message must be an object")
494
+ original_content = last.get("content", [])
495
+ if not isinstance(original_content, list) or not all(isinstance(block, dict) for block in original_content):
496
+ raise ValueError("each message content value must be a list of content blocks")
497
+
498
+ content = [block for block in original_content if "toolUse" not in block]
499
+ if len(content) == len(original_content):
500
+ break
501
+ if content:
502
+ messages[-1] = {**last, "content": content}
503
+ break
504
+ messages.pop()
505
+
506
+ return messages
507
+
508
+
484
509
  def _extract_prompt(payload: dict):
485
- """Accept harness-style messages[], tool_results[], or plain prompt string payloads."""
510
+ """Accept validated harness messages, tool results, or a plain prompt string."""
511
+ if not isinstance(payload, dict):
512
+ raise ValueError("payload must be a JSON object")
486
513
  if "messages" in payload:
487
- return payload["messages"]
514
+ return strip_trailing_tool_use(payload["messages"])
488
515
  if "tool_results" in payload:
516
+ tool_results = payload["tool_results"]
517
+ if not isinstance(tool_results, list) or not all(
518
+ isinstance(tool_result, dict) and isinstance(tool_result.get("toolUseId"), str)
519
+ for tool_result in tool_results
520
+ ):
521
+ raise ValueError("tool_results must contain objects with a toolUseId string")
489
522
  return [{"role": "user", "content": [{"toolResult": {
490
523
  "toolUseId": tr["toolUseId"],
491
524
  "status": tr.get("status", "success"),
492
525
  "content": tr.get("content", []),
493
- }} for tr in payload["tool_results"]]}]
494
- return payload.get("prompt", "")
526
+ }} for tr in tool_results]}]
527
+ prompt = payload.get("prompt", "")
528
+ if not isinstance(prompt, str):
529
+ raise ValueError("prompt must be a string")
530
+ return prompt
495
531
 
496
532
 
497
533
  def _has_inline_function_call(messages) -> bool:
@@ -13,6 +13,11 @@ defines an HTTP server that streams tokens from your chosen Agent framework SDK.
13
13
 
14
14
  `model/load.ts` instantiates your chosen model provider.
15
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
+
16
21
  ## Environment Variables
17
22
 
18
23
  | Variable | Required | Description |
@@ -34,6 +34,10 @@ const SYSTEM_PROMPT = `
34
34
  You are a helpful assistant. Use tools when appropriate.
35
35
  `;
36
36
 
37
+ const requestSchema = z.object({
38
+ prompt: z.string().default(''),
39
+ });
40
+
37
41
  {{#if hasMemory}}
38
42
  const agentCache = new Map<string, Agent>();
39
43
 
@@ -87,7 +91,8 @@ async function getOrCreateAgent(sessionId: string): Promise<Agent> {
87
91
 
88
92
  const app = new BedrockAgentCoreApp({
89
93
  invocationHandler: {
90
- async *process(payload: any, context: any) {
94
+ requestSchema,
95
+ async *process(payload, context) {
91
96
  {{#if hasMemory}}
92
97
  const sessionId = context?.sessionId ?? 'default-session';
93
98
  const actorId = getActorId(payload, context);
@@ -99,7 +104,7 @@ const app = new BedrockAgentCoreApp({
99
104
 
100
105
  {{#if hasMemory}}
101
106
  try {
102
- for await (const event of agent.stream(payload.prompt ?? '')) {
107
+ for await (const event of agent.stream(payload.prompt)) {
103
108
  if (
104
109
  event.type === 'modelStreamUpdateEvent' &&
105
110
  event.event?.type === 'modelContentBlockDeltaEvent' &&
@@ -123,7 +128,7 @@ const app = new BedrockAgentCoreApp({
123
128
  // e.g. Anthropic). Restoring on error keeps the session reusable.
124
129
  const snapshot = agent.takeSnapshot({ include: ['messages'] });
125
130
  try {
126
- for await (const event of agent.stream(payload.prompt ?? '')) {
131
+ for await (const event of agent.stream(payload.prompt)) {
127
132
  if (
128
133
  event.type === 'modelStreamUpdateEvent' &&
129
134
  event.event?.type === 'modelContentBlockDeltaEvent' &&
@@ -13,6 +13,11 @@ defines an HTTP app that streams tokens using the Vercel AI SDK's `streamText` A
13
13
 
14
14
  `model/load.ts` instantiates your chosen model provider.
15
15
 
16
+ ## Input Validation
17
+
18
+ The generated Zod request schema keeps plain prompts typed as strings before forwarding them to the agent framework.
19
+ Retain this validation when extending the request shape, and pass only prompt text to the agent.
20
+
16
21
  ## Environment Variables
17
22
 
18
23
  | Variable | Required | Description |
@@ -1,9 +1,14 @@
1
1
  import { BedrockAgentCoreApp } from 'bedrock-agentcore/runtime';
2
2
  import { streamText, type ModelMessage } from 'ai';
3
+ import { z } from 'zod';
3
4
  import { loadModel } from './model/load.js';
4
5
 
5
6
  const SYSTEM_PROMPT = `You are a helpful assistant.`;
6
7
 
8
+ const requestSchema = z.object({
9
+ prompt: z.string().default(''),
10
+ });
11
+
7
12
  const HISTORY_LIMIT = 128;
8
13
 
9
14
  // Keeps one message history per sessionId so each session remembers its own
@@ -32,10 +37,11 @@ function getHistory(sessionId: string): ModelMessage[] {
32
37
 
33
38
  const app = new BedrockAgentCoreApp({
34
39
  invocationHandler: {
35
- async *process(payload: any, context: any) {
40
+ requestSchema,
41
+ async *process(payload, context) {
36
42
  const sessionId = context?.sessionId ?? 'default-session';
37
43
  const history = getHistory(sessionId);
38
- const userMessage: ModelMessage = { role: 'user', content: payload.prompt ?? '' };
44
+ const userMessage: ModelMessage = { role: 'user', content: payload.prompt };
39
45
 
40
46
  const model = await loadModel();
41
47
  const result = streamText({