@aws/agentcore 0.8.2 → 0.10.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.
Files changed (65) hide show
  1. package/dist/agent-inspector/favicon.svg +60 -0
  2. package/dist/agent-inspector/index.css +1 -0
  3. package/dist/agent-inspector/index.html +14 -0
  4. package/dist/agent-inspector/index.js +274 -0
  5. package/dist/assets/README.md +56 -31
  6. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +1669 -245
  7. package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +77 -0
  8. package/dist/assets/__tests__/dockerfile-render.test.ts +24 -0
  9. package/dist/assets/agents/AGENTS.md +84 -55
  10. package/dist/assets/cdk/cdk.json +1 -1
  11. package/dist/assets/cdk/package.json +1 -1
  12. package/dist/assets/container/python/Dockerfile +4 -0
  13. package/dist/assets/evaluators/python-lambda/execution-role-policy.json +1 -1
  14. package/dist/assets/python/a2a/googleadk/base/main.py +65 -3
  15. package/dist/assets/python/a2a/langchain_langgraph/base/main.py +64 -1
  16. package/dist/assets/python/a2a/strands/base/main.py +65 -2
  17. package/dist/assets/python/agui/googleadk/base/README.md +30 -0
  18. package/dist/assets/python/agui/googleadk/base/gitignore.template +41 -0
  19. package/dist/assets/python/agui/googleadk/base/main.py +31 -0
  20. package/dist/assets/python/agui/googleadk/base/model/__init__.py +1 -0
  21. package/dist/assets/python/agui/googleadk/base/model/load.py +41 -0
  22. package/dist/assets/python/agui/googleadk/base/pyproject.toml +24 -0
  23. package/dist/assets/python/agui/langchain_langgraph/base/README.md +22 -0
  24. package/dist/assets/python/agui/langchain_langgraph/base/gitignore.template +41 -0
  25. package/dist/assets/python/agui/langchain_langgraph/base/main.py +74 -0
  26. package/dist/assets/python/agui/langchain_langgraph/base/model/__init__.py +1 -0
  27. package/dist/assets/python/agui/langchain_langgraph/base/model/load.py +123 -0
  28. package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +30 -0
  29. package/dist/assets/python/agui/strands/base/README.md +22 -0
  30. package/dist/assets/python/agui/strands/base/gitignore.template +41 -0
  31. package/dist/assets/python/agui/strands/base/main.py +43 -0
  32. package/dist/assets/python/agui/strands/base/model/__init__.py +1 -0
  33. package/dist/assets/python/agui/strands/base/model/load.py +123 -0
  34. package/dist/assets/python/agui/strands/base/pyproject.toml +27 -0
  35. package/dist/assets/python/agui/strands/capabilities/memory/__init__.py +1 -0
  36. package/dist/assets/python/agui/strands/capabilities/memory/session.py +38 -0
  37. package/dist/assets/python/http/autogen/base/main.py +61 -1
  38. package/dist/assets/python/http/googleadk/base/main.py +62 -2
  39. package/dist/assets/python/http/langchain_langgraph/base/main.py +61 -1
  40. package/dist/assets/python/http/openaiagents/base/main.py +70 -4
  41. package/dist/assets/python/http/strands/base/main.py +64 -6
  42. package/dist/cli/index.mjs +480 -457
  43. package/dist/lib/errors/config.d.ts.map +1 -1
  44. package/dist/lib/errors/config.js +5 -2
  45. package/dist/lib/errors/config.js.map +1 -1
  46. package/dist/schema/constants.d.ts +1 -0
  47. package/dist/schema/constants.d.ts.map +1 -1
  48. package/dist/schema/constants.js +8 -1
  49. package/dist/schema/constants.js.map +1 -1
  50. package/dist/schema/schemas/agent-env.d.ts +20 -0
  51. package/dist/schema/schemas/agent-env.d.ts.map +1 -1
  52. package/dist/schema/schemas/agent-env.js +17 -2
  53. package/dist/schema/schemas/agent-env.js.map +1 -1
  54. package/dist/schema/schemas/agentcore-project.d.ts +6 -0
  55. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
  56. package/dist/schema/schemas/aws-targets.d.ts +3 -0
  57. package/dist/schema/schemas/aws-targets.d.ts.map +1 -1
  58. package/dist/schema/schemas/aws-targets.js +1 -0
  59. package/dist/schema/schemas/aws-targets.js.map +1 -1
  60. package/dist/schema/schemas/primitives/evaluator.d.ts.map +1 -1
  61. package/dist/schema/schemas/primitives/evaluator.js +0 -1
  62. package/dist/schema/schemas/primitives/evaluator.js.map +1 -1
  63. package/package.json +4 -1
  64. package/scripts/bump-version.ts +7 -80
  65. package/scripts/copy-assets.mjs +14 -0
@@ -0,0 +1,77 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Dockerfile enableOtel rendering > renders opentelemetry-instrument CMD when enableOtel is true > Dockerfile-enableOtel-true 1`] = `
4
+ "FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
5
+
6
+ ARG UV_DEFAULT_INDEX
7
+ ARG UV_INDEX
8
+
9
+ WORKDIR /app
10
+
11
+ ENV UV_SYSTEM_PYTHON=1 \\
12
+ UV_COMPILE_BYTECODE=1 \\
13
+ UV_NO_PROGRESS=1 \\
14
+ PYTHONUNBUFFERED=1 \\
15
+ DOCKER_CONTAINER=1 \\
16
+ UV_DEFAULT_INDEX=\${UV_DEFAULT_INDEX} \\
17
+ UV_INDEX=\${UV_INDEX} \\
18
+ PATH="/app/.venv/bin:$PATH"
19
+
20
+ RUN useradd -m -u 1000 bedrock_agentcore
21
+
22
+ COPY pyproject.toml uv.lock ./
23
+ RUN uv sync --frozen --no-dev --no-install-project
24
+
25
+ COPY --chown=bedrock_agentcore:bedrock_agentcore . .
26
+ RUN uv sync --frozen --no-dev
27
+
28
+ USER bedrock_agentcore
29
+
30
+ # AgentCore Runtime service contract ports
31
+ # https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html
32
+ # 8080: HTTP Mode
33
+ # 8000: MCP Mode
34
+ # 9000: A2A Mode
35
+ EXPOSE 8080 8000 9000
36
+
37
+ CMD ["opentelemetry-instrument", "python", "-m", "main"]
38
+ "
39
+ `;
40
+
41
+ exports[`Dockerfile enableOtel rendering > renders plain python CMD when enableOtel is false > Dockerfile-enableOtel-false 1`] = `
42
+ "FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
43
+
44
+ ARG UV_DEFAULT_INDEX
45
+ ARG UV_INDEX
46
+
47
+ WORKDIR /app
48
+
49
+ ENV UV_SYSTEM_PYTHON=1 \\
50
+ UV_COMPILE_BYTECODE=1 \\
51
+ UV_NO_PROGRESS=1 \\
52
+ PYTHONUNBUFFERED=1 \\
53
+ DOCKER_CONTAINER=1 \\
54
+ UV_DEFAULT_INDEX=\${UV_DEFAULT_INDEX} \\
55
+ UV_INDEX=\${UV_INDEX} \\
56
+ PATH="/app/.venv/bin:$PATH"
57
+
58
+ RUN useradd -m -u 1000 bedrock_agentcore
59
+
60
+ COPY pyproject.toml uv.lock ./
61
+ RUN uv sync --frozen --no-dev --no-install-project
62
+
63
+ COPY --chown=bedrock_agentcore:bedrock_agentcore . .
64
+ RUN uv sync --frozen --no-dev
65
+
66
+ USER bedrock_agentcore
67
+
68
+ # AgentCore Runtime service contract ports
69
+ # https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-service-contract.html
70
+ # 8080: HTTP Mode
71
+ # 8000: MCP Mode
72
+ # 9000: A2A Mode
73
+ EXPOSE 8080 8000 9000
74
+
75
+ CMD ["python", "-m", "main"]
76
+ "
77
+ `;
@@ -0,0 +1,24 @@
1
+ import * as fs from 'fs';
2
+ import Handlebars from 'handlebars';
3
+ import * as path from 'path';
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ const DOCKERFILE_PATH = path.resolve(__dirname, '..', 'container', 'python', 'Dockerfile');
7
+
8
+ describe('Dockerfile enableOtel rendering', () => {
9
+ const template = Handlebars.compile(fs.readFileSync(DOCKERFILE_PATH, 'utf-8'));
10
+
11
+ it('renders opentelemetry-instrument CMD when enableOtel is true', () => {
12
+ const rendered = template({ entrypoint: 'main', enableOtel: true });
13
+ expect(rendered).toMatchSnapshot('Dockerfile-enableOtel-true');
14
+ expect(rendered).toContain('opentelemetry-instrument');
15
+ expect(rendered).not.toContain('CMD ["python", "-m"');
16
+ });
17
+
18
+ it('renders plain python CMD when enableOtel is false', () => {
19
+ const rendered = template({ entrypoint: 'main', enableOtel: false });
20
+ expect(rendered).toMatchSnapshot('Dockerfile-enableOtel-false');
21
+ expect(rendered).toContain('CMD ["python", "-m"');
22
+ expect(rendered).not.toContain('opentelemetry-instrument');
23
+ });
24
+ });
@@ -2,103 +2,114 @@
2
2
 
3
3
  This project contains configuration and infrastructure for an Amazon Bedrock AgentCore application.
4
4
 
5
- The `agentcore/` directory serves as a declarative model of an AgentCore project along with a concrete implementation
6
- through the `agentcore/cdk/` project which is modeled to take the configs as input. The project uses a **flat resource
7
- model** where agents, memories, and credentials are top-level arrays.
5
+ The `agentcore/` directory is a declarative model of the project. The `agentcore/cdk/` subdirectory uses the
6
+ `@aws/agentcore-cdk` L3 constructs to deploy the configuration to AWS.
8
7
 
9
8
  ## Mental Model
10
9
 
11
- The project uses a **flat resource model**. Agents, memories, and credentials are independent top-level arrays in
12
- `agentcore.json`. There is no binding or attachment between resources in the schema — each resource is provisioned
13
- independently. To use a memory or credential from an agent, the application code discovers the resource at runtime
14
- (e.g., via environment variables or SDK calls). Tags defined in `agentcore.json` flow through to deployed CloudFormation resources.
10
+ The project uses a **flat resource model**. Agents, memories, credentials, gateways, evaluators, and policies are
11
+ independent top-level arrays in `agentcore.json`. There is no binding between resources in the schema — each resource is
12
+ provisioned independently. Agents discover memories and credentials at runtime via environment variables or SDK calls.
13
+ Tags defined in `agentcore.json` flow through to deployed CloudFormation resources.
15
14
 
16
15
  ## Critical Invariants
17
16
 
18
- 1. **Schema-First Authority:** The `.json` files are the absolute source of truth. Do not attempt to modify agent
19
- behavior by editing the generated CDK code in `cdk/`.
20
- 2. **Resource Identity:** The `name` field in the schema determines the CloudFormation Logical ID.
21
- - **Renaming** an agent or target will **destroy and recreate** that resource.
22
- - **Modifying** other fields (descriptions, config) will update the resource **in-place**.
23
- 3. **1:1 Validation:** The schema maps directly to valid CloudFormation. If your JSON conforms to the types in
24
- `.llm-context/`, it will deploy successfully.
25
- 4. **Resource Removal:** To remove all resources, use `agentcore remove all`. To tear down deployed infrastructure, run
26
- `agentcore deploy` after removal — it will detect the empty state and offer a teardown flow.
17
+ 1. **Schema-First Authority:** The `.json` files are the source of truth. Do not modify agent behavior by editing
18
+ generated CDK code in `cdk/`.
19
+ 2. **Resource Identity:** The `name` field determines the CloudFormation Logical ID.
20
+ - **Renaming** a resource will **destroy and recreate** it.
21
+ - **Modifying** other fields will update the resource **in-place**.
22
+ 3. **Schema Validation:** If your JSON conforms to the types in `.llm-context/`, it will deploy successfully. Run
23
+ `agentcore validate` to check.
24
+ 4. **Resource Removal:** Use `agentcore remove` to remove resources. Run `agentcore deploy` after removal to tear down
25
+ deployed infrastructure.
27
26
 
28
27
  ## Directory Structure
29
28
 
30
29
  ```
