bedrock-agentcore-starter-toolkit 0.1.8__py3-none-any.whl → 0.1.9__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.

@@ -73,18 +73,59 @@ def _attach_policy(
73
73
  :param policy_name: the policy name (if not using a policy_arn).
74
74
  :return:
75
75
  """
76
- if policy_arn and policy_document:
77
- raise Exception("Cannot specify both policy arn and policy document.")
76
+ # Check for invalid combinations of parameters
77
+ if policy_arn:
78
+ if policy_document or policy_name:
79
+ raise Exception("Cannot specify both policy arn and policy document/name")
80
+ elif not (policy_document and policy_name):
81
+ raise Exception("Must specify both policy document and policy name, or just a policy arn")
82
+
78
83
  try:
79
- if policy_arn:
80
- iam_client.attach_role_policy(RoleName=role_name, PolicyArn=policy_arn)
81
- elif policy_document and policy_name:
82
- policy = iam_client.create_policy(
83
- PolicyName=policy_name,
84
- PolicyDocument=policy_document,
85
- )
86
- iam_client.attach_role_policy(RoleName=role_name, PolicyArn=policy["Policy"]["Arn"])
87
- else:
88
- raise Exception("Must specify both policy document and policy name or just a policy arn")
84
+ if policy_document and policy_name:
85
+ policy_arn = _try_create_policy(iam_client, policy_name, policy_document)
86
+ iam_client.attach_role_policy(RoleName=role_name, PolicyArn=policy_arn)
89
87
  except ClientError as e:
90
88
  raise RuntimeError(f"Failed to attach AgentCore policy: {e}") from e
89
+
90
+ def _try_create_policy(
91
+ iam_client: BaseClient,
92
+ policy_name: str,
93
+ policy_document: str
94
+ ) -> str:
95
+ """Try to create a new policy, or return the arn if the policy already exists.
96
+
97
+ :param iam_client: the IAM client to use.
98
+ :param policy_name: the name of the policy to create.
99
+ :param policy_document: the policy document to create.
100
+ :return: the arn of the policy.
101
+ """
102
+ try:
103
+ policy = iam_client.create_policy(
104
+ PolicyName=policy_name,
105
+ PolicyDocument=policy_document,
106
+ )
107
+ return policy["Policy"]["Arn"]
108
+ except ClientError as e:
109
+ if e.response["Error"]["Code"] == "EntityAlreadyExists":
110
+ return _get_existing_policy_arn(iam_client, policy_name)
111
+ else:
112
+ raise e
113
+
114
+ def _get_existing_policy_arn(
115
+ iam_client: BaseClient,
116
+ policy_name: str
117
+ ) -> str:
118
+ """Get the arn of an existing policy.
119
+
120
+ :param iam_client: the IAM client to use.
121
+ :param policy_name: the name of the policy to get.
122
+ :return: the arn of the policy.
123
+ """
124
+ paginator = iam_client.get_paginator("list_policies")
125
+ try:
126
+ for page in paginator.paginate(Scope="Local"):
127
+ for policy in page["Policies"]:
128
+ if policy["PolicyName"] == policy_name:
129
+ return policy["Arn"]
130
+ except ClientError as e:
131
+ raise RuntimeError(f"Failed to get existing policy arn: {e}") from e
@@ -1031,6 +1031,10 @@ class BaseBedrockTranslator:
1031
1031
 
1032
1032
  return code_1p
1033
1033
 
1034
+ def _get_url_regex_pattern(self) -> str:
1035
+ """Get the URL regex pattern for source extraction."""
1036
+ return r'(?:https?://|www\.)(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(?:/[^/\s]*)*'
1037
+
1034
1038
  def generate_entrypoint_code(self, platform: str) -> str:
1035
1039
  """Generate entrypoint code for the agent."""
1036
1040
  entrypoint_code = ""
@@ -1059,6 +1063,7 @@ class BaseBedrockTranslator:
1059
1063
  else "tools_used.update([msg.name for msg in agent_result if isinstance(msg, ToolMessage)])"
1060
1064
  )
1061
1065
  response_content_code = "str(agent_result)" if platform == "strands" else "agent_result[-1].content"
1066
+ url_pattern = self._get_url_regex_pattern()
1062
1067
 
1063
1068
  entrypoint_code += f"""
1064
1069
  def endpoint(payload, context):
@@ -1079,7 +1084,7 @@ class BaseBedrockTranslator:
1079
1084
 
1080
1085
  # Gathering sources from the response
1081
1086
  sources = []
1082
- urls = re.findall(r'(?:https?://|www\.)(?:[a-zA-Z0-9\-]+\.)+[a-zA-Z]{{2,}}(?:/[^/\s]*)*', response_content)
1087
+ urls = re.findall({repr(url_pattern)}, response_content)
1083
1088
  source_tags = re.findall(r"<source>(.*?)</source>", response_content)
1084
1089
  sources.extend(urls)
1085
1090
  sources.extend(source_tags)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bedrock-agentcore-starter-toolkit
3
- Version: 0.1.8
3
+ Version: 0.1.9
4
4
  Summary: A starter toolkit for using Bedrock AgentCore
5
5
  Project-URL: Homepage, https://github.com/aws/bedrock-agentcore-starter-toolkit
6
6
  Project-URL: Bug Tracker, https://github.com/aws/bedrock-agentcore-starter-toolkit/issues
@@ -22,7 +22,7 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
23
  Requires-Python: >=3.10
24
24
  Requires-Dist: autopep8>=2.3.2
25
- Requires-Dist: bedrock-agentcore>=0.1.2
25
+ Requires-Dist: bedrock-agentcore>=0.1.3
26
26
  Requires-Dist: boto3>=1.39.7
27
27
  Requires-Dist: botocore>=1.39.7
28
28
  Requires-Dist: docstring-parser<1.0,>=0.15
@@ -19,7 +19,7 @@ bedrock_agentcore_starter_toolkit/operations/gateway/__init__.py,sha256=5Qo1GeN-
19
19
  bedrock_agentcore_starter_toolkit/operations/gateway/client.py,sha256=8WP2E_u6h1-mPfz4TgNMloD6bcXfoXQDL3UCrbyhT7g,20068
20
20
  bedrock_agentcore_starter_toolkit/operations/gateway/constants.py,sha256=0_4J6BN4VAE4-XTQhPTEACkhilRrFqu_iKiuHSm2pYk,4610
21
21
  bedrock_agentcore_starter_toolkit/operations/gateway/create_lambda.py,sha256=MQsBJfUj26zBh7LqYWLoekHuvbAHIJE8qcXwrmJOhM0,2875
22
- bedrock_agentcore_starter_toolkit/operations/gateway/create_role.py,sha256=a38JE28PbdRabskTgLXsiqHqWS1vt06jxEEGneYPO_g,3145
22
+ bedrock_agentcore_starter_toolkit/operations/gateway/create_role.py,sha256=Z02OtPyuilulX0DnA5vMfGVyn6KUB9wL1mmKeNOCblw,4511
23
23
  bedrock_agentcore_starter_toolkit/operations/gateway/exceptions.py,sha256=WjsrE7lT2708CJniM_ISMzkfNX4IUteGgvOxleD9JZY,272
24
24
  bedrock_agentcore_starter_toolkit/operations/runtime/__init__.py,sha256=7ucAtIbabrDmEaHOfGqHtEr2CkQlEsb5O2tkHirXCqU,673
25
25
  bedrock_agentcore_starter_toolkit/operations/runtime/configure.py,sha256=7xjNN6fn1U2cv20W2tmHdlbSjc-RU953tnbOaH5iXPQ,9056
@@ -39,7 +39,7 @@ bedrock_agentcore_starter_toolkit/services/import_agent/assets/requirements_lang
39
39
  bedrock_agentcore_starter_toolkit/services/import_agent/assets/requirements_strands.j2,sha256=ZAWzCFwdj8Mbq8aBGO3Jnxz0G8XJZPNpIsPf_2Jetfk,100
40
40
  bedrock_agentcore_starter_toolkit/services/import_agent/assets/template_fixtures_merged.json,sha256=Xem7jS8n96QEyHBmnPAvWHM4AyTLyma7Nq9sCVHuXJA,175239
41
41
  bedrock_agentcore_starter_toolkit/services/import_agent/scripts/__init__.py,sha256=UmhcnsfIo2P1Z9VAJ6Ua2mSkxs4BOeTxgFMcgQXQWCQ,79
42
- bedrock_agentcore_starter_toolkit/services/import_agent/scripts/base_bedrock_translate.py,sha256=xAqf0Rrhb4QWE_6WBk98NkQdHbCyy2uFzKbiw_9cWA4,72520
42
+ bedrock_agentcore_starter_toolkit/services/import_agent/scripts/base_bedrock_translate.py,sha256=zmI1e-1pYhP4SroQ4r_k8KmdncaXmJPsYvsDKPCcvtU,72713
43
43
  bedrock_agentcore_starter_toolkit/services/import_agent/scripts/bedrock_to_langchain.py,sha256=xwoZcmZ27CfYohwSfLIgbFxa2ubiBFhvufgQEWZkmLk,14950
44
44
  bedrock_agentcore_starter_toolkit/services/import_agent/scripts/bedrock_to_strands.py,sha256=eC3v2Ts7B_RUGl4bkUim2uFYYuZZYP9syYBlylJ2gXs,14642
45
45
  bedrock_agentcore_starter_toolkit/utils/endpoints.py,sha256=1gIDRd1oO1fymYpiedVit7m6zl5k6N8Ns9N-2ix7ZaE,1153
@@ -54,9 +54,9 @@ bedrock_agentcore_starter_toolkit/utils/runtime/templates/Dockerfile.j2,sha256=0
54
54
  bedrock_agentcore_starter_toolkit/utils/runtime/templates/dockerignore.template,sha256=b_70sBi0MwkTuA9TqxPqFcWK7TcmpaXBJ6M2Ipox65Q,691
55
55
  bedrock_agentcore_starter_toolkit/utils/runtime/templates/execution_role_policy.json.j2,sha256=-0AXT46IYVQr4fwueXTQ0FVXcCshZFNx7-2mViR34Co,4941
56
56
  bedrock_agentcore_starter_toolkit/utils/runtime/templates/execution_role_trust_policy.json.j2,sha256=PPJF6Ofq70W5DUE0NlbmnZjw5RkgepPgkskxEgEG28o,473
57
- bedrock_agentcore_starter_toolkit-0.1.8.dist-info/METADATA,sha256=T-Y9VXQUjDahbwI5rWcjOYWCgrGU7avljQfd6DBtgLw,9706
58
- bedrock_agentcore_starter_toolkit-0.1.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
59
- bedrock_agentcore_starter_toolkit-0.1.8.dist-info/entry_points.txt,sha256=Tf94DkUf2Tp8P7p8MEXLxre7A7Pp_XNukteiz0wHnk8,77
60
- bedrock_agentcore_starter_toolkit-0.1.8.dist-info/licenses/LICENSE.txt,sha256=nNPOMinitYdtfbhdQgsPgz1UowBznU6QVN3Xs0pSTKU,10768
61
- bedrock_agentcore_starter_toolkit-0.1.8.dist-info/licenses/NOTICE.txt,sha256=rkBsg8DbKqfIoQbveqX9foR4uJPUVAokbkr02pRPilE,8674
62
- bedrock_agentcore_starter_toolkit-0.1.8.dist-info/RECORD,,
57
+ bedrock_agentcore_starter_toolkit-0.1.9.dist-info/METADATA,sha256=TLmOIQhVBcBCBt2IUzBt4eU4PXKLFxLGvVBxVOh3POo,9706
58
+ bedrock_agentcore_starter_toolkit-0.1.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
59
+ bedrock_agentcore_starter_toolkit-0.1.9.dist-info/entry_points.txt,sha256=Tf94DkUf2Tp8P7p8MEXLxre7A7Pp_XNukteiz0wHnk8,77
60
+ bedrock_agentcore_starter_toolkit-0.1.9.dist-info/licenses/LICENSE.txt,sha256=nNPOMinitYdtfbhdQgsPgz1UowBznU6QVN3Xs0pSTKU,10768
61
+ bedrock_agentcore_starter_toolkit-0.1.9.dist-info/licenses/NOTICE.txt,sha256=rkBsg8DbKqfIoQbveqX9foR4uJPUVAokbkr02pRPilE,8674
62
+ bedrock_agentcore_starter_toolkit-0.1.9.dist-info/RECORD,,