Skip to content

Commit f0e1af7

Browse files
authored
feat: add import from Bedrock Agents to add agent and create flows (#563)
* feat: add Import from Bedrock Agents to add agent and create flows Adds a third option in the "add agent" flow that fetches a Bedrock Agent's configuration via AWS SDK and translates it into runnable Strands or LangChain/LangGraph Python code, wired into the standard AgentCore project structure. Supports action groups, knowledge bases, multi-agent collaboration, code interpreter, guardrails, prompt overrides, and memory configuration. Both interactive TUI and non-interactive CLI paths are implemented. * style: fix prettier formatting in docs * fix: escape backslashes in action group description for generated Python code * style: fix prettier formatting across all changed files * fix: align memory retrieval strategies with agentcore.json config - Add actor_id=user_id to all retrieve_memories calls (was missing in Strands translator) - Pass memoryOption through to translators so generated Python code matches the strategies written to agentcore.json - shortTerm: no namespace-specific retrieval (no strategies in schema) - longAndShortTerm: retrieve from all three strategy namespaces (/users/{user_id}/facts, /users/{user_id}/preferences, /summaries/{user_id}/) matching SEMANTIC, USER_PREFERENCE, and SUMMARIZATION strategies * style: fix prettier formatting in translators * fix: address review feedback from aidandaly24 - Prevent infinite recursion in collaborator fetching by threading a visited-agents set through getBedrockAgentConfig - Fix LangGraph checkpointer_STM NameError when memory is disabled by making the checkpointer parameter conditional - Fix memory_manager NameError in both translators when memoryEnabled but agentcoreMemoryEnabled is false - Add shared Python string escaping utilities (escapePyDoubleQuote, escapePySingleQuote, escapePyTripleQuote) and apply consistently to all user-provided string interpolations - Sanitize KB and collaborator names into valid Python identifiers (replace non-alphanumeric chars, handle leading digits) - Add pagination loops for all list API calls (agents, aliases, action groups, knowledge bases, collaborators) - Replace non-null assertions with explicit null guards - Validate alias ARNs with regex before extracting agent/alias IDs - Add console.warn messages to all catch blocks instead of silently discarding errors - Fix stale closure for importConfig.region using a ref - Add guardrail warning comment in Strands generated code * fix: resolve lint errors in bedrock-import and AddAgentScreen - Use Set<string> constructor generic instead of variable annotation - Replace unknown err in template literals with String(err) - Use RegExp#exec() instead of String#match() - Move ref update into useEffect to avoid updating during render
1 parent 4da709b commit f0e1af7

29 files changed

+4915
-604
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Note: CDK L3 constructs are in a separate package `@aws/agentcore-cdk`.
4848
- **Template agents**: Created from framework templates (Strands, LangChain_LangGraph, CrewAI, GoogleADK, OpenAIAgents,
4949
AutoGen)
5050
- **BYO agents**: Bring your own code with `agentcore add agent --type byo`
51+
- **Imported agents**: Import from Bedrock Agents with `agentcore add agent --type import`
5152

5253
### Build Types
5354

docs/commands.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,24 @@ agentcore create --name MyProject --no-agent
5353

5454
# Preview without creating
5555
agentcore create --name MyProject --defaults --dry-run
56+
57+
# Import from Bedrock Agents
58+
agentcore create \
59+
--name MyImportedAgent \
60+
--type import \
61+
--agent-id AGENT123 \
62+
--agent-alias-id ALIAS456 \
63+
--region us-east-1 \
64+
--framework Strands \
65+
--memory none
5666
```
5767

5868
| Flag | Description |
5969
| ------------------------- | -------------------------------------------------------------------------------- |
6070
| `--name <name>` | Project name (alphanumeric, starts with letter, max 23 chars) |
6171
| `--defaults` | Use defaults (Python, Strands, Bedrock, no memory) |
6272
| `--no-agent` | Skip agent creation |
73+
| `--type <type>` | `create` (default) or `import` |
6374
| `--language <lang>` | `Python` (default) |
6475
| `--framework <fw>` | `Strands`, `LangChain_LangGraph`, `CrewAI`, `GoogleADK`, `OpenAIAgents` |
6576
| `--model-provider <p>` | `Bedrock`, `Anthropic`, `OpenAI`, `Gemini` |
@@ -70,6 +81,9 @@ agentcore create --name MyProject --defaults --dry-run
7081
| `--network-mode <mode>` | `PUBLIC` (default) or `VPC` |
7182
| `--subnets <ids>` | Comma-separated subnet IDs (required for VPC mode) |
7283
| `--security-groups <ids>` | Comma-separated security group IDs (required for VPC mode) |
84+
| `--agent-id <id>` | Bedrock Agent ID (import only) |
85+
| `--agent-alias-id <id>` | Bedrock Agent Alias ID (import only) |
86+
| `--region <region>` | AWS region for Bedrock Agent (import only) |
7387
| `--output-dir <dir>` | Output directory |
7488
| `--skip-git` | Skip git initialization |
7589
| `--skip-python-setup` | Skip venv setup |
@@ -167,24 +181,37 @@ agentcore add agent \
167181
--network-mode VPC \
168182
--subnets subnet-abc,subnet-def \
169183
--security-groups sg-123
184+
185+
# Import from Bedrock Agents
186+
agentcore add agent \
187+
--name MyAgent \
188+
--type import \
189+
--agent-id AGENT123 \
190+
--agent-alias-id ALIAS456 \
191+
--region us-east-1 \
192+
--framework Strands \
193+
--memory none
170194
```
171195

172196
| Flag | Description |
173197
| ------------------------- | -------------------------------------------------------------------------------- |
174198
| `--name <name>` | Agent name (alphanumeric, starts with letter, max 64 chars) |
175-
| `--type <type>` | `create` (default) or `byo` |
199+
| `--type <type>` | `create` (default), `byo`, or `import` |
176200
| `--build <type>` | `CodeZip` (default) or `Container` (see [Container Builds](container-builds.md)) |
177201
| `--language <lang>` | `Python` (create); `Python`, `TypeScript`, `Other` (BYO) |
178202
| `--framework <fw>` | `Strands`, `LangChain_LangGraph`, `CrewAI`, `GoogleADK`, `OpenAIAgents` |
179203
| `--model-provider <p>` | `Bedrock`, `Anthropic`, `OpenAI`, `Gemini` |
180204
| `--api-key <key>` | API key for non-Bedrock providers |
181-
| `--memory <opt>` | `none`, `shortTerm`, `longAndShortTerm` (create only) |
205+
| `--memory <opt>` | `none`, `shortTerm`, `longAndShortTerm` (create and import) |
182206
| `--protocol <protocol>` | `HTTP` (default), `MCP`, `A2A` |
183207
| `--code-location <path>` | Path to existing code (BYO only) |
184208
| `--entrypoint <file>` | Entry file relative to code-location (BYO, default: `main.py`) |
185209
| `--network-mode <mode>` | `PUBLIC` (default) or `VPC` |
186210
| `--subnets <ids>` | Comma-separated subnet IDs (required for VPC mode) |
187211
| `--security-groups <ids>` | Comma-separated security group IDs (required for VPC mode) |
212+
| `--agent-id <id>` | Bedrock Agent ID (import only) |
213+
| `--agent-alias-id <id>` | Bedrock Agent Alias ID (import only) |
214+
| `--region <region>` | AWS region for Bedrock Agent (import only) |
188215
| `--json` | JSON output |
189216

190217
### add memory

docs/frameworks.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,51 @@ OpenAI's native agent framework.
7676
agentcore create --framework OpenAIAgents --model-provider OpenAI --api-key sk-...
7777
```
7878

79+
## Import from Bedrock Agents
80+
81+
If you have an existing Bedrock Agent, you can import its configuration and translate it into runnable Strands or
82+
LangChain/LangGraph code. The imported agent preserves your Bedrock Agent's action groups, knowledge bases, multi-agent
83+
collaboration, guardrails, prompts, and memory configuration.
84+
85+
```bash
86+
# Interactive (select "Import from Bedrock Agents" in the wizard)
87+
agentcore add agent
88+
89+
# Non-interactive
90+
agentcore add agent \
91+
--name MyAgent \
92+
--type import \
93+
--agent-id AGENT123 \
94+
--agent-alias-id ALIAS456 \
95+
--region us-east-1 \
96+
--framework Strands \
97+
--memory none
98+
```
99+
100+
### What gets imported
101+
102+
The import process fetches your Bedrock Agent's full configuration and translates it into framework-specific Python code
103+
that runs on AgentCore:
104+
105+
- **Action groups** (function-schema and built-in) become `@tool` decorated functions
106+
- **Knowledge bases** become retrieval tool integrations
107+
- **Multi-agent collaboration** produces separate collaborator files with recursive translation
108+
- **Code interpreter** wires to AgentCore's `code_interpreter_client`
109+
- **Guardrails** are configured in the model initialization
110+
- **Prompt overrides** are preserved as template variables
111+
- **Memory** integrates with AgentCore's memory service when enabled
112+
113+
### Import options
114+
115+
| Flag | Description |
116+
| ----------------------- | ----------------------------------------- |
117+
| `--type import` | Use import mode (required) |
118+
| `--agent-id <id>` | Bedrock Agent ID |
119+
| `--agent-alias-id <id>` | Bedrock Agent Alias ID |
120+
| `--region <region>` | AWS region where the Bedrock Agent exists |
121+
| `--framework <fw>` | `Strands` or `LangChain_LangGraph` |
122+
| `--memory <opt>` | `none`, `shortTerm`, `longAndShortTerm` |
123+
79124
## Bring Your Own (BYO) Agent
80125

81126
For existing agent code or frameworks not listed above, use the BYO option:

0 commit comments

Comments
 (0)