31
- myNewProject/
32
- ├── AGENTS.md # This file - AI coding assistant context
33
- ├── agentcore/ # AgentCore configuration directory
30
+ myProject/
31
+ ├── AGENTS.md # This file AI coding assistant context
32
+ ├── agentcore/
34
33
  │ ├── agentcore.json # Main project config (AgentCoreProjectSpec)
35
- │ ├── aws-targets.json # Deployment targets
36
- │ ├── .llm-context/ # TypeScript type definitions for AI coding assistants
37
- ├── README.md # Guide to using the schema files
34
+ │ ├── aws-targets.json # Deployment targets (account + region)
35
+ │ ├── .env.local # Secrets API keys (gitignored)
36
+ │ ├── .llm-context/ # TypeScript type definitions for AI assistants
37
+ │ │ ├── README.md # Guide to using schema files
38
38
  │ │ ├── agentcore.ts # AgentCoreProjectSpec types
39
- │ │ └── aws-targets.ts # AWS deployment target types
40
- │ └── cdk/ # AWS CDK project for deployment
41
- └── app/ # Application code (if agents were created)
39
+ │ │ ├── aws-targets.ts # AWS deployment target types
40
+ └── mcp.ts # Gateway and MCP tool types
41
+ └── cdk/ # AWS CDK project (@aws/agentcore-cdk L3 constructs)
42
+ ├── app/ # Agent application code
43
+ └── evaluators/ # Custom evaluator code (if any)
42
44
  ```
43
45
 
44
46
  ## Schema Reference
45
47
 
46
48
  The `agentcore/.llm-context/` directory contains TypeScript type definitions optimized for AI coding assistants. Each
47
- file maps to a JSON config file and includes validation constraints as comments.
49
+ file maps to a JSON config file and includes validation constraints as comments (`@regex`, `@min`, `@max`).
48
50
 
49
- | JSON Config | Schema File | Root Type |
50
- | ---------------------------- | --------------------------------------- | ----------------------- |
51
- | `agentcore/agentcore.json` | `agentcore/.llm-context/agentcore.ts` | `AgentCoreProjectSpec` |
52
- | `agentcore/aws-targets.json` | `agentcore/.llm-context/aws-targets.ts` | `AWSDeploymentTarget[]` |
51
+ | JSON Config | Schema File | Root Type |
52
+ | --- | --- | --- |
53
+ | `agentcore/agentcore.json` | `agentcore/.llm-context/agentcore.ts` | `AgentCoreProjectSpec` |
54
+ | `agentcore/agentcore.json` (gateways) | `agentcore/.llm-context/mcp.ts` | `AgentCoreMcpSpec` |
55
+ | `agentcore/aws-targets.json` | `agentcore/.llm-context/aws-targets.ts` | `AwsDeploymentTarget[]` |
53
56
 
54
57
  ### Key Types
55
58
 
56
- - **AgentCoreProjectSpec**: Root project configuration with `agents`, `memories`, `credentials` arrays
57
- - **AgentEnvSpec**: Agent configuration (runtime, entrypoint, code location)
58
- - **Memory**: Memory resource with strategies and expiry
59
- - **Credential**: API key credential provider
59
+ - **AgentCoreProjectSpec**: Root config with `runtimes`, `memories`, `credentials`, `agentCoreGateways`, `evaluators`, `onlineEvalConfigs`, `policyEngines` arrays
60
+ - **AgentEnvSpec**: Agent configuration (build type, entrypoint, code location, runtime version, network mode)
61
+ - **Memory**: Memory resource with strategies (SEMANTIC, SUMMARIZATION, USER_PREFERENCE, EPISODIC) and expiry
62
+ - **Credential**: API key or OAuth credential provider
63
+ - **AgentCoreGateway**: MCP gateway with targets (Lambda, MCP server, OpenAPI, Smithy, API Gateway)
64
+ - **Evaluator**: LLM-as-a-Judge or code-based evaluator
65
+ - **OnlineEvalConfig**: Continuous evaluation pipeline bound to an agent
60
66
 
61
67
  ### Common Enum Values
62
68
 
63
69
  - **BuildType**: `'CodeZip'` | `'Container'`
64
- - **NetworkMode**: `'PUBLIC'`
65
- - **RuntimeVersion**: `'PYTHON_3_10'` | `'PYTHON_3_11'` | `'PYTHON_3_12'` | `'PYTHON_3_13'` | `'PYTHON_3_14'`
70
+ - **NetworkMode**: `'PUBLIC'` | `'VPC'`
71
+ - **RuntimeVersion**: `'PYTHON_3_10'` | `'PYTHON_3_11'` | `'PYTHON_3_12'` | `'PYTHON_3_13'` | `'PYTHON_3_14'` | `'NODE_18'` | `'NODE_20'` | `'NODE_22'`
66
72
  - **MemoryStrategyType**: `'SEMANTIC'` | `'SUMMARIZATION'` | `'USER_PREFERENCE'` | `'EPISODIC'`
73
+ - **GatewayTargetType**: `'lambda'` | `'mcpServer'` | `'openApiSchema'` | `'smithyModel'` | `'apiGateway'` | `'lambdaFunctionArn'`
74
+ - **ModelProvider**: `'Bedrock'` | `'Gemini'` | `'OpenAI'` | `'Anthropic'`
67
75
 
68
76
  ### Build Types
69
77
 
70
- - **CodeZip**: Python source is packaged as a zip artifact and deployed directly to AgentCore Runtime.
71
- - **Container**: Agent code is built as a Docker container image. Requires a `Dockerfile` in the agent's `codeLocation`
72
- directory. At deploy time, the source is uploaded to S3, built in CodeBuild (ARM64), pushed to a per-agent ECR
73
- repository, and the container URI is provided to the AgentCore Runtime. For local development (`agentcore dev`), the
74
- container is built and run locally with volume-mounted hot-reload.
78
+ - **CodeZip**: Python source packaged as a zip and deployed directly to AgentCore Runtime.
79
+ - **Container**: Docker image built in CodeBuild (ARM64), pushed to a per-agent ECR repository. Requires a `Dockerfile`
80
+ in the agent's `codeLocation` directory. For local development (`agentcore dev`), the container is built and run
81
+ locally with volume-mounted hot-reload.
75
82
 
76
83
  ### Supported Frameworks (for template agents)
77
84
 
78
- - **Strands** - Works with Bedrock, Anthropic, OpenAI, Gemini
79
- - **LangChain_LangGraph** - Works with Bedrock, Anthropic, OpenAI, Gemini
80
- - **GoogleADK** - Gemini only
81
- - **OpenAIAgents** - OpenAI only
85
+ - **Strands** Bedrock, Anthropic, OpenAI, Gemini
86
+ - **LangChain/LangGraph** Bedrock, Anthropic, OpenAI, Gemini
87
+ - **GoogleADK** Gemini
88
+ - **OpenAI Agents** OpenAI
89
+ - **Autogen** — Bedrock, Anthropic, OpenAI, Gemini
82
90
 
91
+ ### Protocols
83
92
 
84
- ### Specific Context
85
-
86
- Directory pathing to local projects is required for runtimes. Both CodeZip (Python zip) and Container (Docker image)
87
- deployment options are available.
93
+ - **HTTP** — Standard HTTP agent endpoint
94
+ - **MCP** — Model Context Protocol server
95
+ - **A2A** — Agent-to-Agent protocol (Google A2A)
88
96
 
89
97
  ## Deployment
90
98
 
91
- The `agentcore/cdk/` subdirectory contains an AWS CDK node project.
99
+ Deployments are orchestrated through the CLI:
92
100
 
93
- Deployments of this project are primarily intended to be orchestrated through the `agentcore deploy` command in the CLI.
101
+ ```bash
102
+ agentcore deploy # Synthesizes CDK and deploys to AWS
103
+ agentcore status # Shows deployment status
104
+ ```
94
105
 
95
- Alternatively, the project can be deployed directly as a traditional CDK project:
106
+ Alternatively, deploy directly via CDK:
96
107
 
97
108
  ```bash
