Skip to content

Commit f2f27fa

Browse files
committed
Add container agent support
- Add Container as a build type for agents (create, add, dev, deploy, invoke, package) - Add Dockerfile and dockerignore templates for Python container agents - Add container dev server with Docker build, run, volume mount, and hot-reload - Add container packaging with Docker runtime detection and validation - Add Docker prerequisite check and runtime detection utility - Wire userId (default: "default-user") through invoke flow for container auth - Log userId in invoke request logs - Upgrade vended @aws/agentcore-cdk to ^0.1.0-alpha.2 - Fix eslint require-await errors in codezip-dev-server and container packaging - Simplify BaseRenderer to use copyAndRenderDir for container templates
1 parent 567fdef commit f2f27fa

56 files changed

Lines changed: 1094 additions & 337 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ workdir-tmp/
5858

5959
# Bun
6060
bun.lock
61+
62+
.agentreview

src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ exports[`Assets Directory Snapshots > CDK assets > cdk/cdk/package.json should m
280280
"typescript": "~5.9.3"
281281
},
282282
"dependencies": {
283-
"@aws/agentcore-cdk": "^0.1.0-alpha.1",
283+
"@aws/agentcore-cdk": "^0.1.0-alpha.2",
284284
"aws-cdk-lib": "2.234.1",
285285
"constructs": "^10.0.0"
286286
}
@@ -356,6 +356,8 @@ exports[`Assets Directory Snapshots > File listing > should match the expected f
356356
"cdk/package.json",
357357
"cdk/test/cdk.test.ts",
358358
"cdk/tsconfig.json",
359+
"container/python/Dockerfile",
360+
"container/python/dockerignore.template",
359361
"mcp/python-lambda/README.md",
360362
"mcp/python-lambda/handler.py",
361363
"mcp/python-lambda/pyproject.toml",

src/assets/cdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"typescript": "~5.9.3"
2424
},
2525
"dependencies": {
26-
"@aws/agentcore-cdk": "^0.1.0-alpha.1",
26+
"@aws/agentcore-cdk": "^0.1.0-alpha.2",
2727
"aws-cdk-lib": "2.234.1",
2828
"constructs": "^10.0.0"
2929
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
2+
3+
WORKDIR /app
4+
5+
ENV UV_SYSTEM_PYTHON=1 \
6+
UV_COMPILE_BYTECODE=1 \
7+
UV_NO_PROGRESS=1 \
8+
PYTHONUNBUFFERED=1 \
9+
DOCKER_CONTAINER=1
10+
11+
COPY pyproject.toml uv.lock* ./
12+
RUN uv pip install -r pyproject.toml
13+
14+
RUN useradd -m -u 1000 bedrock_agentcore
15+
USER bedrock_agentcore
16+
17+
COPY . .
18+
19+
EXPOSE 8080 8000 9000
20+
21+
CMD ["opentelemetry-instrument", "python", "-m", "{{entrypoint}}"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*.egg-info/
5+
.venv/
6+
dist/
7+
build/
8+
9+
# IDE
10+
.vscode/
11+
.idea/
12+
13+
# Testing
14+
.pytest_cache/
15+
.coverage
16+
htmlcov/
17+
18+
# AgentCore build artifacts
19+
.agentcore/artifacts/
20+
*.zip

src/cli/aws/agentcore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ export interface SSELogger {
1010
logSSEEvent(rawLine: string): void;
1111
}
1212

13+
/** Default user ID sent with invocations. Container agents require this to obtain workload access tokens. */
14+
export const DEFAULT_RUNTIME_USER_ID = 'default-user';
15+
1316
export interface InvokeAgentRuntimeOptions {
1417
region: string;
1518
runtimeArn: string;
1619
payload: string;
1720
sessionId?: string;
21+
/** User ID for the runtime invocation. Defaults to 'default-user'. Required for Container agents using identity providers. */
22+
userId?: string;
1823
/** Optional logger for SSE event debugging */
1924
logger?: SSELogger;
2025
}
@@ -112,6 +117,7 @@ export async function invokeAgentRuntimeStreaming(options: InvokeAgentRuntimeOpt
112117
contentType: 'application/json',
113118
accept: 'application/json',
114119
runtimeSessionId: options.sessionId,
120+
runtimeUserId: options.userId ?? DEFAULT_RUNTIME_USER_ID,
115121
});
116122

117123
const response = await client.send(command);
@@ -207,6 +213,7 @@ export async function invokeAgentRuntime(options: InvokeAgentRuntimeOptions): Pr
207213
contentType: 'application/json',
208214
accept: 'application/json',
209215
runtimeSessionId: options.sessionId,
216+
runtimeUserId: options.userId ?? DEFAULT_RUNTIME_USER_ID,
210217
});
211218

