@aws/agentcore 0.15.0 → 0.17.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 +5 -0
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +68 -7
- package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +2 -2
- package/dist/assets/cdk/bin/cdk.ts +37 -0
- package/dist/assets/cdk/lib/cdk-stack.ts +24 -5
- package/dist/assets/container/python/Dockerfile +1 -1
- package/dist/assets/harness/invoke.py.template +74 -0
- package/dist/assets/python/a2a/googleadk/base/pyproject.toml +1 -1
- package/dist/assets/python/a2a/langchain_langgraph/base/pyproject.toml +1 -0
- package/dist/assets/python/agui/googleadk/base/pyproject.toml +1 -1
- package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +1 -0
- package/dist/assets/python/http/googleadk/base/pyproject.toml +1 -0
- package/dist/assets/python/http/langchain_langgraph/base/pyproject.toml +1 -0
- package/dist/cli/index.mjs +524 -472
- 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/types.d.ts +6 -0
- package/dist/lib/errors/types.d.ts.map +1 -1
- package/dist/lib/errors/types.js +10 -1
- package/dist/lib/errors/types.js.map +1 -1
- package/dist/lib/packaging/helpers.d.ts.map +1 -1
- package/dist/lib/packaging/helpers.js +6 -10
- package/dist/lib/packaging/helpers.js.map +1 -1
- package/dist/lib/result.d.ts +15 -0
- package/dist/lib/result.d.ts.map +1 -1
- package/dist/lib/result.js +12 -0
- package/dist/lib/result.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/global-config.d.ts +28 -21
- package/dist/lib/schemas/io/global-config.d.ts.map +1 -1
- package/dist/lib/schemas/io/global-config.js +57 -28
- package/dist/lib/schemas/io/global-config.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/lib/utils/index.d.ts +1 -1
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +2 -1
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/zod.d.ts +16 -0
- package/dist/lib/utils/zod.d.ts.map +1 -1
- package/dist/lib/utils/zod.js +45 -0
- package/dist/lib/utils/zod.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +11 -0
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/agentcore-project.js +21 -2
- 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/harness.d.ts +363 -0
- package/dist/schema/schemas/primitives/harness.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/harness.js +261 -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 +17 -1
- package/dist/schema/schemas/primitives/index.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +9 -8
- package/scripts/bump-version.ts +1 -1
- package/scripts/bundle.mjs +86 -9
package/README.md
CHANGED
|
@@ -194,6 +194,11 @@ Projects use JSON schema files in the `agentcore/` directory:
|
|
|
194
194
|
- [Local Development](docs/local-development.md) - Dev server and debugging
|
|
195
195
|
- [Feedback](docs/feedback.md) - Submit feedback from your terminal
|
|
196
196
|
|
|
197
|
+
## Examples
|
|
198
|
+
|
|
199
|
+
See the [AgentCore Samples](https://github.com/awslabs/agentcore-samples) repository for end-to-end examples using the
|
|
200
|
+
CLI, including multi-agent workflows, MCP gateway targets, and framework integrations.
|
|
201
|
+
|
|
197
202
|
## Feedback & Issues
|
|
198
203
|
|
|
199
204
|
Have a quick comment or suggestion? Send it from your terminal:
|
|
@@ -99,6 +99,42 @@ async function main() {
|
|
|
99
99
|
throw new Error('No deployment targets configured. Please define targets in agentcore/aws-targets.json');
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
// Read harness configs for role creation.
|
|
103
|
+
const projectRoot = path.resolve(configRoot, '..');
|
|
104
|
+
const harnessConfigs: {
|
|
105
|
+
name: string;
|
|
106
|
+
executionRoleArn?: string;
|
|
107
|
+
memoryName?: string;
|
|
108
|
+
containerUri?: string;
|
|
109
|
+
hasDockerfile?: boolean;
|
|
110
|
+
dockerfile?: string;
|
|
111
|
+
codeLocation?: string;
|
|
112
|
+
tools?: { type: string; name: string }[];
|
|
113
|
+
apiKeyArn?: string;
|
|
114
|
+
}[] = [];
|
|
115
|
+
for (const entry of specAny.harnesses ?? []) {
|
|
116
|
+
const harnessDir = path.resolve(projectRoot, entry.path);
|
|
117
|
+
const harnessPath = path.resolve(harnessDir, 'harness.json');
|
|
118
|
+
try {
|
|
119
|
+
const harnessSpec = JSON.parse(fs.readFileSync(harnessPath, 'utf-8'));
|
|
120
|
+
harnessConfigs.push({
|
|
121
|
+
name: entry.name,
|
|
122
|
+
executionRoleArn: harnessSpec.executionRoleArn,
|
|
123
|
+
memoryName: harnessSpec.memory?.name,
|
|
124
|
+
containerUri: harnessSpec.containerUri,
|
|
125
|
+
hasDockerfile: !!harnessSpec.dockerfile,
|
|
126
|
+
dockerfile: harnessSpec.dockerfile,
|
|
127
|
+
codeLocation: harnessSpec.dockerfile ? harnessDir : undefined,
|
|
128
|
+
tools: harnessSpec.tools,
|
|
129
|
+
apiKeyArn: harnessSpec.model?.apiKeyArn,
|
|
130
|
+
});
|
|
131
|
+
} catch (err) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
\`Could not read harness.json for "\${entry.name}" at \${harnessPath}: \${err instanceof Error ? err.message : err}\`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
102
138
|
const app = new App();
|
|
103
139
|
|
|
104
140
|
for (const target of targets) {
|
|
@@ -118,6 +154,7 @@ async function main() {
|
|
|
118
154
|
spec,
|
|
119
155
|
mcpSpec,
|
|
120
156
|
credentials,
|
|
157
|
+
harnesses: harnessConfigs.length > 0 ? harnessConfigs : undefined,
|
|
121
158
|
env,
|
|
122
159
|
description: \`AgentCore stack for \${spec.name} deployed to \${target.name} (\${target.region})\`,
|
|
123
160
|
tags: {
|
|
@@ -265,6 +302,18 @@ exports[`Assets Directory Snapshots > CDK assets > cdk/cdk/lib/cdk-stack.ts shou
|
|
|
265
302
|
import { CfnOutput, Stack, type StackProps } from 'aws-cdk-lib';
|
|
266
303
|
import { Construct } from 'constructs';
|
|
267
304
|
|
|
305
|
+
export interface HarnessConfig {
|
|
306
|
+
name: string;
|
|
307
|
+
executionRoleArn?: string;
|
|
308
|
+
memoryName?: string;
|
|
309
|
+
containerUri?: string;
|
|
310
|
+
hasDockerfile?: boolean;
|
|
311
|
+
dockerfile?: string;
|
|
312
|
+
codeLocation?: string;
|
|
313
|
+
tools?: { type: string; name: string }[];
|
|
314
|
+
apiKeyArn?: string;
|
|
315
|
+
}
|
|
316
|
+
|
|
268
317
|
export interface AgentCoreStackProps extends StackProps {
|
|
269
318
|
/**
|
|
270
319
|
* The AgentCore project specification containing agents, memories, and credentials.
|
|
@@ -278,6 +327,10 @@ export interface AgentCoreStackProps extends StackProps {
|
|
|
278
327
|
* Credential provider ARNs from deployed state, keyed by credential name.
|
|
279
328
|
*/
|
|
280
329
|
credentials?: Record<string, { credentialProviderArn: string; clientSecretArn?: string }>;
|
|
330
|
+
/**
|
|
331
|
+
* Harness role configurations.
|
|
332
|
+
*/
|
|
333
|
+
harnesses?: HarnessConfig[];
|
|
281
334
|
}
|
|
282
335
|
|
|
283
336
|
/**
|
|
@@ -293,12 +346,15 @@ export class AgentCoreStack extends Stack {
|
|
|
293
346
|
constructor(scope: Construct, id: string, props: AgentCoreStackProps) {
|
|
294
347
|
super(scope, id, props);
|
|
295
348
|
|
|
296
|
-
const { spec, mcpSpec, credentials } = props;
|
|
349
|
+
const { spec, mcpSpec, credentials, harnesses } = props;
|
|
297
350
|
|
|
298
|
-
// Create AgentCoreApplication with all agents
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
351
|
+
// Create AgentCoreApplication with all agents and harness roles
|
|
352
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
353
|
+
const appProps: Record<string, unknown> = { spec };
|
|
354
|
+
if (harnesses?.length) {
|
|
355
|
+
appProps.harnesses = harnesses;
|
|
356
|
+
}
|
|
357
|
+
this.application = new AgentCoreApplication(this, 'Application', appProps as any);
|
|
302
358
|
|
|
303
359
|
// Create AgentCoreMcp if there are gateways configured
|
|
304
360
|
if (mcpSpec?.agentCoreGateways && mcpSpec.agentCoreGateways.length > 0) {
|
|
@@ -454,6 +510,7 @@ exports[`Assets Directory Snapshots > File listing > should match the expected f
|
|
|
454
510
|
"evaluators/python-lambda/execution-role-policy.json",
|
|
455
511
|
"evaluators/python-lambda/lambda_function.py",
|
|
456
512
|
"evaluators/python-lambda/pyproject.toml",
|
|
513
|
+
"harness/invoke.py.template",
|
|
457
514
|
"mcp/python-lambda/README.md",
|
|
458
515
|
"mcp/python-lambda/handler.py",
|
|
459
516
|
"mcp/python-lambda/pyproject.toml",
|
|
@@ -1185,7 +1242,7 @@ dependencies = [
|
|
|
1185
1242
|
"aws-opentelemetry-distro",
|
|
1186
1243
|
"bedrock-agentcore[a2a] >= 1.0.3",
|
|
1187
1244
|
"google-adk >= 1.0.0, < 2.0.0",
|
|
1188
|
-
"google-genai >= 1.0.0",
|
|
1245
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
1189
1246
|
]
|
|
1190
1247
|
|
|
1191
1248
|
[tool.hatch.build.targets.wheel]
|
|
@@ -1546,6 +1603,7 @@ dependencies = [
|
|
|
1546
1603
|
{{#if (eq modelProvider "Anthropic")}}"langchain-anthropic >= 0.3.0",
|
|
1547
1604
|
{{/if}}{{#if (eq modelProvider "Bedrock")}}"langchain-aws >= 0.2.0",
|
|
1548
1605
|
{{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
|
|
1606
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
1549
1607
|
{{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
|
|
1550
1608
|
{{/if}}"aws-opentelemetry-distro",
|
|
1551
1609
|
"opentelemetry-instrumentation-langchain >= 0.59.0",
|
|
@@ -2133,7 +2191,7 @@ dependencies = [
|
|
|
2133
2191
|
"bedrock-agentcore >= 1.0.3",
|
|
2134
2192
|
"fastapi >= 0.115.12",
|
|
2135
2193
|
"google-adk >= 1.16.0, < 2.0.0",
|
|
2136
|
-
"google-genai >= 1.0.0",
|
|
2194
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
2137
2195
|
"opentelemetry-distro",
|
|
2138
2196
|
"opentelemetry-exporter-otlp",
|
|
2139
2197
|
"uvicorn >= 0.34.3",
|
|
@@ -2442,6 +2500,7 @@ dependencies = [
|
|
|
2442
2500
|
{{#if (eq modelProvider "Anthropic")}}"langchain-anthropic >= 0.3.0",
|
|
2443
2501
|
{{/if}}{{#if (eq modelProvider "Bedrock")}}"langchain-aws >= 0.2.0",
|
|
2444
2502
|
{{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
|
|
2503
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
2445
2504
|
{{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
|
|
2446
2505
|
{{/if}}"aws-opentelemetry-distro",
|
|
2447
2506
|
"opentelemetry-instrumentation-langchain >= 0.59.0",
|
|
@@ -3617,6 +3676,7 @@ dependencies = [
|
|
|
3617
3676
|
"opentelemetry-distro",
|
|
3618
3677
|
"opentelemetry-exporter-otlp",
|
|
3619
3678
|
"google-adk >= 1.17.0, < 2.0.0",
|
|
3679
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
3620
3680
|
"bedrock-agentcore >= 1.0.3",
|
|
3621
3681
|
"botocore[crt] >= 1.35.0",
|
|
3622
3682
|
{{#if hasGateway}}{{#if (includes gatewayAuthTypes "AWS_IAM")}}"mcp-proxy-for-aws >= 1.1.0",
|
|
@@ -4145,6 +4205,7 @@ dependencies = [
|
|
|
4145
4205
|
{{/if}}
|
|
4146
4206
|
{{#if (eq modelProvider "Gemini")}}
|
|
4147
4207
|
"langchain-google-genai >= 3.0.3",
|
|
4208
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
4148
4209
|
{{/if}}
|
|
4149
4210
|
{{#if hasGateway}}{{#if (includes gatewayAuthTypes "AWS_IAM")}}"mcp-proxy-for-aws >= 1.1.0",
|
|
4150
4211
|
{{/if}}{{/if}}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
2
|
|
|
3
3
|
exports[`Dockerfile enableOtel rendering > renders opentelemetry-instrument CMD when enableOtel is true > Dockerfile-enableOtel-true 1`] = `
|
|
4
|
-
"FROM public.ecr.aws/docker/library/python:3.12-slim-
|
|
4
|
+
"FROM public.ecr.aws/docker/library/python:3.12-slim-trixie
|
|
5
5
|
|
|
6
6
|
RUN pip install --no-cache-dir uv
|
|
7
7
|
|
|
@@ -41,7 +41,7 @@ CMD ["opentelemetry-instrument", "python", "-m", "main"]
|
|
|
41
41
|
`;
|
|
42
42
|
|
|
43
43
|
exports[`Dockerfile enableOtel rendering > renders plain python CMD when enableOtel is false > Dockerfile-enableOtel-false 1`] = `
|
|
44
|
-
"FROM public.ecr.aws/docker/library/python:3.12-slim-
|
|
44
|
+
"FROM public.ecr.aws/docker/library/python:3.12-slim-trixie
|
|
45
45
|
|
|
46
46
|
RUN pip install --no-cache-dir uv
|
|
47
47
|
|
|
@@ -54,6 +54,42 @@ 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
|
+
const projectRoot = path.resolve(configRoot, '..');
|
|
59
|
+
const harnessConfigs: {
|
|
60
|
+
name: string;
|
|
61
|
+
executionRoleArn?: string;
|
|
62
|
+
memoryName?: string;
|
|
63
|
+
containerUri?: string;
|
|
64
|
+
hasDockerfile?: boolean;
|
|
65
|
+
dockerfile?: string;
|
|
66
|
+
codeLocation?: string;
|
|
67
|
+
tools?: { type: string; name: string }[];
|
|
68
|
+
apiKeyArn?: string;
|
|
69
|
+
}[] = [];
|
|
70
|
+
for (const entry of specAny.harnesses ?? []) {
|
|
71
|
+
const harnessDir = path.resolve(projectRoot, entry.path);
|
|
72
|
+
const harnessPath = path.resolve(harnessDir, '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
|
+
dockerfile: harnessSpec.dockerfile,
|
|
82
|
+
codeLocation: harnessSpec.dockerfile ? harnessDir : undefined,
|
|
83
|
+
tools: harnessSpec.tools,
|
|
84
|
+
apiKeyArn: harnessSpec.model?.apiKeyArn,
|
|
85
|
+
});
|
|
86
|
+
} catch (err) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Could not read harness.json for "${entry.name}" at ${harnessPath}: ${err instanceof Error ? err.message : err}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
57
93
|
const app = new App();
|
|
58
94
|
|
|
59
95
|
for (const target of targets) {
|
|
@@ -73,6 +109,7 @@ async function main() {
|
|
|
73
109
|
spec,
|
|
74
110
|
mcpSpec,
|
|
75
111
|
credentials,
|
|
112
|
+
harnesses: harnessConfigs.length > 0 ? harnessConfigs : undefined,
|
|
76
113
|
env,
|
|
77
114
|
description: `AgentCore stack for ${spec.name} deployed to ${target.name} (${target.region})`,
|
|
78
115
|
tags: {
|
|
@@ -7,6 +7,18 @@ import {
|
|
|
7
7
|
import { CfnOutput, Stack, type StackProps } from 'aws-cdk-lib';
|
|
8
8
|
import { Construct } from 'constructs';
|
|
9
9
|
|
|
10
|
+
export interface HarnessConfig {
|
|
11
|
+
name: string;
|
|
12
|
+
executionRoleArn?: string;
|
|
13
|
+
memoryName?: string;
|
|
14
|
+
containerUri?: string;
|
|
15
|
+
hasDockerfile?: boolean;
|
|
16
|
+
dockerfile?: string;
|
|
17
|
+
codeLocation?: string;
|
|
18
|
+
tools?: { type: string; name: string }[];
|
|
19
|
+
apiKeyArn?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
export interface AgentCoreStackProps extends StackProps {
|
|
11
23
|
/**
|
|
12
24
|
* The AgentCore project specification containing agents, memories, and credentials.
|
|
@@ -20,6 +32,10 @@ export interface AgentCoreStackProps extends StackProps {
|
|
|
20
32
|
* Credential provider ARNs from deployed state, keyed by credential name.
|
|
21
33
|
*/
|
|
22
34
|
credentials?: Record<string, { credentialProviderArn: string; clientSecretArn?: string }>;
|
|
35
|
+
/**
|
|
36
|
+
* Harness role configurations.
|
|
37
|
+
*/
|
|
38
|
+
harnesses?: HarnessConfig[];
|
|
23
39
|
}
|
|
24
40
|
|
|
25
41
|
/**
|
|
@@ -35,12 +51,15 @@ export class AgentCoreStack extends Stack {
|
|
|
35
51
|
constructor(scope: Construct, id: string, props: AgentCoreStackProps) {
|
|
36
52
|
super(scope, id, props);
|
|
37
53
|
|
|
38
|
-
const { spec, mcpSpec, credentials } = props;
|
|
54
|
+
const { spec, mcpSpec, credentials, harnesses } = props;
|
|
39
55
|
|
|
40
|
-
// Create AgentCoreApplication with all agents
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
// Create AgentCoreApplication with all agents and harness roles
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
const appProps: Record<string, unknown> = { spec };
|
|
59
|
+
if (harnesses?.length) {
|
|
60
|
+
appProps.harnesses = harnesses;
|
|
61
|
+
}
|
|
62
|
+
this.application = new AgentCoreApplication(this, 'Application', appProps as any);
|
|
44
63
|
|
|
45
64
|
// Create AgentCoreMcp if there are gateways configured
|
|
46
65
|
if (mcpSpec?.agentCoreGateways && mcpSpec.agentCoreGateways.length > 0) {
|
|
@@ -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)
|
|
@@ -13,6 +13,7 @@ dependencies = [
|
|
|
13
13
|
{{#if (eq modelProvider "Anthropic")}}"langchain-anthropic >= 0.3.0",
|
|
14
14
|
{{/if}}{{#if (eq modelProvider "Bedrock")}}"langchain-aws >= 0.2.0",
|
|
15
15
|
{{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
|
|
16
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
16
17
|
{{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
|
|
17
18
|
{{/if}}"aws-opentelemetry-distro",
|
|
18
19
|
"opentelemetry-instrumentation-langchain >= 0.59.0",
|
|
@@ -14,7 +14,7 @@ dependencies = [
|
|
|
14
14
|
"bedrock-agentcore >= 1.0.3",
|
|
15
15
|
"fastapi >= 0.115.12",
|
|
16
16
|
"google-adk >= 1.16.0, < 2.0.0",
|
|
17
|
-
"google-genai >= 1.0.0",
|
|
17
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
18
18
|
"opentelemetry-distro",
|
|
19
19
|
"opentelemetry-exporter-otlp",
|
|
20
20
|
"uvicorn >= 0.34.3",
|
|
@@ -14,6 +14,7 @@ dependencies = [
|
|
|
14
14
|
{{#if (eq modelProvider "Anthropic")}}"langchain-anthropic >= 0.3.0",
|
|
15
15
|
{{/if}}{{#if (eq modelProvider "Bedrock")}}"langchain-aws >= 0.2.0",
|
|
16
16
|
{{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
|
|
17
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
17
18
|
{{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
|
|
18
19
|
{{/if}}"aws-opentelemetry-distro",
|
|
19
20
|
"opentelemetry-instrumentation-langchain >= 0.59.0",
|
|
@@ -12,6 +12,7 @@ dependencies = [
|
|
|
12
12
|
"opentelemetry-distro",
|
|
13
13
|
"opentelemetry-exporter-otlp",
|
|
14
14
|
"google-adk >= 1.17.0, < 2.0.0",
|
|
15
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
15
16
|
"bedrock-agentcore >= 1.0.3",
|
|
16
17
|
"botocore[crt] >= 1.35.0",
|
|
17
18
|
{{#if hasGateway}}{{#if (includes gatewayAuthTypes "AWS_IAM")}}"mcp-proxy-for-aws >= 1.1.0",
|
|
@@ -28,6 +28,7 @@ dependencies = [
|
|
|
28
28
|
{{/if}}
|
|
29
29
|
{{#if (eq modelProvider "Gemini")}}
|
|
30
30
|
"langchain-google-genai >= 3.0.3",
|
|
31
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
31
32
|
{{/if}}
|
|
32
33
|
{{#if hasGateway}}{{#if (includes gatewayAuthTypes "AWS_IAM")}}"mcp-proxy-for-aws >= 1.1.0",
|
|
33
34
|
{{/if}}{{/if}}
|