Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
"import argparse\n",
"from boto3.session import Session\n",
"from opentelemetry import baggage, context\n",
"from scripts.utils import get_ssm_parameter\n",
"from lab_helpers.utils import get_ssm_parameter\n",
"\n",
"from strands import Agent\n",
"from strands.models import BedrockModel\n",
Expand Down
109 changes: 39 additions & 70 deletions 01-tutorials/07-AgentCore-E2E/Optional-lab-identity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@
"from strands import tool\n",
"from strands import Agent\n",
"from strands.models import BedrockModel\n",
"from strands_tools import calculator\n",
"import webbrowser\n",
"import sys\n",
"import os\n",
"\n",
"from lab_helpers.utils import get_ssm_parameter, put_ssm_parameter\n",
"from lab_helpers.utils import get_ssm_parameter\n",
"\n",
"session = boto3.session.Session()\n",
"region = session.region_name\n",
Expand All @@ -127,7 +124,7 @@
" \"bedrock-agentcore-control\",\n",
" region_name=region,\n",
")\n",
"cognito = boto3.client('cognito-idp')\n",
"cognito = boto3.client(\"cognito-idp\")\n",
"ssm = boto3.client(\"ssm\", region_name=region)\n",
"\n",
"print(\"✅ Libraries imported successfully!\")"
Expand All @@ -143,6 +140,7 @@
"source": [
"# Helper functions to save, retrieve, and delete provider names from SSM\n",
"\n",
"\n",
"def store_provider_name_in_ssm(provider_name: str):\n",
" \"\"\"Store credential provider name in SSM parameter.\"\"\"\n",
" param_name = \"/app/customersupport/agentcore/google_provider\"\n",
Expand Down Expand Up @@ -184,44 +182,11 @@
"We'll reuse the customer support tools from Lab 1 to maintain our agent's core functionality.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from lab_helpers.lab1_strands_agent import (\n",
" get_return_policy,\n",
" get_product_info,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 3: Import Memory Tools\n",
"\n",
"We'll reuse the memory tools from Lab 2 to maintain our agent's core functionality.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from lab_helpers.lab2_helper import setup_memory\n",
"\n",
"memory_hook = setup_memory()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Step 4: Configure AgentCore Identity Clients\n",
"## Step 3: Configure AgentCore Identity Clients\n",
"\n",
"In this step, we'll integrate Google Calendar API functionality into our customer support agent. To securely access external services like Google Calendar on behalf of users, we need to implement proper authentication mechanisms.\n",
"\n",
Expand Down Expand Up @@ -291,7 +256,7 @@
"source": [
"credentials_file = \"credentials.json\"\n",
"\n",
"#Verify credentials file looks as expected, and extract credentials\n",
"# Verify credentials file looks as expected, and extract credentials\n",
"\n",
"if not os.path.isfile(credentials_file):\n",
" print(f\"❌ Error: '{credentials_file}' file not found\")\n",
Expand Down Expand Up @@ -394,11 +359,13 @@
"source": [
"async def on_auth_url(url: str):\n",
" webbrowser.open(url)\n",
" \n",
"\n",
"\n",
"SCOPES = [\"https://www.googleapis.com/auth/calendar\"]\n",
"\n",
"google_access_token = None\n",
"\n",
"\n",
"@requires_access_token(\n",
" provider_name=google_provider_name,\n",
" scopes=[\"https://www.googleapis.com/auth/calendar\"], # Google OAuth2 scopes\n",
Expand All @@ -407,7 +374,6 @@
" force_authentication=True,\n",
" into=\"access_token\",\n",
")\n",
"\n",
"def get_google_access_token(access_token: str):\n",
" return access_token"
]
Expand All @@ -434,7 +400,7 @@
" description=\"Creates a new event on your Google Calendar\",\n",
")\n",
"def create_calendar_event() -> str:\n",
" google_access_token = ''\n",
" google_access_token = \"\"\n",
" try:\n",
" google_access_token = get_google_access_token(access_token=google_access_token)\n",
" if not google_access_token:\n",
Expand Down Expand Up @@ -480,7 +446,7 @@
" except HttpError as error:\n",
" return json.dumps({\"error\": str(error), \"event_created\": False})\n",
" except Exception as e:\n",
" return json.dumps({\"error\": str(e), \"event_created\": False})\n"
" return json.dumps({\"error\": str(e), \"event_created\": False})"
]
},
{
Expand All @@ -496,10 +462,9 @@
" description=\"Retrieves the calendar events for the day from your Google Calendar\",\n",
")\n",
"def get_calendar_events_today() -> str:\n",
" google_access_token = ''\n",
" google_access_token = \"\"\n",
" try:\n",
" google_access_token = get_google_access_token(\n",
" access_token=google_access_token)\n",
" google_access_token = get_google_access_token(access_token=google_access_token)\n",
"\n",
" if not google_access_token:\n",
" raise Exception(\"requires_access_token did not provide tokens\")\n",
Expand Down Expand Up @@ -601,9 +566,13 @@
},
"outputs": [],
"source": [
"print(str(agent(\n",
"print(\n",
" str(\n",
" agent(\n",
" \"Can you create a new event on my cal? You can call the create_calendar_event directly.\"\n",
" )))\n"
" )\n",
" )\n",
")"
]
},
{
Expand Down Expand Up @@ -679,8 +648,8 @@
"\n",
"try:\n",
" print(\"📥 Fetching Cognito configuration from SSM...\")\n",
" \n",
" client_id = get_ssm_parameter(\"/app/customersupport/agentcore/machine_client_id\")\n",
"\n",
" client_id = get_ssm_parameter(\"/app/customersupport/agentcore/client_id\")\n",
" print(f\"✅ Retrieved client ID: {client_id}\")\n",
"\n",
" client_secret = get_ssm_parameter(\"/app/customersupport/agentcore/cognito_secret\")\n",
Expand All @@ -695,30 +664,30 @@
" print(f\"✅ Token Endpoint: {token_url}\")\n",
"\n",
" print(\"⚙️ Creating OAuth2 credential provider...\")\n",
" \n",
"\n",
" cognito_provider = identity_client.create_oauth2_credential_provider(\n",
" name=cognito_provider_name,\n",
" credentialProviderVendor=\"CustomOauth2\",\n",
" oauth2ProviderConfigInput={\n",
" \"customOauth2ProviderConfig\": {\n",
" \"clientId\": client_id,\n",
" \"clientSecret\": client_secret,\n",
" \"oauthDiscovery\": {\n",
" \"authorizationServerMetadata\": {\n",
" \"issuer\": issuer,\n",
" \"authorizationEndpoint\": auth_url,\n",
" \"tokenEndpoint\": token_url,\n",
" \"responseTypes\": [\"code\", \"token\"],\n",
" }\n",
" },\n",
" }\n",
" },\n",
" )\n",
" name=cognito_provider_name,\n",
" credentialProviderVendor=\"CustomOauth2\",\n",
" oauth2ProviderConfigInput={\n",
" \"customOauth2ProviderConfig\": {\n",
" \"clientId\": client_id,\n",
" \"clientSecret\": client_secret,\n",
" \"oauthDiscovery\": {\n",
" \"authorizationServerMetadata\": {\n",
" \"issuer\": issuer,\n",
" \"authorizationEndpoint\": auth_url,\n",
" \"tokenEndpoint\": token_url,\n",
" \"responseTypes\": [\"code\", \"token\"],\n",
" }\n",
" },\n",
" }\n",
" },\n",
" )\n",
"\n",
" provider_arn = cognito_provider[\"credentialProviderArn\"]\n",
" print(provider_arn)\n",
"except Exception as e:\n",
" print(f\"❌ Error creating Cognito credential provider: {str(e)}\")"
" print(f\"❌ Error creating Cognito credential provider: {str(e)}\")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions 01-tutorials/07-AgentCore-E2E/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ Each lab builds on the previous one, but you can jump ahead if you understand th

Watch your architecture grow from a simple local agent to a production system:

**Lab 1:** Local agent with embedded tools
**Lab 1:** Local agent with embedded tools
**Lab 2:** Agent + AgentCore Memory for persistence
**Lab 3:** Agent + AgentCore Memory + AgentCore Gateway and AgentCore Identity for shared tools
**Lab 4:** Deployment to AgentCore Runtime and observability with AgentCore Observability
**Lab 5:** Customer-facing application with authentication

Ready to build? [Start with Lab 1 →](lab-01-create-an-agent.ipynb)
Ready to build? [Start with Lab 1 →](lab-01-create-an-agent.ipynb)
Loading
Loading