212219
const response = await client.send(command);

src/cli/aws/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export {
1414
type GetAgentRuntimeStatusOptions,
1515
} from './agentcore-control';
1616
export {
17+
DEFAULT_RUNTIME_USER_ID,
1718
invokeAgentRuntime,
1819
invokeAgentRuntimeStreaming,
1920
stopRuntimeSession,

src/cli/commands/add/actions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { APP_DIR, ConfigIO, MCP_APP_SUBDIR, NoProjectError, findConfigRoot, setEnvVar } from '../../../lib';
22
import type {
33
AgentEnvSpec,
4+
BuildType,
45
DirectoryPath,
56
FilePath,
67
GatewayAuthorizerType,
@@ -36,6 +37,7 @@ import { dirname, join } from 'path';
3637
export interface ValidatedAddAgentOptions {
3738
name: string;
3839
type: 'create' | 'byo';
40+
buildType: BuildType;
3941
language: TargetLanguage;
4042
framework: SDKFramework;
4143
modelProvider: ModelProvider;
@@ -113,6 +115,7 @@ async function handleCreatePath(options: ValidatedAddAgentOptions, configBaseDir
113115

114116
const generateConfig = {
115117
projectName: options.name,
118+
buildType: options.buildType,
116119
sdk: options.framework,
117120
modelProvider: options.modelProvider,
118121
memory: options.memory!,
@@ -186,7 +189,7 @@ async function handleByoPath(
186189
const agent: AgentEnvSpec = {
187190
type: 'AgentCoreRuntime',
188191
name: options.name,
189-
build: 'CodeZip',
192+
build: options.buildType,
190193
entrypoint: (options.entrypoint ?? 'main.py') as FilePath,
191194
codeLocation: codeLocation as DirectoryPath,
192195
runtimeVersion: 'PYTHON_3_12',

src/cli/commands/add/command.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async function handleAddAgentCLI(options: AddAgentOptions): Promise<void> {
3434
const result = await handleAddAgent({
3535
name: options.name!,
3636
type: options.type! ?? 'create',
37+
buildType: (options.build as 'CodeZip' | 'Container') ?? 'CodeZip',
3738
language: options.language!,
3839
framework: options.framework!,
3940
modelProvider: options.modelProvider!,
@@ -217,6 +218,7 @@ export function registerAdd(program: Command) {
217218
.description('Add an agent to the project')
218219
.option('--name <name>', 'Agent name (start with letter, alphanumeric only, max 64 chars) [non-interactive]')
219220
.option('--type <type>', 'Agent type: create or byo [non-interactive]', 'create')
221+
.option('--build <type>', 'Build type: CodeZip or Container (default: CodeZip) [non-interactive]')
220222
.option('--language <lang>', 'Language: Python (create), or Python/TypeScript/Other (BYO) [non-interactive]')
221223
.option(
222224
'--framework <fw>',

src/cli/commands/add/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { MemoryOption } from '../../tui/screens/generate/types';
55
export interface AddAgentOptions {
66
name?: string;
77
type?: 'create' | 'byo';
8+
build?: string;
89
language?: TargetLanguage;
910
framework?: SDKFramework;
1011
modelProvider?: ModelProvider;

0 commit comments

Comments
 (0)