@aws/agentcore 0.8.2 → 1.0.0-preview.1
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/dist/agent-inspector/favicon.svg +60 -0
- package/dist/agent-inspector/index.css +1 -0
- package/dist/agent-inspector/index.html +14 -0
- package/dist/agent-inspector/index.js +275 -0
- package/dist/agent-inspector/index.js.map +1 -0
- package/dist/assets/README.md +56 -31
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +1732 -259
- package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +77 -0
- package/dist/assets/__tests__/dockerfile-render.test.ts +24 -0
- package/dist/assets/agents/AGENTS.md +84 -55
- package/dist/assets/cdk/bin/cdk.ts +35 -0
- package/dist/assets/cdk/lib/cdk-stack.ts +15 -2
- package/dist/assets/cdk/package.json +1 -1
- package/dist/assets/container/python/Dockerfile +4 -0
- package/dist/assets/harness/invoke.py.template +74 -0
- package/dist/assets/python/a2a/googleadk/base/main.py +65 -3
- package/dist/assets/python/a2a/langchain_langgraph/base/main.py +64 -1
- package/dist/assets/python/a2a/strands/base/main.py +65 -2
- package/dist/assets/python/agui/googleadk/base/README.md +30 -0
- package/dist/assets/python/agui/googleadk/base/gitignore.template +41 -0
- package/dist/assets/python/agui/googleadk/base/main.py +31 -0
- package/dist/assets/python/agui/googleadk/base/model/__init__.py +1 -0
- package/dist/assets/python/agui/googleadk/base/model/load.py +41 -0
- package/dist/assets/python/agui/googleadk/base/pyproject.toml +24 -0
- package/dist/assets/python/agui/langchain_langgraph/base/README.md +22 -0
- package/dist/assets/python/agui/langchain_langgraph/base/gitignore.template +41 -0
- package/dist/assets/python/agui/langchain_langgraph/base/main.py +74 -0
- package/dist/assets/python/agui/langchain_langgraph/base/model/__init__.py +1 -0
- package/dist/assets/python/agui/langchain_langgraph/base/model/load.py +123 -0
- package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +30 -0
- package/dist/assets/python/agui/strands/base/README.md +22 -0
- package/dist/assets/python/agui/strands/base/gitignore.template +41 -0
- package/dist/assets/python/agui/strands/base/main.py +43 -0
- package/dist/assets/python/agui/strands/base/model/__init__.py +1 -0
- package/dist/assets/python/agui/strands/base/model/load.py +123 -0
- package/dist/assets/python/agui/strands/base/pyproject.toml +27 -0
- package/dist/assets/python/agui/strands/capabilities/memory/__init__.py +1 -0
- package/dist/assets/python/agui/strands/capabilities/memory/session.py +38 -0
- package/dist/assets/python/http/autogen/base/main.py +61 -1
- package/dist/assets/python/http/googleadk/base/main.py +62 -2
- package/dist/assets/python/http/langchain_langgraph/base/main.py +61 -1
- package/dist/assets/python/http/openaiagents/base/main.py +70 -4
- package/dist/assets/python/http/strands/base/main.py +64 -6
- package/dist/cli/index.mjs +517 -466
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +3 -1
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/errors/config.d.ts.map +1 -1
- package/dist/lib/errors/config.js +5 -2
- package/dist/lib/errors/config.js.map +1 -1
- package/dist/lib/schemas/io/config-io.d.ts +9 -1
- package/dist/lib/schemas/io/config-io.d.ts.map +1 -1
- package/dist/lib/schemas/io/config-io.js +14 -0
- package/dist/lib/schemas/io/config-io.js.map +1 -1
- package/dist/lib/schemas/io/path-resolver.d.ts +12 -0
- package/dist/lib/schemas/io/path-resolver.d.ts.map +1 -1
- package/dist/lib/schemas/io/path-resolver.js +18 -0
- package/dist/lib/schemas/io/path-resolver.js.map +1 -1
- package/dist/schema/constants.d.ts +1 -0
- package/dist/schema/constants.d.ts.map +1 -1
- package/dist/schema/constants.js +8 -1
- package/dist/schema/constants.js.map +1 -1
- package/dist/schema/schemas/agent-env.d.ts +20 -0
- package/dist/schema/schemas/agent-env.d.ts.map +1 -1
- package/dist/schema/schemas/agent-env.js +17 -2
- package/dist/schema/schemas/agent-env.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +17 -0
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/agentcore-project.js +18 -1
- package/dist/schema/schemas/agentcore-project.js.map +1 -1
- package/dist/schema/schemas/deployed-state.d.ts +50 -0
- package/dist/schema/schemas/deployed-state.d.ts.map +1 -1
- package/dist/schema/schemas/deployed-state.js +15 -1
- package/dist/schema/schemas/deployed-state.js.map +1 -1
- package/dist/schema/schemas/primitives/evaluator.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/evaluator.js +0 -1
- package/dist/schema/schemas/primitives/evaluator.js.map +1 -1
- package/dist/schema/schemas/primitives/harness.d.ts +287 -0
- package/dist/schema/schemas/primitives/harness.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/harness.js +237 -0
- package/dist/schema/schemas/primitives/harness.js.map +1 -0
- package/dist/schema/schemas/primitives/index.d.ts +2 -0
- package/dist/schema/schemas/primitives/index.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/index.js +14 -1
- package/dist/schema/schemas/primitives/index.js.map +1 -1
- package/package.json +4 -1
- package/scripts/bump-version.ts +7 -80
- package/scripts/bundle.mjs +57 -3
- 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
|
|
6
|
-
|
|
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,
|
|
12
|
-
`agentcore.json`. There is no binding
|
|
13
|
-
independently.
|
|
14
|
-
|
|
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
|
|
19
|
-
|
|
20
|
-
2. **Resource Identity:** The `name` field
|
|
21
|
-
- **Renaming**
|
|
22
|
-
- **Modifying** other fields
|
|
23
|
-
3. **
|
|
24
|
-
|
|
25
|
-
4. **Resource Removal:**
|
|
26
|
-
|
|
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
|
-
|
|
32
|
-
├── AGENTS.md # This file
|
|
33
|
-
├── agentcore/
|
|
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
|
-
│ ├── .
|
|
37
|
-
│
|
|
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
|
-
│ │
|
|
40
|
-
│ └──
|
|
41
|
-
└──
|
|
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
|
|
50
|
-
|
|
|
51
|
-
| `agentcore/agentcore.json`
|
|
52
|
-
| `agentcore/
|
|
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
|
|
57
|
-
- **AgentEnvSpec**: Agent configuration (
|
|
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
|
|
71
|
-
- **Container**:
|
|
72
|
-
|
|
73
|
-
|
|
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**
|
|
79
|
-
- **
|
|
80
|
-
- **GoogleADK**
|
|
81
|
-
- **
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
99
|
+
Deployments are orchestrated through the CLI:
|
|
92
100
|
|
|
93
|
-
|
|
101
|
+
```bash
|
|
102
|
+
agentcore deploy # Synthesizes CDK and deploys to AWS
|
|
103
|
+
agentcore status # Shows deployment status
|
|
104
|
+
```
|
|
94
105
|
|
|
95
|
-
Alternatively,
|
|
106
|
+
Alternatively, deploy directly via CDK:
|
|
96
107
|
|
|
97
108
|
```bash
|
|
98
109
|
cd agentcore/cdk
|
|
99
110
|
npm install
|
|
100
|
-
npx cdk synth
|
|
101
|
-
npx cdk deploy
|
|
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`
|
|
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 |
|
|
@@ -54,6 +54,40 @@ async function main() {
|
|
|
54
54
|
throw new Error('No deployment targets configured. Please define targets in agentcore/aws-targets.json');
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// Read harness configs for role creation.
|
|
58
|
+
// Harness fields may not yet be on the AgentCoreProjectSpec type from @aws/agentcore-cdk,
|
|
59
|
+
// so we read them dynamically via specAny (same pattern as gateways above).
|
|
60
|
+
// Harness paths in agentcore.json are relative to the project root (parent of agentcore/).
|
|
61
|
+
const projectRoot = path.resolve(configRoot, '..');
|
|
62
|
+
const harnessConfigs: {
|
|
63
|
+
name: string;
|
|
64
|
+
executionRoleArn?: string;
|
|
65
|
+
memoryName?: string;
|
|
66
|
+
containerUri?: string;
|
|
67
|
+
hasDockerfile?: boolean;
|
|
68
|
+
tools?: { type: string; name: string }[];
|
|
69
|
+
apiKeyArn?: string;
|
|
70
|
+
}[] = [];
|
|
71
|
+
for (const entry of specAny.harnesses ?? []) {
|
|
72
|
+
const harnessPath = path.resolve(projectRoot, entry.path, 'harness.json');
|
|
73
|
+
try {
|
|
74
|
+
const harnessSpec = JSON.parse(fs.readFileSync(harnessPath, 'utf-8'));
|
|
75
|
+
harnessConfigs.push({
|
|
76
|
+
name: entry.name,
|
|
77
|
+
executionRoleArn: harnessSpec.executionRoleArn,
|
|
78
|
+
memoryName: harnessSpec.memory?.name,
|
|
79
|
+
containerUri: harnessSpec.containerUri,
|
|
80
|
+
hasDockerfile: !!harnessSpec.dockerfile,
|
|
81
|
+
tools: harnessSpec.tools,
|
|
82
|
+
apiKeyArn: harnessSpec.model?.apiKeyArn,
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Could not read harness.json for "${entry.name}" at ${harnessPath}: ${err instanceof Error ? err.message : err}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
57
91
|
const app = new App();
|
|
58
92
|
|
|
59
93
|
for (const target of targets) {
|
|
@@ -73,6 +107,7 @@ async function main() {
|
|
|
73
107
|
spec,
|
|
74
108
|
mcpSpec,
|
|
75
109
|
credentials,
|
|
110
|
+
harnesses: harnessConfigs.length > 0 ? harnessConfigs : undefined,
|
|
76
111
|
env,
|
|
77
112
|
description: `AgentCore stack for ${spec.name} deployed to ${target.name} (${target.region})`,
|
|
78
113
|
tags: {
|
|
@@ -20,6 +20,18 @@ export interface AgentCoreStackProps extends StackProps {
|
|
|
20
20
|
* Credential provider ARNs from deployed state, keyed by credential name.
|
|
21
21
|
*/
|
|
22
22
|
credentials?: Record<string, { credentialProviderArn: string; clientSecretArn?: string }>;
|
|
23
|
+
/**
|
|
24
|
+
* Harness role configurations. Each entry creates an IAM execution role for a harness.
|
|
25
|
+
*/
|
|
26
|
+
harnesses?: {
|
|
27
|
+
name: string;
|
|
28
|
+
executionRoleArn?: string;
|
|
29
|
+
memoryName?: string;
|
|
30
|
+
containerUri?: string;
|
|
31
|
+
hasDockerfile?: boolean;
|
|
32
|
+
tools?: { type: string; name: string }[];
|
|
33
|
+
apiKeyArn?: string;
|
|
34
|
+
}[];
|
|
23
35
|
}
|
|
24
36
|
|
|
25
37
|
/**
|
|
@@ -35,11 +47,12 @@ export class AgentCoreStack extends Stack {
|
|
|
35
47
|
constructor(scope: Construct, id: string, props: AgentCoreStackProps) {
|
|
36
48
|
super(scope, id, props);
|
|
37
49
|
|
|
38
|
-
const { spec, mcpSpec, credentials } = props;
|
|
50
|
+
const { spec, mcpSpec, credentials, harnesses } = props;
|
|
39
51
|
|
|
40
|
-
// Create AgentCoreApplication with all agents
|
|
52
|
+
// Create AgentCoreApplication with all agents and harness roles
|
|
41
53
|
this.application = new AgentCoreApplication(this, 'Application', {
|
|
42
54
|
spec,
|
|
55
|
+
harnesses,
|
|
43
56
|
});
|
|
44
57
|
|
|
45
58
|
// Create AgentCoreMcp if there are gateways configured
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Standalone invoke script for AgentCore Harness.
|
|
3
|
+
Generated by: agentcore create --with-invoke-script
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
pip install boto3
|
|
7
|
+
export HARNESS_ARN="arn:aws:bedrock-agentcore:<region>:<account>:harness/<harness-id>"
|
|
8
|
+
python invoke.py "Hello, what can you do?"
|
|
9
|
+
python invoke.py --raw-events "Hello"
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
import uuid
|
|
17
|
+
|
|
18
|
+
import boto3
|
|
19
|
+
|
|
20
|
+
# --- Configuration ---
|
|
21
|
+
HARNESS_ARN = os.environ.get("HARNESS_ARN", "{{HARNESS_ARN}}")
|
|
22
|
+
REGION = os.environ.get("AWS_REGION", "{{REGION}}")
|
|
23
|
+
SESSION_ID = os.environ.get("SESSION_ID", str(uuid.uuid4()))
|
|
24
|
+
|
|
25
|
+
parser = argparse.ArgumentParser(description="Invoke an AgentCore Harness")
|
|
26
|
+
parser.add_argument("prompt", nargs="?", default="Hello!", help="Prompt to send to the agent")
|
|
27
|
+
parser.add_argument("--raw-events", action="store_true", help="Print raw streaming events as JSON")
|
|
28
|
+
parser.add_argument("--session-id", default=SESSION_ID, help="Session ID for conversation continuity")
|
|
29
|
+
args = parser.parse_args()
|
|
30
|
+
|
|
31
|
+
client = boto3.client("bedrock-agentcore", region_name=REGION)
|
|
32
|
+
|
|
33
|
+
response = client.invoke_harness(
|
|
34
|
+
harnessArn=HARNESS_ARN,
|
|
35
|
+
runtimeSessionId=args.session_id,
|
|
36
|
+
messages=[
|
|
37
|
+
{
|
|
38
|
+
"role": "user",
|
|
39
|
+
"content": [{"text": args.prompt}],
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
for event in response["stream"]:
|
|
45
|
+
if args.raw_events:
|
|
46
|
+
print(json.dumps(event, default=str))
|
|
47
|
+
else:
|
|
48
|
+
if "contentBlockStart" in event:
|
|
49
|
+
start = event["contentBlockStart"].get("start", {})
|
|
50
|
+
if "toolUse" in start:
|
|
51
|
+
tool = start["toolUse"]
|
|
52
|
+
print(f"\n🔧 Tool: {tool.get('name', 'unknown')}", flush=True)
|
|
53
|
+
elif "contentBlockDelta" in event:
|
|
54
|
+
delta = event["contentBlockDelta"].get("delta", {})
|
|
55
|
+
if "text" in delta:
|
|
56
|
+
print(delta["text"], end="", flush=True)
|
|
57
|
+
elif "messageStop" in event:
|
|
58
|
+
stop_reason = event["messageStop"].get("stopReason", "")
|
|
59
|
+
if stop_reason == "end_turn":
|
|
60
|
+
print()
|
|
61
|
+
elif "metadata" in event:
|
|
62
|
+
usage = event["metadata"].get("usage", {})
|
|
63
|
+
metrics = event["metadata"].get("metrics", {})
|
|
64
|
+
latency = metrics.get("latencyMs", 0) / 1000
|
|
65
|
+
print(
|
|
66
|
+
f"\n⚡ {usage.get('inputTokens', 0)} in · "
|
|
67
|
+
f"{usage.get('outputTokens', 0)} out · "
|
|
68
|
+
f"{latency:.1f}s",
|
|
69
|
+
file=sys.stderr,
|
|
70
|
+
)
|
|
71
|
+
elif "internalServerException" in event:
|
|
72
|
+
print(f"\nError: {event['internalServerException']}", file=sys.stderr)
|
|
73
|
+
|
|
74
|
+
print(f"\n🔗 Session: {args.session_id}", file=sys.stderr)
|
|
@@ -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=
|
|
78
|
+
model="gemini-2.5-flash",
|
|
17
79
|
name="{{ name }}",
|
|
18
80
|
description="A helpful assistant that can use tools.",
|
|
19
|
-
instruction=
|
|
20
|
-
tools=
|
|
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=
|
|
85
|
+
graph = create_react_agent(model, tools=tools, prompt=SYSTEM_PROMPT)
|
|
23
86
|
|
|
24
87
|
|
|
25
88
|
class LangGraphA2AExecutor(AgentExecutor):
|