Skip to content

Deploy strands#1991

Open
afarntrog wants to merge 11 commits intostrands-agents:mainfrom
afarntrog:deploy_strands
Open

Deploy strands#1991
afarntrog wants to merge 11 commits intostrands-agents:mainfrom
afarntrog:deploy_strands

Conversation

@afarntrog
Copy link
Copy Markdown
Contributor

Description

Deploying a Strands agent to the cloud today requires writing a service wrapper, packaging code and dependencies, provisioning infrastructure, and tracking deployed resources — none of which has anything to do with the agent itself. This PR adds an experimental deploy() function that takes a Strands Agent and deploys it to AWS Bedrock AgentCore in a single call.

from strands import Agent
from strands.experimental.deploy import deploy

agent = Agent(name="my-agent", tools=[my_tool])
result = deploy(agent)
print(result.agent_runtime_arn)

The module captures the caller's source file, strips the deploy() call via AST transformation, appends a BedrockAgentCoreApp entrypoint wrapper, and delegates provisioning to the bedrock-agentcore-starter-toolkit. Deployment state is persisted to .strands_deploy/state.json so subsequent calls update rather than duplicate resources. A DeployTarget ABC provides a strategy interface for future targets (Lambda, ECS, etc.) beyond the initial AgentCore implementation.

The feature is exposed under strands.experimental with an optional dependency (pip install 'strands-agents[deploy]') to allow the API to evolve before graduating to agent.deploy() on the Agent class.

Related Issues

Documentation PR

Type of Change

New feature

Testing

Added unit tests across five test files in tests/strands/experimental/deploy/:

  • test_agentcore.py — AgentCoreTarget validation, deploy (create and update), region resolution, destroy lifecycle, and user agent injection (idempotency, silent failure)

  • test_constants.py — Python runtime mapping and AgentCore name prefixing

  • test_deploy_integration.py — Top-level deploy() function: config construction, name sanitization, environment variable passthrough, unknown target rejection, and import verification

  • test_packaging.py — AST-based deploy call stripping, __main__ block removal, non-deploy code preservation, and error on missing caller source

  • test_state.py — StateManager save/load roundtrip, atomic writes, created_at preservation on update, multi-deployment coexistence, delete, version stamping, and corrupted file handling

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • 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.

Introduce `agent.deploy()` and `agent.destroy()` methods that package
agent code, provision cloud infrastructure (IAM roles, S3 buckets,
AgentCore runtimes), and return a live endpoint — all from Python
without Terraform, CloudFormation, or Docker.

Key components:
- AgentCore deployment target with create/update/destroy lifecycle
- Automatic code packaging with dependency bundling for Lambda-style runtimes
- File-based state management to track deployed resources
- Support for custom IAM policies, VPC configuration, and region selection
- Protocol-based target abstraction for future deployment backends

Includes comprehensive unit tests and documentation with usage examples
for rapid prototyping, CI/CD integration, and multi-agent deployments.
…toolkit

Replace custom IAM, S3, runtime creation, polling, and endpoint
management logic with the bedrock-agentcore-starter-toolkit Runtime
class. This removes significant boilerplate from _agentcore.py,
_packaging.py, and _constants.py, and adds a new 'deploy' optional
dependency group. Tests are updated to mock the toolkit's Runtime
class instead of individual boto3 clients.
Relocate the deploy module from strands.deploy to strands.experimental.deploy
to signal its experimental status. Remove the agent.deploy() convenience method
and top-level deploy export. Update packaging excludes for new artifact paths
(.strands_deploy/, .bedrock_agentcore.yaml, dependencies.*), and add a fallback
for unsupported Python versions to use the highest supported runtime.
…onfig serialization

Replace the template-based agent config extraction approach with AST-based
source capture that copies the caller's actual source file, strips the
`deploy()` call, and appends an AgentCore wrapper. This preserves tools,
plugins, hooks, and all Agent parameters without needing serialization.

- Add `_find_caller_info()` to walk the call stack and locate the caller's
  source file and agent variable name
- Add `_DeployStripper` AST transformer to remove deploy-related imports
  and calls from the packaged source
- Update `_build_zip_bundle` to package all CWD files and use the
  caller's source as the entrypoint
- Improve deploy() docstring to document packaging, imports, and
  dependency behavior
- Add comprehensive tests for source stripping, caller detection, and
  zip bundling
Add design document 0002-deploy.md describing the `strands.experimental.deploy`
feature that bridges the gap between local agent development and cloud deployment
on AWS Bedrock AgentCore. Covers source capture, entrypoint generation, dependency
resolution, state management, and the path to promoting `agent.deploy()` as a
stable API.
…ckaging code

- Remove `agent_runtime_endpoint_arn` and `role_arn` from DeployResult
- Remove `create_code_zip` function and related imports from _packaging.py
- Remove `auth` config option from DeployConfig in tests
- Update agent name prefix from `strands-` to `strands_` in tests
- Clean up deploy output to no longer print endpoint ARN
Remove PACKAGING_EXCLUDES constant, _should_exclude function, and
associated tests as they are no longer needed for agent deployment
packaging. Update module docstring to reflect reduced scope.
…nstants

Replace all print() calls with structured logger.info() using key=value
format for better observability. Extract hardcoded strings (entrypoint
filename, base requirements, deployment type, build artifacts, runtime
name) into named constants in _constants.py to improve maintainability
and reduce duplication.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant