bedrock-agentcore-starter-toolkit 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
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.
Potentially problematic release.
This version of bedrock-agentcore-starter-toolkit might be problematic. Click here for more details.
- bedrock_agentcore_starter_toolkit/cli/__init__.py +1 -0
- bedrock_agentcore_starter_toolkit/cli/cli.py +3 -1
- bedrock_agentcore_starter_toolkit/cli/common.py +1 -1
- bedrock_agentcore_starter_toolkit/cli/import_agent/README.md +35 -0
- bedrock_agentcore_starter_toolkit/cli/import_agent/__init__.py +1 -0
- bedrock_agentcore_starter_toolkit/cli/import_agent/agent_info.py +230 -0
- bedrock_agentcore_starter_toolkit/cli/import_agent/commands.py +518 -0
- bedrock_agentcore_starter_toolkit/cli/runtime/commands.py +132 -42
- bedrock_agentcore_starter_toolkit/notebook/runtime/bedrock_agentcore.py +120 -22
- bedrock_agentcore_starter_toolkit/operations/gateway/client.py +2 -2
- bedrock_agentcore_starter_toolkit/operations/runtime/configure.py +5 -2
- bedrock_agentcore_starter_toolkit/operations/runtime/invoke.py +1 -1
- bedrock_agentcore_starter_toolkit/operations/runtime/launch.py +108 -30
- bedrock_agentcore_starter_toolkit/operations/runtime/models.py +1 -1
- bedrock_agentcore_starter_toolkit/services/__init__.py +1 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/__init__.py +1 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/assets/memory_manager_template.py +207 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/assets/requirements_langchain.j2 +9 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/assets/requirements_strands.j2 +5 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/assets/template_fixtures_merged.json +1102 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/scripts/__init__.py +1 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/scripts/base_bedrock_translate.py +1668 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/scripts/bedrock_to_langchain.py +382 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/scripts/bedrock_to_strands.py +374 -0
- bedrock_agentcore_starter_toolkit/services/import_agent/utils.py +417 -0
- bedrock_agentcore_starter_toolkit/services/runtime.py +35 -12
- bedrock_agentcore_starter_toolkit/utils/runtime/container.py +54 -3
- bedrock_agentcore_starter_toolkit/utils/runtime/entrypoint.py +11 -5
- bedrock_agentcore_starter_toolkit/utils/runtime/templates/execution_role_policy.json.j2 +2 -1
- {bedrock_agentcore_starter_toolkit-0.1.2.dist-info → bedrock_agentcore_starter_toolkit-0.1.4.dist-info}/METADATA +22 -2
- {bedrock_agentcore_starter_toolkit-0.1.2.dist-info → bedrock_agentcore_starter_toolkit-0.1.4.dist-info}/RECORD +35 -19
- {bedrock_agentcore_starter_toolkit-0.1.2.dist-info → bedrock_agentcore_starter_toolkit-0.1.4.dist-info}/WHEEL +0 -0
- {bedrock_agentcore_starter_toolkit-0.1.2.dist-info → bedrock_agentcore_starter_toolkit-0.1.4.dist-info}/entry_points.txt +0 -0
- {bedrock_agentcore_starter_toolkit-0.1.2.dist-info → bedrock_agentcore_starter_toolkit-0.1.4.dist-info}/licenses/LICENSE.txt +0 -0
- {bedrock_agentcore_starter_toolkit-0.1.2.dist-info → bedrock_agentcore_starter_toolkit-0.1.4.dist-info}/licenses/NOTICE.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI commands for the Bedrock AgentCore Starter Toolkit."""
|
|
@@ -4,9 +4,10 @@ import typer
|
|
|
4
4
|
|
|
5
5
|
from ..cli.gateway.commands import create_mcp_gateway, create_mcp_gateway_target, gateway_app
|
|
6
6
|
from ..utils.logging_config import setup_toolkit_logging
|
|
7
|
+
from .import_agent.commands import import_agent
|
|
7
8
|
from .runtime.commands import configure_app, invoke, launch, status
|
|
8
9
|
|
|
9
|
-
app = typer.Typer(name="agentcore", help="BedrockAgentCore CLI", add_completion=False)
|
|
10
|
+
app = typer.Typer(name="agentcore", help="BedrockAgentCore CLI", add_completion=False, rich_markup_mode="rich")
|
|
10
11
|
|
|
11
12
|
# Setup centralized logging for CLI
|
|
12
13
|
setup_toolkit_logging(mode="cli")
|
|
@@ -15,6 +16,7 @@ setup_toolkit_logging(mode="cli")
|
|
|
15
16
|
app.command("invoke")(invoke)
|
|
16
17
|
app.command("status")(status)
|
|
17
18
|
app.command("launch")(launch)
|
|
19
|
+
app.command("import-agent")(import_agent)
|
|
18
20
|
app.add_typer(configure_app)
|
|
19
21
|
|
|
20
22
|
# gateway
|
|
@@ -18,7 +18,7 @@ def _handle_error(message: str, exception: Optional[Exception] = None) -> NoRetu
|
|
|
18
18
|
raise typer.Exit(1)
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def _handle_warn(message: str) ->
|
|
21
|
+
def _handle_warn(message: str) -> None:
|
|
22
22
|
"""Handle errors with consistent formatting and exit."""
|
|
23
23
|
console.print(f"⚠️ {message}", new_line_start=True, style="bold yellow underline")
|
|
24
24
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Usage of Import Agent CLI
|
|
2
|
+
|
|
3
|
+
This document explains how to use the `import_agent` command.
|
|
4
|
+
|
|
5
|
+
The workflow can be started with `agentcore import-agent`. Additionally, the following flags can be provided.
|
|
6
|
+
|
|
7
|
+
## Available Flags
|
|
8
|
+
|
|
9
|
+
| Flag | Description | Type | Default |
|
|
10
|
+
|------|-------------|------|---------|
|
|
11
|
+
| `--region` | AWS Region to use when fetching Bedrock Agents | string | None |
|
|
12
|
+
| `--agent-id` | ID of the Bedrock Agent to import | string | None |
|
|
13
|
+
| `--agent-alias-id` | ID of the Agent Alias to use | string | None |
|
|
14
|
+
| `--target-platform` | Target platform (langchain + langgraph or strands) | string | None |
|
|
15
|
+
| `--verbose` | Enable verbose mode | boolean | False |
|
|
16
|
+
| `--disable-memory` | Disable AgentCore Memory primitive | boolean | False |
|
|
17
|
+
| `--disable-code-interpreter` | Disable AgentCore Code Interpreter primitive | boolean | False |
|
|
18
|
+
| `--disable-observability` | Disable AgentCore Observability primitive | boolean | False |
|
|
19
|
+
| `--deploy-runtime` | Deploy to AgentCore Runtime | boolean | False |
|
|
20
|
+
| `--run-option` | How to run the agent (locally, runtime, none) | string | None |
|
|
21
|
+
| `--output-dir` | Output directory for generated code | string | "./output/" |
|
|
22
|
+
|
|
23
|
+
## Behavior
|
|
24
|
+
|
|
25
|
+
- If required flags like `--agent-id`, `--agent-alias-id`, or `--target-platform` are not provided, the command will fall back to interactive prompts.
|
|
26
|
+
- Boolean flags like `--verbose`, `--debug`, `--disable-memory`, etc. don't require values; their presence sets them to `True`.
|
|
27
|
+
- If neither `--verbose` nor `--debug` flags are provided, the command will prompt the user to enable verbose mode.
|
|
28
|
+
- `--verbose` will enable verbose mode. Use `--verbose` for standard verbose output for the generated agent.
|
|
29
|
+
- Memory, Code Interpreter, and Observability primitives are enabled by default. Use `--disable-memory`, `--disable-code-interpreter`, or `--disable-observability` to disable them.
|
|
30
|
+
- If the `--deploy-runtime` flag is not provided, the command will prompt the user whether to deploy the agent to AgentCore Runtime.
|
|
31
|
+
- If the `--run-option` flag is not provided, the command will prompt the user to select how to run the agent.
|
|
32
|
+
- The `--run-option` can be one of:
|
|
33
|
+
- `locally`: Run the agent locally
|
|
34
|
+
- `runtime`: Run on AgentCore Runtime (requires `--deploy-runtime`)
|
|
35
|
+
- `none`: Don't run the agent
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI commands for the Bedrock Agent Import Tool."""
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""This module provides utility functions to interact with AWS Bedrock Agent services."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
import boto3
|
|
7
|
+
from prance import ResolvingParser
|
|
8
|
+
from ruamel.yaml import YAML # pylint: disable=import-error # type: ignore
|
|
9
|
+
|
|
10
|
+
from ...services.import_agent.utils import clean_variable_name, fix_field
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_clients(credentials, region_name="us-west-2"):
|
|
14
|
+
"""Get Bedrock and Bedrock Agent clients using the provided credentials and region.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
credentials: AWS credentials
|
|
18
|
+
region_name: AWS region name (default: us-west-2)
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
tuple: (bedrock_client, bedrock_agent_client)
|
|
22
|
+
"""
|
|
23
|
+
boto3_session = boto3.Session(
|
|
24
|
+
aws_access_key_id=credentials.access_key,
|
|
25
|
+
aws_secret_access_key=credentials.secret_key,
|
|
26
|
+
aws_session_token=credentials.token,
|
|
27
|
+
region_name=region_name,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
bedrock_agent_client = boto3_session.client("bedrock-agent", region_name=region_name)
|
|
31
|
+
bedrock_client = boto3_session.client("bedrock", region_name=region_name)
|
|
32
|
+
|
|
33
|
+
return bedrock_client, bedrock_agent_client
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_agents(bedrock_agent_client) -> list[dict[str, str]]:
|
|
37
|
+
"""Retrieve a list of agents in the AWS account.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
bedrock_client: The Bedrock client.
|
|
41
|
+
bedrock_agent_client: The Bedrock Agent client.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
list: A list of dictionaries containing agent information.
|
|
45
|
+
"""
|
|
46
|
+
agents_in_account = bedrock_agent_client.list_agents(maxResults=200)["agentSummaries"]
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
"id": agent.get("agentId", ""),
|
|
50
|
+
"name": agent.get("agentName", ""),
|
|
51
|
+
"description": agent.get("description", ""),
|
|
52
|
+
}
|
|
53
|
+
for agent in agents_in_account
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def get_agent_aliases(bedrock_agent_client, agent_id):
|
|
58
|
+
"""Retrieve a list of aliases for a specific agent.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
bedrock_client: The Bedrock client.
|
|
62
|
+
bedrock_agent_client: The Bedrock Agent client.
|
|
63
|
+
agent_id (str): The ID of the agent.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
list: A list of dictionaries containing alias information for the specified agent.
|
|
67
|
+
"""
|
|
68
|
+
aliases_for_agent = bedrock_agent_client.list_agent_aliases(agentId=agent_id)["agentAliasSummaries"]
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
"id": agent.get("agentAliasId", ""),
|
|
72
|
+
"name": agent.get("agentAliasName", ""),
|
|
73
|
+
"description": agent.get("description", ""),
|
|
74
|
+
}
|
|
75
|
+
for agent in aliases_for_agent
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def get_agent_info(agent_id: str, agent_alias_id: str, bedrock_client, bedrock_agent_client):
|
|
80
|
+
"""Retrieve detailed information about a specific agent and its alias.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
agent_id (str): The ID of the agent.
|
|
84
|
+
agent_alias_id (str): The ID of the agent alias.
|
|
85
|
+
bedrock_client: The Bedrock client.
|
|
86
|
+
bedrock_agent_client: The Bedrock Agent client.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
dict: A dictionary containing detailed information about the agent, its alias, action groups,
|
|
90
|
+
knowledge bases, and collaborators.
|
|
91
|
+
"""
|
|
92
|
+
agent_version = bedrock_agent_client.get_agent_alias(agentId=agent_id, agentAliasId=agent_alias_id)["agentAlias"][
|
|
93
|
+
"routingConfiguration"
|
|
94
|
+
][0]["agentVersion"]
|
|
95
|
+
|
|
96
|
+
identifier = agent_id
|
|
97
|
+
version = agent_version
|
|
98
|
+
|
|
99
|
+
targets = {}
|
|
100
|
+
|
|
101
|
+
agentinfo = bedrock_agent_client.get_agent(agentId=identifier)["agent"]
|
|
102
|
+
|
|
103
|
+
# reduce agent prompt configurations to only the enabled set
|
|
104
|
+
if agentinfo["orchestrationType"] == "DEFAULT":
|
|
105
|
+
agentinfo["promptOverrideConfiguration"]["promptConfigurations"] = [
|
|
106
|
+
fix_field(config, "basePromptTemplate")
|
|
107
|
+
for config in agentinfo["promptOverrideConfiguration"]["promptConfigurations"]
|
|
108
|
+
if config["promptState"] == "ENABLED"
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
# get agent guardrail information
|
|
112
|
+
guardrail_config = agentinfo.get("guardrailConfiguration", {})
|
|
113
|
+
guardrail_identifier = guardrail_config.get("guardrailIdentifier")
|
|
114
|
+
guardrail_version = guardrail_config.get("guardrailVersion")
|
|
115
|
+
if guardrail_identifier and guardrail_version:
|
|
116
|
+
agentinfo["guardrailConfiguration"] = bedrock_client.get_guardrail(
|
|
117
|
+
guardrailIdentifier=guardrail_identifier,
|
|
118
|
+
guardrailVersion=guardrail_version,
|
|
119
|
+
)
|
|
120
|
+
agentinfo["guardrailConfiguration"].pop("ResponseMetadata")
|
|
121
|
+
|
|
122
|
+
# get more model information
|
|
123
|
+
model_inference_profile = agentinfo["foundationModel"].split("/")[-1]
|
|
124
|
+
model_id = ".".join(model_inference_profile.split(".")[-2:])
|
|
125
|
+
agentinfo["model"] = bedrock_client.get_foundation_model(modelIdentifier=model_id)["modelDetails"]
|
|
126
|
+
agentinfo["alias"] = agent_alias_id
|
|
127
|
+
|
|
128
|
+
# get agent action groups and lambdas in them
|
|
129
|
+
action_groups = bedrock_agent_client.list_agent_action_groups(agentId=identifier, agentVersion=version)[
|
|
130
|
+
"actionGroupSummaries"
|
|
131
|
+
]
|
|
132
|
+
for action_group in action_groups:
|
|
133
|
+
action_group_info = bedrock_agent_client.get_agent_action_group(
|
|
134
|
+
agentId=identifier,
|
|
135
|
+
agentVersion=version,
|
|
136
|
+
actionGroupId=action_group["actionGroupId"],
|
|
137
|
+
)["agentActionGroup"]
|
|
138
|
+
action_group.update(action_group_info)
|
|
139
|
+
action_group["actionGroupName"] = clean_variable_name(action_group["actionGroupName"])
|
|
140
|
+
|
|
141
|
+
if action_group.get("apiSchema", False):
|
|
142
|
+
open_api_schema = action_group["apiSchema"].get("payload", False)
|
|
143
|
+
if open_api_schema:
|
|
144
|
+
yaml = YAML(typ="safe")
|
|
145
|
+
action_group["apiSchema"]["payload"] = yaml.load(open_api_schema)
|
|
146
|
+
else:
|
|
147
|
+
s3_bucket_name = action_group["apiSchema"]["s3"]["s3BucketName"]
|
|
148
|
+
s3_object_key = action_group["apiSchema"]["s3"]["s3ObjectKey"]
|
|
149
|
+
|
|
150
|
+
s3_client = boto3.client("s3")
|
|
151
|
+
response = s3_client.get_object(Bucket=s3_bucket_name, Key=s3_object_key)
|
|
152
|
+
yaml_content = response["Body"].read().decode("utf-8")
|
|
153
|
+
yaml = YAML(typ="safe")
|
|
154
|
+
action_group["apiSchema"]["payload"] = yaml.load(yaml_content)
|
|
155
|
+
# resolve the openapi schema references
|
|
156
|
+
parser = ResolvingParser(spec_string=json.dumps(action_group["apiSchema"]["payload"]))
|
|
157
|
+
action_group["apiSchema"]["payload"] = parser.specification
|
|
158
|
+
|
|
159
|
+
# get agent knowledge bases
|
|
160
|
+
knowledge_bases = bedrock_agent_client.list_agent_knowledge_bases(agentId=identifier, agentVersion=version)[
|
|
161
|
+
"agentKnowledgeBaseSummaries"
|
|
162
|
+
]
|
|
163
|
+
for knowledge_base in knowledge_bases:
|
|
164
|
+
knowledge_base_info = bedrock_agent_client.get_knowledge_base(
|
|
165
|
+
knowledgeBaseId=knowledge_base["knowledgeBaseId"],
|
|
166
|
+
)["knowledgeBase"]
|
|
167
|
+
knowledge_base_info["name"] = clean_variable_name(knowledge_base_info["name"])
|
|
168
|
+
for key, value in knowledge_base_info.items():
|
|
169
|
+
if key not in knowledge_base:
|
|
170
|
+
knowledge_base[key] = value
|
|
171
|
+
|
|
172
|
+
agentinfo["version"] = version
|
|
173
|
+
targets.update(
|
|
174
|
+
{
|
|
175
|
+
"agent": agentinfo,
|
|
176
|
+
"action_groups": action_groups,
|
|
177
|
+
"knowledge_bases": knowledge_bases,
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
# get agent collaborators and recursively fetch their information
|
|
182
|
+
targets["collaborators"] = []
|
|
183
|
+
if agentinfo.get("agentCollaboration", "DISABLED") != "DISABLED":
|
|
184
|
+
collaborators = bedrock_agent_client.list_agent_collaborators(agentId=agent_id, agentVersion=agent_version)[
|
|
185
|
+
"agentCollaboratorSummaries"
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
for collaborator in collaborators:
|
|
189
|
+
arn = collaborator["agentDescriptor"]["aliasArn"].split("/")
|
|
190
|
+
collab_id = arn[1]
|
|
191
|
+
collab_alias_id = arn[2]
|
|
192
|
+
if collab_alias_id == agent_alias_id:
|
|
193
|
+
continue
|
|
194
|
+
collaborator_info = get_agent_info(collab_id, collab_alias_id, bedrock_client, bedrock_agent_client)
|
|
195
|
+
collaborator_info["collaboratorName"] = clean_variable_name(collaborator["collaboratorName"])
|
|
196
|
+
collaborator_info["collaborationInstruction"] = collaborator.get("collaborationInstruction", "")
|
|
197
|
+
collaborator_info["relayConversationHistory"] = collaborator.get("relayConversationHistory", "DISABLED")
|
|
198
|
+
|
|
199
|
+
targets["collaborators"].append(collaborator_info)
|
|
200
|
+
|
|
201
|
+
if identifier == agent_id and version == agent_version and collaborators:
|
|
202
|
+
agentinfo["isPrimaryAgent"] = True
|
|
203
|
+
agentinfo["collaborators"] = collaborators
|
|
204
|
+
|
|
205
|
+
return targets
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def auth_and_get_info(agent_id: str, agent_alias_id: str, output_dir: str, region_name: str = "us-west-2"):
|
|
209
|
+
"""Authenticate with AWS and retrieve agent information.
|
|
210
|
+
|
|
211
|
+
Args:
|
|
212
|
+
agent_id (str): The ID of the agent.
|
|
213
|
+
agent_alias_id (str): The ID of the agent alias.
|
|
214
|
+
output_dir (str): The directory where the output Bedrock Agent configuration will be saved.
|
|
215
|
+
region_name (str): AWS region name (default: us-west-2).
|
|
216
|
+
|
|
217
|
+
Returns:
|
|
218
|
+
dict: A dictionary containing detailed information about the agent, its alias,
|
|
219
|
+
action groups, knowledge bases, and collaborators.
|
|
220
|
+
"""
|
|
221
|
+
credentials = boto3.Session().get_credentials()
|
|
222
|
+
bedrock_client, bedrock_agent_client = get_clients(credentials, region_name)
|
|
223
|
+
output = get_agent_info(agent_id, agent_alias_id, bedrock_client, bedrock_agent_client)
|
|
224
|
+
|
|
225
|
+
# Save the output Bedrock Agent configuration to a file for debugging and reference
|
|
226
|
+
with open(os.path.join(output_dir, "bedrock_config.json"), "a+", encoding="utf-8") as f:
|
|
227
|
+
f.truncate(0)
|
|
228
|
+
json.dump(output, f, ensure_ascii=False, indent=4, default=str)
|
|
229
|
+
|
|
230
|
+
return output
|