98
109
  cd agentcore/cdk
99
110
  npm install
100
- npx cdk synth # Preview CloudFormation template
101
- npx cdk deploy # Deploy to AWS
111
+ npx cdk synth
112
+ npx cdk deploy
102
113
  ```
103
114
 
104
115
  ## Editing Schemas
@@ -109,4 +120,22 @@ When modifying JSON config files:
109
120
  2. Check validation constraint comments (`@regex`, `@min`, `@max`)
110
121
  3. Use exact enum values as string literals
111
122
  4. Use CloudFormation-safe names (alphanumeric, start with letter)
112
- 5. Run `agentcore validate` command to verify changes.
123
+ 5. Run `agentcore validate` to verify changes
124
+
125
+ ## CLI Commands
126
+
127
+ | Command | Description |
128
+ | --- | --- |
129
+ | `agentcore create` | Create a new project |
130
+ | `agentcore add <resource>` | Add agent, memory, credential, gateway, evaluator, policy |
131
+ | `agentcore remove <resource>` | Remove a resource |
132
+ | `agentcore dev` | Run agent locally with hot-reload |
133
+ | `agentcore deploy` | Deploy to AWS |
134
+ | `agentcore status` | Show deployment status |
135
+ | `agentcore invoke` | Invoke agent (local or deployed) |
136
+ | `agentcore logs` | View agent logs |
137
+ | `agentcore traces` | View agent traces |
138
+ | `agentcore eval` | Run evaluations against an agent |
139
+ | `agentcore package` | Package agent artifacts |
140
+ | `agentcore validate` | Validate configuration |
141
+ | `agentcore pause` / `resume` | Pause or resume a deployed agent |
@@ -9,7 +9,7 @@
9
9
  "@aws-cdk/aws-ecs-patterns:secGroupsDisablesImplicitOpenListener": true,
10
10
  "@aws-cdk/aws-lambda:recognizeLayerVersion": true,
11
11
  "@aws-cdk/core:checkSecretUsage": true,
12
- "@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
12
+ "@aws-cdk/core:target-partitions": ["aws", "aws-cn", "aws-us-gov"],
13
13
  "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
14
14
  "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
15
15
  "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
@@ -23,7 +23,7 @@
23
23
  "typescript": "~5.9.3"
24
24
  },
25
25
  "dependencies": {
26
- "@aws/agentcore-cdk": "0.1.0-alpha.19",
26
+ "@aws/agentcore-cdk": "^0.1.0-alpha.19",
27
27
  "aws-cdk-lib": "^2.248.0",
28
28
  "constructs": "^10.0.0"
29
29
  }
@@ -31,4 +31,8 @@ USER bedrock_agentcore
31
31
  # 9000: A2A Mode
32
32
  EXPOSE 8080 8000 9000
33
33
 
34
+ {{#if enableOtel}}
34
35
  CMD ["opentelemetry-instrument", "python", "-m", "{{entrypoint}}"]
36
+ {{else}}
37
+ CMD ["python", "-m", "{{entrypoint}}"]
38
+ {{/if}}
@@ -4,7 +4,7 @@
4
4
  {
5
5
  "Effect": "Allow",
6
6
  "Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"],
7
- "Resource": "arn:aws:logs:*:*:log-group:/aws/lambda/*"
7
+ "Resource": "arn:*:logs:*:*:log-group:/aws/lambda/*"
8
8
  }
9
9
  ]
10
10
  }
@@ -1,3 +1,4 @@
1
+ import os
1
2
  from google.adk.agents import Agent
2
3
  from google.adk.a2a.executor.a2a_agent_executor import A2aAgentExecutor
3
4
  from google.adk.runners import Runner
@@ -6,18 +7,79 @@ from a2a.types import AgentCapabilities, AgentCard, AgentSkill
6
7
  from bedrock_agentcore.runtime import serve_a2a
7
8
  from model.load import load_model
8
9
 
10
+ load_model() # Sets GOOGLE_API_KEY env var (returns None)
11
+
9
12
 
10
13
  def add_numbers(a: int, b: int) -> int:
11
14
  """Return the sum of two numbers."""
12
15
  return a + b
13
16
 
14
17
 
18
+ tools = [add_numbers]
19
+
20
+ {{#if sessionStorageMountPath}}
21
+ SESSION_STORAGE_PATH = "{{sessionStorageMountPath}}"
22
+
23
+ def _safe_resolve(path: str) -> str:
24
+ """Resolve path safely within the storage boundary."""
25
+ resolved = os.path.realpath(os.path.join(SESSION_STORAGE_PATH, path.lstrip("/")))
26
+ if not resolved.startswith(os.path.realpath(SESSION_STORAGE_PATH)):
27
+ raise ValueError(f"Path '{path}' is outside the storage boundary")
28
+ return resolved
29
+
30
+ def file_read(path: str) -> str:
31
+ """Read a file from persistent storage. The path is relative to the storage root."""
32
+ try:
33
+ full_path = _safe_resolve(path)
34
+ with open(full_path) as f:
35
+ return f.read()
36
+ except ValueError as e:
37
+ return str(e)
38
+ except OSError as e:
39
+ return f"Error reading '{path}': {e.strerror}"
40
+
41
+ def file_write(path: str, content: str) -> str:
42
+ """Write content to a file in persistent storage. The path is relative to the storage root."""
43
+ try:
44
+ full_path = _safe_resolve(path)
45
+ parent = os.path.dirname(full_path)
46
+ if parent:
47
+ os.makedirs(parent, exist_ok=True)
48
+ with open(full_path, "w") as f:
49
+ f.write(content)
50
+ return f"Written to {path}"
51
+ except ValueError as e:
52
+ return str(e)
53
+ except OSError as e:
54
+ return f"Error writing '{path}': {e.strerror}"
55
+
56
+ def list_files(directory: str = "") -> str:
57
+ """List files in persistent storage. The directory is relative to the storage root."""
58
+ try:
59
+ target = _safe_resolve(directory)
60
+ entries = os.listdir(target)
61
+ return "\n".join(entries) if entries else "(empty directory)"
62
+ except ValueError as e:
63
+ return str(e)
64
+ except OSError as e:
65
+ return f"Error listing '{directory}': {e.strerror}"
66
+
67
+ tools.extend([file_read, file_write, list_files])
68
+ {{/if}}
69
+
70
+ AGENT_INSTRUCTION = """
71
+ You are a helpful assistant. Use tools when appropriate.
72
+ {{#if sessionStorageMountPath}}
73
+ You have persistent storage at {{sessionStorageMountPath}}. Use file tools to read and write files. Data persists across sessions.
74
+ {{/if}}
75
+ """
76
+
15
77
  agent = Agent(
16
- model=load_model(),
78
+ model="gemini-2.5-flash",
17
79
  name="{{ name }}",
18
80
  description="A helpful assistant that can use tools.",
19
- instruction="You are a helpful assistant. Use tools when appropriate.",
20
- tools=[add_numbers],
81
+ instruction=AGENT_INSTRUCTION,
82
+ tools=tools,
21
83
  )
22
84
 
23
85
  runner = Runner(
@@ -1,3 +1,4 @@
1
+ import os
1
2
  from langchain_core.tools import tool
2
3
  from langgraph.prebuilt import create_react_agent
3
4
  from opentelemetry.instrumentation.langchain import LangchainInstrumentor
@@ -18,8 +19,70 @@ def add_numbers(a: int, b: int) -> int:
18
19
  return a + b
19
20
 
20
21
 
22
+ tools = [add_numbers]
23
+
24
+ {{#if sessionStorageMountPath}}
25
+ SESSION_STORAGE_PATH = "{{sessionStorageMountPath}}"
26
+
27
+ def _safe_resolve(path: str) -> str:
28
+ """Resolve path safely within the storage boundary."""
29
+ resolved = os.path.realpath(os.path.join(SESSION_STORAGE_PATH, path.lstrip("/")))
30
+ if not resolved.startswith(os.path.realpath(SESSION_STORAGE_PATH)):
31
+ raise ValueError(f"Path '{path}' is outside the storage boundary")
32
+ return resolved
33
+
34
+ @tool
35
+ def file_read(path: str) -> str:
36
+ """Read a file from persistent storage. The path is relative to the storage root."""
37
+ try:
38
+ full_path = _safe_resolve(path)
39
+ with open(full_path) as f:
40
+ return f.read()
41
+ except ValueError as e:
42
+ return str(e)
43
+ except OSError as e:
44
+ return f"Error reading '{path}': {e.strerror}"
45
+
46
+ @tool
47
+ def file_write(path: str, content: str) -> str:
48
+ """Write content to a file in persistent storage. The path is relative to the storage root."""
49
+ try:
50
+ full_path = _safe_resolve(path)
51
+ parent = os.path.dirname(full_path)
52
+ if parent:
53
+ os.makedirs(parent, exist_ok=True)
54
+ with open(full_path, "w") as f:
55
+ f.write(content)
56
+ return f"Written to {path}"
57
+ except ValueError as e:
58
+ return str(e)
59
+ except OSError as e:
60
+ return f"Error writing '{path}': {e.strerror}"
61
+
62
+ @tool
63
+ def list_files(directory: str = "") -> str:
64
+ """List files in persistent storage. The directory is relative to the storage root."""
65
+ try:
66
+ target = _safe_resolve(directory)
67
+ entries = os.listdir(target)
68
+ return "\n".join(entries) if entries else "(empty directory)"
69
+ except ValueError as e:
70
+ return str(e)
71
+ except OSError as e:
72
+ return f"Error listing '{directory}': {e.strerror}"
73
+
74
+ tools.extend([file_read, file_write, list_files])
75
+ {{/if}}
76
+
77
+ SYSTEM_PROMPT = """
78
+ You are a helpful assistant. Use tools when appropriate.
79
+ {{#if sessionStorageMountPath}}
80
+ You have persistent storage at {{sessionStorageMountPath}}. Use file tools to read and write files. Data persists across sessions.
81
+ {{/if}}
82
+ """
83
+
21
84
  model = load_model()
22
- graph = create_react_agent(model, tools=[add_numbers])
85
+ graph = create_react_agent(model, tools=tools, prompt=SYSTEM_PROMPT)
23
86
 
24
87
 
25
88
  class LangGraphA2AExecutor(AgentExecutor):
@@ -5,6 +5,9 @@ from model.load import load_model
5
5
  {{#if hasMemory}}
6
6
  from memory.session import get_memory_session_manager
7
7
  {{/if}}
8
+ {{#if sessionStorageMountPath}}
9
+ import os
10
+ {{/if}}
8
11
 
9
12
 
10
13
  @tool
@@ -15,6 +18,66 @@ def add_numbers(a: int, b: int) -> int:
15
18
 
16
19
  tools = [add_numbers]
17
20
 
21
+ {{#if sessionStorageMountPath}}
22
+ SESSION_STORAGE_PATH = "{{sessionStorageMountPath}}"
23
+
24
+ def _safe_resolve(path: str) -> str:
25
+ """Resolve path safely within the storage boundary."""
26
+ resolved = os.path.realpath(os.path.join(SESSION_STORAGE_PATH, path.lstrip("/")))
27
+ if not resolved.startswith(os.path.realpath(SESSION_STORAGE_PATH)):
28
+ raise ValueError(f"Path '{path}' is outside the storage boundary")
29
+ return resolved
30
+
31
+ @tool
32
+ def file_read(path: str) -> str:
33
+ """Read a file from persistent storage. The path is relative to the storage root."""
34
+ try:
35
+ full_path = _safe_resolve(path)
36
+ with open(full_path) as f:
37
+ return f.read()
38
+ except ValueError as e:
39
+ return str(e)
40
+ except OSError as e:
41
+ return f"Error reading '{path}': {e.strerror}"
42
+
43
+ @tool
44
+ def file_write(path: str, content: str) -> str:
45
+ """Write content to a file in persistent storage. The path is relative to the storage root."""
46
+ try:
47
+ full_path = _safe_resolve(path)
48
+ parent = os.path.dirname(full_path)
49
+ if parent:
50
+ os.makedirs(parent, exist_ok=True)
51
+ with open(full_path, "w") as f:
52
+ f.write(content)
53
+ return f"Written to {path}"
54
+ except ValueError as e:
55
+ return str(e)
56
+ except OSError as e:
57
+ return f"Error writing '{path}': {e.strerror}"
58
+
59
+ @tool
60
+ def list_files(directory: str = "") -> str:
61
+ """List files in persistent storage. The directory is relative to the storage root."""
62
+ try:
63
+ target = _safe_resolve(directory)
64
+ entries = os.listdir(target)
65
+ return "\n".join(entries) if entries else "(empty directory)"
66
+ except ValueError as e:
67
+ return str(e)
68
+ except OSError as e:
69
+ return f"Error listing '{directory}': {e.strerror}"
70
+
71
+ tools.extend([file_read, file_write, list_files])
72
+ {{/if}}
73
+
74
+ SYSTEM_PROMPT = """
75
+ You are a helpful assistant. Use tools when appropriate.
76
+ {{#if sessionStorageMountPath}}
77
+ You have persistent storage at {{sessionStorageMountPath}}. Use file tools to read and write files. Data persists across sessions.
78
+ {{/if}}
79
+ """
80
+
18
81
  {{#if hasMemory}}
19
82
  def agent_factory():
20
83
  cache = {}
@@ -24,7 +87,7 @@ def agent_factory():
24
87
  cache[key] = Agent(
25
88
  model=load_model(),
26
89
  session_manager=get_memory_session_manager(session_id, user_id),
27
- system_prompt="You are a helpful assistant. Use tools when appropriate.",
90
+ system_prompt=SYSTEM_PROMPT,
28
91
  tools=tools,
29
92
  )
30
93
  return cache[key]
@@ -35,7 +98,7 @@ agent = get_or_create_agent("default-session", "default-user")
35
98
  {{else}}
36
99
  agent = Agent(
37
100
  model=load_model(),
38
- system_prompt="You are a helpful assistant. Use tools when appropriate.",
101
+ system_prompt=SYSTEM_PROMPT,
39
102
  tools=tools,
40
103
  )
41
104
  {{/if}}
@@ -0,0 +1,30 @@
1
+ # {{ name }}
2
+
3
+ An AG-UI agent deployed on Amazon Bedrock AgentCore using Google ADK.
4
+
5
+ ## Overview
6
+
7
+ This agent implements the AG-UI protocol using Google's Agent Development Kit, enabling rich agent-user interaction via the AG-UI event stream.
8
+
9
+ ## Local Development
10
+
11
+ ```bash
12
+ uv sync
13
+ uv run python main.py
14
+ ```
15
+
16
+ The agent starts on port 8080 and serves requests at `/invocations`.
17
+
18
+ ## Health Check
19
+
20
+ ```
21
+ GET /ping
22
+ ```
23
+
24
+ Returns `{"status": "healthy"}`.
25
+
26
+ ## Deploy
27
+
28
+ ```bash
29
+ agentcore deploy
30
+ ```
@@ -0,0 +1,41 @@
1
+ # Environment variables
2
+ .env
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+ *.so
9
+ .Python
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # Virtual environments
27
+ .venv/
28
+ venv/
29
+ ENV/
30
+ env/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+ *~
38
+
39
+ # OS
40
+ .DS_Store
41
+ Thumbs.db