Skip to content

feat(deploy): Run the boxed agent in a box on AgentCore Runtime - #2791

Draft
mquang-amazon wants to merge 4 commits into
dev-box-runfrom
deploy-box-runtime
Draft

mquang-amazon wants to merge 4 commits into
dev-box-runfrom
deploy-box-runtime

Conversation

@mquang-amazon

Copy link
Copy Markdown
Contributor

Description

agentcore deploy runs the agent that agentcore create boxes in a box on AgentCore Runtime. Before this, only agentcore dev ran it in a box (#2790). Nothing shipped box to the Runtime or started it there.

  • CodeZip start scripts: create writes start.py and start.sh into every Python CodeZip template (Strands HTTP/A2A/AG-UI, LangChain, minimal, FastMCP) and sets entrypoint to start.py. The Runtime needs a .py entry point, so start.py hands over to start.sh. start.sh fills in the Runtime profile and runs box run in /tmp/box/workspace. If box fails or the agent does not answer within 22s, it serves main.py without box (the Runtime allows 30s). BOX_START_DISABLE=1 skips box.
  • Container image: the Strands container template's Dockerfile copies box, its helpers, packs, profile, and start.sh into /opt/box, and its ENTRYPOINT is start.sh. Under agentcore dev (LOCAL_DEV=1), start.sh only runs box run with the project's profile, which dev stages (feat(dev): Run CodeZip and container agents with box run #2790).
  • Staging on build and deploy: CdkBackend stages .box-dist/ from AGENTCORE_BOX_SOURCE before synth. That covers each CodeZip runtime whose entry point is start.py and each container whose Dockerfile copies .box-dist/. The Linux build comes from a staging-boxy checkout's target-al2023/, plus the libffi shim for CodeZip. If a boxed runtime has no AGENTCORE_BOX_SOURCE, build fails with an actionable error.
  • Runtime box profile: renderRuntimeBoxProfile renders the profile from agentcore.json. It has no reload. Bedrock is signed with a bare aws://, the default chain, i.e. the execution role. It includes placeholders (@CODE@, @PYTHON@, @PYTHON_PREFIX@, @GATEWAY_BOX_URL@, # @AGENT_ENV@) that start.sh fills in. Only the deployed Memory/Gateway IDs and URLs reach the agent's env. A non-Bedrock provider gets no route yet: on the Runtime its key comes from AgentCore Identity.
  • Memory through the Box gateway: when a boxed runtime has its default Memory, build and deploy add the Box gateway's agentcore passthrough target, bedrock-agentcore.us-west-2, signed with the gateway role. They also write agentcore/box-memory-policy.json (Memory data-plane actions on <project>_*<memory>-*) and list it in the gateway's new additionalPolicies. The raw agentcore.json is patched, as syncRuntimeBuilds does, so unknown fields survive. Running it again changes nothing.
  • Schema: agentCoreGateways[].additionalPolicies, which cannot be combined with executionRoleArn.
  • dev guard: a runtime whose entry point is start.py but has no .box/profile.toml is refused, because start.py runs no agent of its own.

The local (agentcore dev) profile is byte-identical to #2788's for every template and model provider (checked across 29 combinations).

Out of scope (follow-ups): TypeScript CodeZip/container templates (no TS box profile in #2788 yet), and the Bedrock Managed Agents executor box.

Depends on

Related Issue

N/A (box integration)

Documentation PR

Not applicable.

Type of Change

  • New feature

Testing

  • I ran bun test: 4903 pass. 3 fail on this host and also fail on an unmodified base: toolAvailable, requireTool, SourceResolver bytes ... under node
  • bun run test:e2e: not run. A boxed deploy needs AGENTCORE_BOX_SOURCE and the unreleased CDK library
  • I ran bun run typecheck
  • I ran bun run lint:check
  • I ran bun run format:check
  • I ran bun run audit
  • I ran bun run secrets:check
  • I ran bun run build
  • I modified src/assets/ and updated manager.test.ts.snap (new start.py/start.sh, entrypoint: start.py)
  • This PR does not change command.md

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

Templates whose agent calls a model now write "projectType": "box" and a
"box" agentCoreGateways entry to agentcore.json. The CDK library owns the
Box gateway (AWS_IAM, HTTP only) for a Box project; the entry only adds
targets to it. The entry gets a us-west-2 "bedrock" passthrough target
when the agent calls Bedrock (the Bedrock provider, or LiteLLM on a
bedrock/ model). MCP, BMA and empty templates stay as before.

The project schema accepts projectType, with no default, so existing
projects are written back unchanged.

Needs aws/agentcore-l3-cdk-constructs#454 for the CDK library to read
projectType and add the Box gateway.
An MCP server calls no model when created, but its tools, or a model added later, still need a gateway for their outbound calls. mcp-python-fastmcp now writes "projectType": "box" and a box entry with no targets: a template with no model provider gets no Bedrock target.
# Conflicts:
#	src/handlers/project/shortcuts.ts
create wrote a box profile for `agentcore dev`, but a deployed agent ran
unboxed: nothing shipped box to the Runtime or started it there.

create now writes start.py and start.sh into every Python CodeZip
template and sets entrypoint to start.py, and writes start.sh beside the
Strands container template, whose Dockerfile copies box into /opt/box
and starts it. On build and deploy, the CDK backend stages box from
AGENTCORE_BOX_SOURCE (a staging-boxy checkout with an Amazon Linux 2023
build) into the zip's or the image's .box-dist/, with the AgentCore
Runtime profile rendered from agentcore.json: no reload, signed with the
execution role through the default AWS chain, and placeholders that
start.sh fills in with the Runtime's paths and the deployed resources'
variables. If box fails or the agent does not answer in 22s, start.sh
serves the agent without box.

When a boxed runtime has its default Memory, build and deploy add the
Box gateway's `agentcore` passthrough target and route the agent's
Memory calls through it, and write agentcore/box-memory-policy.json,
listed in the gateway's new additionalPolicies, so the gateway role may
call Memory. The local profile is unchanged byte for byte.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant