From 2b43ea4d389cceb142657b012c98f539c8e1cb97 Mon Sep 17 00:00:00 2001 From: Paul Hargis Date: Wed, 10 Sep 2025 16:06:43 +0000 Subject: [PATCH 1/5] Initial commit for new Strands-only required dependency notebook and creation for Mistral LLM sagemaker endpoint. --- .../1-required-dependencies-strands.ipynb | 246 ++++++++ .../2-setup-mistral-sagemaker-endpoint.ipynb | 555 ++++++++++++++++++ 2 files changed, 801 insertions(+) create mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb create mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb new file mode 100644 index 0000000..426e5e0 --- /dev/null +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb @@ -0,0 +1,246 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e05d69d6", + "metadata": {}, + "source": [ + "# Installing Dependencies\n", + "\n", + "Please install the dependencies before proceeding with the rest of the workshop." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "18de50ca", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:26:53.038020Z", + "iopub.status.busy": "2025-09-10T15:26:53.037704Z", + "iopub.status.idle": "2025-09-10T15:26:53.185121Z", + "shell.execute_reply": "2025-09-10T15:26:53.184531Z", + "shell.execute_reply.started": "2025-09-10T15:26:53.037993Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "strands-agents==1.4.0\n", + "strands-agents[sagemaker]\n", + "strands-agents-tools>=0.2.3\n", + "strands-agents-builder>=0.1.7\n", + "yfinance==0.2.65\n", + "matplotlib==3.10.3\n", + "beautifulsoup4>=4.13.4\n", + "pandas==2.3.0\n", + "seaborn==0.13.2\n", + "joblib==1.5.1\n", + "requests>=2.32.4\n", + "scikit-learn==1.7.0\n", + "uv==0.8.6\n", + "mem0ai==0.1.114\n", + "opensearch-py\n", + "ddgs==9.3.1\n", + "faiss-cpu==1.11.0\n", + "sagemaker==2.249.0\n", + "openai==1.99.3\n", + "aiohttp==3.12.15\n", + "boto3==1.39.8\n", + "bedrock-agentcore==0.1.1\n", + "bedrock-agentcore-starter-toolkit==0.1.5\n", + "botocore==1.39.8\n", + "litellm==1.72.2\n" + ] + } + ], + "source": [ + "!cat requirements-strands.txt" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d82dc1bd-c256-40a7-b25b-751ece4b43c1", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:26:55.416854Z", + "iopub.status.busy": "2025-09-10T15:26:55.416508Z", + "iopub.status.idle": "2025-09-10T15:26:55.974046Z", + "shell.execute_reply": "2025-09-10T15:26:55.973427Z", + "shell.execute_reply.started": "2025-09-10T15:26:55.416830Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[33mWARNING: Skipping autogluon-multimodal as it is not installed.\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping autogluon-timeseries as it is not installed.\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping autogluon-features as it is not installed.\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping autogluon-common as it is not installed.\u001b[0m\u001b[33m\n", + "\u001b[0m\u001b[33mWARNING: Skipping autogluon-core as it is not installed.\u001b[0m\u001b[33m\n", + "\u001b[0mNote: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "# Warnings are safe to ignore\n", + "%pip uninstall -q -y autogluon-multimodal autogluon-timeseries autogluon-features autogluon-common autogluon-core" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1453ae11-d805-4f94-a299-7198638b80bf", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:27:02.652613Z", + "iopub.status.busy": "2025-09-10T15:27:02.652276Z", + "iopub.status.idle": "2025-09-10T15:27:04.912916Z", + "shell.execute_reply": "2025-09-10T15:27:04.912260Z", + "shell.execute_reply.started": "2025-09-10T15:27:02.652587Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip install -q -r requirements-strands.txt" + ] + }, + { + "cell_type": "markdown", + "id": "a3fd75f2", + "metadata": {}, + "source": [ + "### This cell will restart the kernel. Wait for the pop-up box to appear, then click \"OK\" before proceeding." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b96ff09e", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:27:08.212243Z", + "iopub.status.busy": "2025-09-10T15:27:08.211902Z", + "iopub.status.idle": "2025-09-10T15:27:08.218540Z", + "shell.execute_reply": "2025-09-10T15:27:08.218046Z", + "shell.execute_reply.started": "2025-09-10T15:27:08.212217Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'status': 'ok', 'restart': True}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from IPython import get_ipython\n", + "get_ipython().kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "id": "351d1369-51aa-47bb-800b-653b3a734a8a", + "metadata": {}, + "source": [ + "### Cell below displays the installed versions of Strands libraries\n", + "\n", + "As a result of the `pip installs` above, this cell outputs the current versions of Strands libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "9c692e9f-7072-4f90-aa8e-eda90ab04b3d", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:27:13.593844Z", + "iopub.status.busy": "2025-09-10T15:27:13.593542Z", + "iopub.status.idle": "2025-09-10T15:27:14.977405Z", + "shell.execute_reply": "2025-09-10T15:27:14.976815Z", + "shell.execute_reply.started": "2025-09-10T15:27:13.593821Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: strands-agents\n", + "Version: 1.4.0\n", + "Summary: A model-driven approach to building AI agents in just a few lines of code\n", + "Home-page: https://github.com/strands-agents/sdk-python\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder, strands-agents-tools\n", + "---\n", + "Name: strands-agents-tools\n", + "Version: 0.2.6\n", + "Summary: A collection of specialized tools for Strands Agents\n", + "Home-page: https://github.com/strands-agents/tools\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, readabilipy, requests, rich, slack-bolt, strands-agents, sympy, tenacity, watchdog\n", + "Required-by: strands-agents-builder\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip show strands-agents strands-agents-tools" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9687e1a-9b01-4a48-ba06-c370158f1caf", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb new file mode 100644 index 0000000..5ec68ff --- /dev/null +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb @@ -0,0 +1,555 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "586f2662-a568-4c29-af10-7bcb2eadbf30", + "metadata": {}, + "source": [ + "# Deploying an LLM to Amazon SageMaker AI real-time endpoint\n", + "\n", + "## Prerequisites\n", + "\n", + "To use SageMaker AI endpoints in these examples, you will need to first deploy a managed endpoint. In this example you will deploy an endpoint through SageMaker Jumpstart, a feature that helps machine learning practitioners quickly get started with hundreds of production-ready models in SageMaker AI.\n", + "\n", + "## Dependencies\n", + "\n", + "
\n", + "⚠️ Important: Make sure you've run the 1-required-dependencies-strands.ipynb notebook in this folder before proceeding. If you haven't, close this notebook, run the previous one first, then come back to this.\n", + "
\n", + "\n", + "## Create Sagemaker Endpoint\n", + "\n", + "In this notebook, we first create an endpoint config that defines parameters for the endpoint. Then we specify an inference component that will field our requests. This component will create and kick-off the Sagemaker endpoint after some delay.\n", + "\n", + "**NOTE**: In order to deploy a Sagemaker Endpoint on a larger instance type, such as `ml.g5.48xlarge`, you may have to request a quota increase for your account. Please refer to AWS documentation on how to [increase quotas](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html). \n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "0f49d687-9592-4d6d-98e6-0e3a191f9fa1", + "metadata": {}, + "source": [ + "### Run this cell to make sure the Strands Agent libraries are installed" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b2ce612f-74cb-4c44-9483-a019bfa006d5", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:27:34.854067Z", + "iopub.status.busy": "2025-09-10T15:27:34.853759Z", + "iopub.status.idle": "2025-09-10T15:27:36.244146Z", + "shell.execute_reply": "2025-09-10T15:27:36.243506Z", + "shell.execute_reply.started": "2025-09-10T15:27:34.854045Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: strands-agents\n", + "Version: 1.4.0\n", + "Summary: A model-driven approach to building AI agents in just a few lines of code\n", + "Home-page: https://github.com/strands-agents/sdk-python\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder, strands-agents-tools\n", + "---\n", + "Name: strands-agents-tools\n", + "Version: 0.2.6\n", + "Summary: A collection of specialized tools for Strands Agents\n", + "Home-page: https://github.com/strands-agents/tools\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, readabilipy, requests, rich, slack-bolt, strands-agents, sympy, tenacity, watchdog\n", + "Required-by: strands-agents-builder\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip show strands-agents strands-agents-tools" + ] + }, + { + "cell_type": "markdown", + "id": "b35c2bba-157b-49f5-9cf0-aaacf8f6347a", + "metadata": {}, + "source": [ + "### If Strands Agents libraries do not show above, then install them by running this cell" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b3530b42-c71f-4d70-8856-60f8e24603e8", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:27:39.751870Z", + "iopub.status.busy": "2025-09-10T15:27:39.751511Z", + "iopub.status.idle": "2025-09-10T15:27:39.755015Z", + "shell.execute_reply": "2025-09-10T15:27:39.754435Z", + "shell.execute_reply.started": "2025-09-10T15:27:39.751844Z" + } + }, + "outputs": [], + "source": [ + "# Uncomment line below to run pip install\n", + "# %pip install 'strands-agents[sagemaker]' strands-agents-tools" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3e8e0da6-0c35-484b-85dc-0510d0742b8d", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:27:40.658240Z", + "iopub.status.busy": "2025-09-10T15:27:40.657911Z", + "iopub.status.idle": "2025-09-10T15:27:42.625298Z", + "shell.execute_reply": "2025-09-10T15:27:42.624515Z", + "shell.execute_reply.started": "2025-09-10T15:27:40.658218Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml\n", + "sagemaker.config INFO - Not applying SDK defaults from location: /home/sagemaker-user/.config/sagemaker/config.yaml\n" + ] + } + ], + "source": [ + "import boto3\n", + "import json\n", + "from sagemaker import get_execution_role\n", + "from sagemaker.jumpstart.model import JumpStartModel\n", + "\n", + "# Setup role and sagemaker session\n", + "iam_role = get_execution_role()\n", + "boto_session = boto3.Session(region_name='us-west-2')\n", + "sagemaker_client = boto_session.client('sagemaker')\n", + "sagemaker_runtime = boto3.client(\"sagemaker-runtime\") \n", + "\n", + "# Names for endpoint config and endpoint\n", + "endpointName='strands-endpoint-001'\n", + "endpointConfigName='strands-endpoint-config'\n", + "inferenceComponentName='mistral-24b-instruct-2501-ic'\n" + ] + }, + { + "cell_type": "markdown", + "id": "c2bdb040-cb4d-464c-9c58-58c938e5e283", + "metadata": {}, + "source": [ + "## Delete Resources if they already exist\n", + "\n", + "**Note**: If you re-run this notebook, or see failures to create resources, run the next 3 cells to delete previously created resources." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "47f59cb0-e525-4d3b-b2f7-faa551fa967a", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:32:35.816143Z", + "iopub.status.busy": "2025-09-10T15:32:35.815819Z", + "iopub.status.idle": "2025-09-10T15:32:35.932134Z", + "shell.execute_reply": "2025-09-10T15:32:35.931582Z", + "shell.execute_reply.started": "2025-09-10T15:32:35.816121Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'ResponseMetadata': {'RequestId': 'b8a68ac1-efe8-4b98-9f8e-ccb90d8974a2',\n", + " 'HTTPStatusCode': 200,\n", + " 'HTTPHeaders': {'x-amzn-requestid': 'b8a68ac1-efe8-4b98-9f8e-ccb90d8974a2',\n", + " 'content-type': 'application/x-amz-json-1.1',\n", + " 'date': 'Wed, 10 Sep 2025 15:32:35 GMT',\n", + " 'content-length': '0'},\n", + " 'RetryAttempts': 0}}" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Run this line if the endpoint already exists\n", + "sagemaker_client.delete_endpoint(EndpointName=endpointName)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "9185be4a-8252-4951-a0c0-de9de0505112", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:32:42.162578Z", + "iopub.status.busy": "2025-09-10T15:32:42.162257Z", + "iopub.status.idle": "2025-09-10T15:32:42.360272Z", + "shell.execute_reply": "2025-09-10T15:32:42.359820Z", + "shell.execute_reply.started": "2025-09-10T15:32:42.162558Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'ResponseMetadata': {'RequestId': '776861f6-f561-45b9-a37b-2c23c9c06b19',\n", + " 'HTTPStatusCode': 200,\n", + " 'HTTPHeaders': {'x-amzn-requestid': '776861f6-f561-45b9-a37b-2c23c9c06b19',\n", + " 'content-type': 'application/x-amz-json-1.1',\n", + " 'date': 'Wed, 10 Sep 2025 15:32:42 GMT',\n", + " 'content-length': '0'},\n", + " 'RetryAttempts': 0}}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Run this line if the endpoint config already exists\n", + "sagemaker_client.delete_endpoint_config(EndpointConfigName=endpointConfigName)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24591a94-1ff5-4d12-a5ad-f32f75ad84df", + "metadata": {}, + "outputs": [], + "source": [ + "# Run this code to delete inference component (if exists)\n", + "sagemaker_client.delete_inference_component(InferenceComponentName=inferenceComponentName)" + ] + }, + { + "cell_type": "markdown", + "id": "f0b8cfd4-b13a-4e4b-8dc3-48150f783536", + "metadata": {}, + "source": [ + "## Create Endpoint Config, Endpoint, and Inference Component" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "6d0587aa-3647-44b0-a29b-9ce65239c05b", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:34:16.883968Z", + "iopub.status.busy": "2025-09-10T15:34:16.883648Z", + "iopub.status.idle": "2025-09-10T15:34:17.202421Z", + "shell.execute_reply": "2025-09-10T15:34:17.201912Z", + "shell.execute_reply.started": "2025-09-10T15:34:16.883948Z" + } + }, + "outputs": [], + "source": [ + "# Create endpoint config\n", + "\n", + "endpoint_config = sagemaker_client.create_endpoint_config(\n", + " EndpointConfigName=endpointConfigName,\n", + " EnableNetworkIsolation=False,\n", + " ExecutionRoleArn=iam_role,\n", + " ProductionVariants=[\n", + " {\n", + " \"VariantName\": 'AllTraffic',\n", + " \"InstanceType\": 'ml.g5.48xlarge',\n", + " \"InitialInstanceCount\": 1,\n", + " \"ModelDataDownloadTimeoutInSeconds\": 3600,\n", + " \"ContainerStartupHealthCheckTimeoutInSeconds\": 3600,\n", + " \"ManagedInstanceScaling\": {\n", + " \"Status\": \"ENABLED\",\n", + " \"MinInstanceCount\": 0,\n", + " \"MaxInstanceCount\": 2,\n", + " },\n", + " \"RoutingConfig\": {\"RoutingStrategy\": \"LEAST_OUTSTANDING_REQUESTS\"},\n", + " }\n", + " ],\n", + ")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "65f574c2-6b35-4dc1-aeab-b35cf7214794", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:34:21.458940Z", + "iopub.status.busy": "2025-09-10T15:34:21.458634Z", + "iopub.status.idle": "2025-09-10T15:34:21.914548Z", + "shell.execute_reply": "2025-09-10T15:34:21.914051Z", + "shell.execute_reply.started": "2025-09-10T15:34:21.458920Z" + } + }, + "outputs": [], + "source": [ + "# Create endpoint\n", + "endpoint = sagemaker_client.create_endpoint(\n", + " EndpointName=endpointName,\n", + " EndpointConfigName=endpointConfigName\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "0e9a7f7c-429b-47e4-9cdc-b2b57821a7c2", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:34:25.695975Z", + "iopub.status.busy": "2025-09-10T15:34:25.695657Z", + "iopub.status.idle": "2025-09-10T15:34:26.994556Z", + "shell.execute_reply": "2025-09-10T15:34:26.994046Z", + "shell.execute_reply.started": "2025-09-10T15:34:25.695956Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Using model 'huggingface-llm-mistral-small-24B-Instruct-2501' with wildcard version identifier '*'. You can pin to version '3.0.0' for more stable results. Note that models may have different input/output signatures after a major version upgrade.\n" + ] + } + ], + "source": [ + "env = {\n", + " 'ENDPOINT_SERVER_TIMEOUT': '600',\n", + " 'SM_NUM_GPUS': json.dumps(4),\n", + " 'MESSAGES_API_ENABLED': 'true'\n", + "}\n", + "\n", + "model = JumpStartModel(\n", + " model_id=\"huggingface-llm-mistral-small-24B-Instruct-2501\",\n", + " enable_network_isolation=False,\n", + " env=env,\n", + " role=iam_role\n", + ")\n", + "\n", + "model.create()\n", + "model_name = model.name" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "f43aae8f-502f-4ab0-a4fc-fe8fbcbcdd54", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T15:34:39.669261Z", + "iopub.status.busy": "2025-09-10T15:34:39.668914Z", + "iopub.status.idle": "2025-09-10T15:34:40.315449Z", + "shell.execute_reply": "2025-09-10T15:34:40.314936Z", + "shell.execute_reply.started": "2025-09-10T15:34:39.669240Z" + } + }, + "outputs": [], + "source": [ + "# Create inference component\n", + "\n", + "mistral_7Bv03_ic = sagemaker_client.create_inference_component(\n", + " EndpointName=endpointName,\n", + " InferenceComponentName=inferenceComponentName,\n", + " RuntimeConfig={\n", + " 'CopyCount': 1\n", + " },\n", + " Specification={\n", + " 'ModelName': model_name,\n", + " 'StartupParameters': {\n", + " 'ModelDataDownloadTimeoutInSeconds': 3600,\n", + " 'ContainerStartupHealthCheckTimeoutInSeconds': 3600\n", + " },\n", + " 'ComputeResourceRequirements': {\n", + " 'MinMemoryRequiredInMb': 1024,\n", + " 'NumberOfAcceleratorDevicesRequired': 4,\n", + " }\n", + " },\n", + " Tags=[{\n", + " 'Key': 'Usage',\n", + " 'Value': 'Strands Agents'\n", + " }],\n", + " VariantName=\"AllTraffic\"\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "d7440010-016b-4d22-9532-a35426ce2c86", + "metadata": {}, + "source": [ + "
\n", + "⚠️ Note: Deployment of the Sagemaker Endpoint Inference Component will take 5~10 minutes. \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "6f1af96d-c8ff-4956-8272-c2bd9b6914cd", + "metadata": {}, + "source": [ + "## Must WAIT up to 10 minutes for Endpoint AutoScaling to complete\n", + "\n", + "**Notice**: If you get this error message below, you must WAIT for the endpoint to complete it's auto-scaling\n", + "\n", + "`ValidationError: An error occurred (ValidationError) when calling the InvokeEndpoint operation: Inference Component\n", + "has no capacity to process this request. ApplicationAutoScaling may be in-progress (if configured) or try to \n", + "increase the capacity by invoking UpdateInferenceComponentRuntimeConfig API.`\n", + "\n", + "If the cell below fails, you can simply retry after waiting." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "fd08268e", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T16:04:59.071151Z", + "iopub.status.busy": "2025-09-10T16:04:59.070822Z", + "iopub.status.idle": "2025-09-10T16:05:01.988520Z", + "shell.execute_reply": "2025-09-10T16:05:01.988009Z", + "shell.execute_reply.started": "2025-09-10T16:04:59.071131Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'id': 'chatcmpl-19101479311344f58381c4a5a3e75e47', 'object': 'chat.completion', 'created': 1757520299, 'model': 'lmi', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'reasoning_content': None, 'content': 'The square root of 81 is 9.\\n\\nThe significance of this result is that 9 is the number that, when multiplied by itself, gives 81. In mathematical terms, if \\\\( x^2 = 81 \\\\), then \\\\( x = \\\\sqrt{81} = 9 \\\\). This is a fundamental concept in algebra and arithmetic, demonstrating the relationship between a number and its square root.', 'tool_calls': []}, 'logprobs': None, 'finish_reason': 'stop', 'stop_reason': None}], 'usage': {'prompt_tokens': 33, 'total_tokens': 120, 'completion_tokens': 87, 'prompt_tokens_details': None}, 'prompt_logprobs': None}\n" + ] + } + ], + "source": [ + "messages = [\n", + " {\"role\": \"system\", \"content\": \"You are a helpful assistant capable of performing math calculations.\"},\n", + " {\"role\": \"user\", \"content\": \"Calculate the square root of 81. Briefly explain the significance of the result.\"}\n", + "]\n", + "\n", + "payload = {\n", + " \"messages\": messages,\n", + " \"max_tokens\": 4000,\n", + " \"temperature\": 0.1,\n", + " \"top_p\": 0.9,\n", + "}\n", + "\n", + "response_model = sagemaker_runtime.invoke_endpoint(\n", + " InferenceComponentName=inferenceComponentName,\n", + " EndpointName=endpointName,\n", + " Body=json.dumps({\n", + " \"messages\": messages,\n", + " \"parameters\": {\n", + " \"do_sample\": True,\n", + " \"max_new_tokens\": 256,\n", + " }\n", + " }),\n", + " ContentType=\"application/json\"\n", + ")\n", + "\n", + "response = json.loads(response_model['Body'].read().decode('utf-8'))\n", + "print(response)" + ] + }, + { + "cell_type": "markdown", + "id": "c0a39f67-2169-4251-abca-49a9c17614fa", + "metadata": {}, + "source": [ + "### Save Endpoint Name Attributes\n", + "\n", + "We save various attributes like endpoint name and inference component name using `store` magic command, as they will be needed in later notebooks." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "18e6de49-11f7-4e36-b7bb-322282a51e53", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T16:05:07.423227Z", + "iopub.status.busy": "2025-09-10T16:05:07.422911Z", + "iopub.status.idle": "2025-09-10T16:05:07.428807Z", + "shell.execute_reply": "2025-09-10T16:05:07.428336Z", + "shell.execute_reply.started": "2025-09-10T16:05:07.423207Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Endpoint name: strands-endpoint-001\n", + "Endpoint Config Name: strands-endpoint-config\n", + "Inference Component Name: mistral-24b-instruct-2501-ic\n", + "Stored 'MISTRAL_ENDPOINT_NAME' (str)\n", + "Stored 'MISTRAL_ENDPOINT_CONFIG_NAME' (str)\n", + "Stored 'MISTRAL_INFERENCE_COMPONENT_NAME' (str)\n" + ] + } + ], + "source": [ + "MISTRAL_ENDPOINT_NAME = endpointName\n", + "MISTRAL_ENDPOINT_CONFIG_NAME = endpointConfigName\n", + "MISTRAL_INFERENCE_COMPONENT_NAME = inferenceComponentName\n", + "\n", + "print(f\"Endpoint name: {MISTRAL_ENDPOINT_NAME}\")\n", + "print(f\"Endpoint Config Name: {MISTRAL_ENDPOINT_CONFIG_NAME}\")\n", + "print(f\"Inference Component Name: {MISTRAL_INFERENCE_COMPONENT_NAME}\")\n", + "\n", + "%store MISTRAL_ENDPOINT_NAME\n", + "%store MISTRAL_ENDPOINT_CONFIG_NAME\n", + "%store MISTRAL_INFERENCE_COMPONENT_NAME\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81cf1157-7f7e-4926-aa35-f78f66b1f03b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 4a55067a5d92b89f8b6177b9b84ce367c70ac6fb Mon Sep 17 00:00:00 2001 From: Paul Hargis Date: Wed, 10 Sep 2025 19:49:18 +0000 Subject: [PATCH 2/5] Minor updates: added markdown to Mistrall setup notebook. --- .../0-setup/2-setup-mistral-sagemaker-endpoint.ipynb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb index 5ec68ff..afe1cbb 100644 --- a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb @@ -475,7 +475,7 @@ "id": "c0a39f67-2169-4251-abca-49a9c17614fa", "metadata": {}, "source": [ - "### Save Endpoint Name Attributes\n", + "### Save names of Endpoint, Endpoint Config, and Inference Component\n", "\n", "We save various attributes like endpoint name and inference component name using `store` magic command, as they will be needed in later notebooks." ] @@ -518,8 +518,7 @@ "\n", "%store MISTRAL_ENDPOINT_NAME\n", "%store MISTRAL_ENDPOINT_CONFIG_NAME\n", - "%store MISTRAL_INFERENCE_COMPONENT_NAME\n", - " " + "%store MISTRAL_INFERENCE_COMPONENT_NAME\n" ] }, { From abb047d2d51056b5b29820170e0a3c6b49ff9bd9 Mon Sep 17 00:00:00 2001 From: Paul Hargis Date: Mon, 27 Oct 2025 11:46:03 -0500 Subject: [PATCH 3/5] Created bootcamp folder for Strands agents notebooks. --- .../1-required-dependencies-strands.ipynb | 249 +++++++++ .../2-setup-mistral-sagemaker-endpoint.ipynb | 515 ++++++++++++++++++ .../bootcamp/requirements-strands.txt | 25 + .../bootcamp/strands-agents-mistral-llm.ipynb | 483 ++++++++++++++++ 4 files changed, 1272 insertions(+) create mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/1-required-dependencies-strands.ipynb create mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/2-setup-mistral-sagemaker-endpoint.ipynb create mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/requirements-strands.txt create mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents-mistral-llm.ipynb diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/1-required-dependencies-strands.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/1-required-dependencies-strands.ipynb new file mode 100644 index 0000000..87f2c07 --- /dev/null +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/1-required-dependencies-strands.ipynb @@ -0,0 +1,249 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e05d69d6", + "metadata": {}, + "source": [ + "# Installing Dependencies\n", + "\n", + "Please install the dependencies before proceeding with the rest of the workshop." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "18de50ca", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:56:09.291906Z", + "iopub.status.busy": "2025-10-23T18:56:09.291582Z", + "iopub.status.idle": "2025-10-23T18:56:09.446265Z", + "shell.execute_reply": "2025-10-23T18:56:09.445577Z", + "shell.execute_reply.started": "2025-10-23T18:56:09.291885Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "strands-agents==1.4.0\n", + "strands-agents[sagemaker]\n", + "strands-agents-tools>=0.2.3\n", + "strands-agents-builder>=0.1.7\n", + "yfinance==0.2.65\n", + "matplotlib==3.10.3\n", + "beautifulsoup4>=4.13.4\n", + "pandas==2.3.0\n", + "seaborn==0.13.2\n", + "joblib==1.5.1\n", + "requests>=2.32.4\n", + "scikit-learn==1.7.0\n", + "uv==0.8.6\n", + "mem0ai==0.1.114\n", + "opensearch-py\n", + "ddgs==9.3.1\n", + "faiss-cpu==1.11.0\n", + "sagemaker==2.249.0\n", + "openai==1.99.3\n", + "aiohttp==3.12.15\n", + "boto3==1.39.8\n", + "bedrock-agentcore==0.1.1\n", + "bedrock-agentcore-starter-toolkit==0.1.5\n", + "botocore==1.39.8\n", + "litellm==1.72.2\n" + ] + } + ], + "source": [ + "!cat requirements-strands.txt" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d82dc1bd-c256-40a7-b25b-751ece4b43c1", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:56:09.447730Z", + "iopub.status.busy": "2025-10-23T18:56:09.447437Z", + "iopub.status.idle": "2025-10-23T18:56:13.687534Z", + "shell.execute_reply": "2025-10-23T18:56:13.686666Z", + "shell.execute_reply.started": "2025-10-23T18:56:09.447708Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "# Warnings are safe to ignore\n", + "%pip uninstall -q -y autogluon-multimodal autogluon-timeseries autogluon-features autogluon-common autogluon-core" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "1453ae11-d805-4f94-a299-7198638b80bf", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:56:13.689248Z", + "iopub.status.busy": "2025-10-23T18:56:13.688543Z", + "iopub.status.idle": "2025-10-23T18:56:45.305777Z", + "shell.execute_reply": "2025-10-23T18:56:45.305092Z", + "shell.execute_reply.started": "2025-10-23T18:56:13.689221Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "autogluon-tabular 1.3.1 requires autogluon.core==1.3.1, which is not installed.\n", + "autogluon-tabular 1.3.1 requires autogluon.features==1.3.1, which is not installed.\n", + "aiobotocore 2.21.1 requires botocore<1.37.2,>=1.37.0, but you have botocore 1.39.8 which is incompatible.\n", + "autogluon-tabular 1.3.1 requires pandas<2.3.0,>=2.0.0, but you have pandas 2.3.0 which is incompatible.\n", + "autogluon-tabular 1.3.1 requires scikit-learn<1.7.0,>=1.4.0, but you have scikit-learn 1.7.0 which is incompatible.\n", + "sagemaker-studio-analytics-extension 0.1.7 requires sparkmagic==0.22.0, but you have sparkmagic 0.21.0 which is incompatible.\n", + "sparkmagic 0.21.0 requires pandas<2.0.0,>=0.17.1, but you have pandas 2.3.0 which is incompatible.\u001b[0m\u001b[31m\n", + "\u001b[0mNote: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip install -q -r requirements-strands.txt" + ] + }, + { + "cell_type": "markdown", + "id": "a3fd75f2", + "metadata": {}, + "source": [ + "### This cell will restart the kernel. Wait for the pop-up box to appear, then click \"OK\" before proceeding." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b96ff09e", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:56:45.307086Z", + "iopub.status.busy": "2025-10-23T18:56:45.306710Z", + "iopub.status.idle": "2025-10-23T18:56:45.313401Z", + "shell.execute_reply": "2025-10-23T18:56:45.312862Z", + "shell.execute_reply.started": "2025-10-23T18:56:45.307049Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "{'status': 'ok', 'restart': True}" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from IPython import get_ipython\n", + "get_ipython().kernel.do_shutdown(True)" + ] + }, + { + "cell_type": "markdown", + "id": "351d1369-51aa-47bb-800b-653b3a734a8a", + "metadata": {}, + "source": [ + "### Cell below displays the installed versions of Strands libraries\n", + "\n", + "As a result of the `pip installs` above, this cell outputs the current versions of Strands libraries" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "9c692e9f-7072-4f90-aa8e-eda90ab04b3d", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:56:45.315004Z", + "iopub.status.busy": "2025-10-23T18:56:45.314775Z", + "iopub.status.idle": "2025-10-23T18:56:46.730733Z", + "shell.execute_reply": "2025-10-23T18:56:46.730034Z", + "shell.execute_reply.started": "2025-10-23T18:56:45.314988Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: strands-agents\n", + "Version: 1.4.0\n", + "Summary: A model-driven approach to building AI agents in just a few lines of code\n", + "Home-page: https://github.com/strands-agents/sdk-python\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder, strands-agents-tools\n", + "---\n", + "Name: strands-agents-tools\n", + "Version: 0.2.12\n", + "Summary: A collection of specialized tools for Strands Agents\n", + "Home-page: https://github.com/strands-agents/tools\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, requests, rich, slack-bolt, strands-agents, sympy, tenacity, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip show strands-agents strands-agents-tools" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9687e1a-9b01-4a48-ba06-c370158f1caf", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/2-setup-mistral-sagemaker-endpoint.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/2-setup-mistral-sagemaker-endpoint.ipynb new file mode 100644 index 0000000..97a25e9 --- /dev/null +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/2-setup-mistral-sagemaker-endpoint.ipynb @@ -0,0 +1,515 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "586f2662-a568-4c29-af10-7bcb2eadbf30", + "metadata": {}, + "source": [ + "# Deploying an LLM to Amazon SageMaker AI real-time endpoint\n", + "\n", + "## Prerequisites\n", + "\n", + "To use SageMaker AI endpoints in these examples, you will need to first deploy a managed endpoint. In this example you will deploy an endpoint through SageMaker Jumpstart, a feature that helps machine learning practitioners quickly get started with hundreds of production-ready models in SageMaker AI.\n", + "\n", + "## Dependencies\n", + "\n", + "
\n", + "⚠️ Important: Make sure you've run the 1-required-dependencies-strands.ipynb notebook in this folder before proceeding. If you haven't, close this notebook, run the previous one first, then come back to this.\n", + "
\n", + "\n", + "## Create Sagemaker Endpoint\n", + "\n", + "In this notebook, we first create an endpoint config that defines parameters for the endpoint. Then we specify an inference component that will field our requests. This component will create and kick-off the Sagemaker endpoint after some delay.\n", + "\n", + "**NOTE**: In order to deploy a Sagemaker Endpoint on a larger instance type, such as `ml.g5.48xlarge`, you may have to request a quota increase for your account. Please refer to AWS documentation on how to [increase quotas](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html). \n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "0f49d687-9592-4d6d-98e6-0e3a191f9fa1", + "metadata": {}, + "source": [ + "### Run this cell to make sure the Strands Agent libraries are installed" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b2ce612f-74cb-4c44-9483-a019bfa006d5", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:57:12.027566Z", + "iopub.status.busy": "2025-10-23T18:57:12.027229Z", + "iopub.status.idle": "2025-10-23T18:57:13.471878Z", + "shell.execute_reply": "2025-10-23T18:57:13.471110Z", + "shell.execute_reply.started": "2025-10-23T18:57:12.027543Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: strands-agents\n", + "Version: 1.4.0\n", + "Summary: A model-driven approach to building AI agents in just a few lines of code\n", + "Home-page: https://github.com/strands-agents/sdk-python\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder, strands-agents-tools\n", + "---\n", + "Name: strands-agents-tools\n", + "Version: 0.2.12\n", + "Summary: A collection of specialized tools for Strands Agents\n", + "Home-page: https://github.com/strands-agents/tools\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, requests, rich, slack-bolt, strands-agents, sympy, tenacity, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip show strands-agents strands-agents-tools" + ] + }, + { + "cell_type": "markdown", + "id": "b35c2bba-157b-49f5-9cf0-aaacf8f6347a", + "metadata": {}, + "source": [ + "### If Strands Agents libraries do not show above, then install them by running this cell" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b3530b42-c71f-4d70-8856-60f8e24603e8", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:57:13.473416Z", + "iopub.status.busy": "2025-10-23T18:57:13.473098Z", + "iopub.status.idle": "2025-10-23T18:57:13.476502Z", + "shell.execute_reply": "2025-10-23T18:57:13.475865Z", + "shell.execute_reply.started": "2025-10-23T18:57:13.473393Z" + } + }, + "outputs": [], + "source": [ + "# Uncomment line below to run pip install\n", + "# %pip install 'strands-agents[sagemaker]' strands-agents-tools" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3e8e0da6-0c35-484b-85dc-0510d0742b8d", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:57:13.477542Z", + "iopub.status.busy": "2025-10-23T18:57:13.477255Z", + "iopub.status.idle": "2025-10-23T18:57:15.551862Z", + "shell.execute_reply": "2025-10-23T18:57:15.551207Z", + "shell.execute_reply.started": "2025-10-23T18:57:13.477526Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml\n", + "sagemaker.config INFO - Not applying SDK defaults from location: /home/sagemaker-user/.config/sagemaker/config.yaml\n" + ] + } + ], + "source": [ + "import boto3\n", + "import json\n", + "from sagemaker import get_execution_role\n", + "from sagemaker.jumpstart.model import JumpStartModel\n", + "\n", + "# Setup role and sagemaker session\n", + "iam_role = get_execution_role()\n", + "boto_session = boto3.Session(region_name='us-west-2')\n", + "sagemaker_client = boto_session.client('sagemaker')\n", + "sagemaker_runtime = boto3.client(\"sagemaker-runtime\") \n", + "\n", + "# Names for endpoint config and endpoint\n", + "endpointName='strands-endpoint-001'\n", + "endpointConfigName='strands-endpoint-config'\n", + "inferenceComponentName='mistral-24b-instruct-2501-ic'\n" + ] + }, + { + "cell_type": "markdown", + "id": "c2bdb040-cb4d-464c-9c58-58c938e5e283", + "metadata": {}, + "source": [ + "## Delete Resources if they already exist\n", + "\n", + "**Note**: If you re-run this notebook, or see failures to create resources, run the next 3 cells to delete previously created resources." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24591a94-1ff5-4d12-a5ad-f32f75ad84df", + "metadata": {}, + "outputs": [], + "source": [ + "# Run this code to delete inference component (if exists)\n", + "sagemaker_client.delete_inference_component(InferenceComponentName=inferenceComponentName)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47f59cb0-e525-4d3b-b2f7-faa551fa967a", + "metadata": {}, + "outputs": [], + "source": [ + "# Run this line if the endpoint already exists\n", + "sagemaker_client.delete_endpoint(EndpointName=endpointName)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9185be4a-8252-4951-a0c0-de9de0505112", + "metadata": {}, + "outputs": [], + "source": [ + "# Run this line if the endpoint config already exists\n", + "sagemaker_client.delete_endpoint_config(EndpointConfigName=endpointConfigName)" + ] + }, + { + "cell_type": "markdown", + "id": "f0b8cfd4-b13a-4e4b-8dc3-48150f783536", + "metadata": {}, + "source": [ + "## Create Endpoint Config, Endpoint, and Inference Component" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "6d0587aa-3647-44b0-a29b-9ce65239c05b", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:57:51.765826Z", + "iopub.status.busy": "2025-10-23T18:57:51.765154Z", + "iopub.status.idle": "2025-10-23T18:57:52.135235Z", + "shell.execute_reply": "2025-10-23T18:57:52.134651Z", + "shell.execute_reply.started": "2025-10-23T18:57:51.765801Z" + } + }, + "outputs": [], + "source": [ + "# Create endpoint config\n", + "\n", + "endpoint_config = sagemaker_client.create_endpoint_config(\n", + " EndpointConfigName=endpointConfigName,\n", + " EnableNetworkIsolation=False,\n", + " ExecutionRoleArn=iam_role,\n", + " ProductionVariants=[\n", + " {\n", + " \"VariantName\": 'AllTraffic',\n", + " \"InstanceType\": 'ml.g5.48xlarge',\n", + " \"InitialInstanceCount\": 1,\n", + " \"ModelDataDownloadTimeoutInSeconds\": 3600,\n", + " \"ContainerStartupHealthCheckTimeoutInSeconds\": 3600,\n", + " \"ManagedInstanceScaling\": {\n", + " \"Status\": \"ENABLED\",\n", + " \"MinInstanceCount\": 0,\n", + " \"MaxInstanceCount\": 2,\n", + " },\n", + " \"RoutingConfig\": {\"RoutingStrategy\": \"LEAST_OUTSTANDING_REQUESTS\"},\n", + " }\n", + " ],\n", + ")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "65f574c2-6b35-4dc1-aeab-b35cf7214794", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:57:58.123249Z", + "iopub.status.busy": "2025-10-23T18:57:58.122746Z", + "iopub.status.idle": "2025-10-23T18:57:58.634838Z", + "shell.execute_reply": "2025-10-23T18:57:58.634214Z", + "shell.execute_reply.started": "2025-10-23T18:57:58.123226Z" + } + }, + "outputs": [], + "source": [ + "# Create endpoint\n", + "endpoint = sagemaker_client.create_endpoint(\n", + " EndpointName=endpointName,\n", + " EndpointConfigName=endpointConfigName\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "0e9a7f7c-429b-47e4-9cdc-b2b57821a7c2", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T18:58:05.686983Z", + "iopub.status.busy": "2025-10-23T18:58:05.686464Z", + "iopub.status.idle": "2025-10-23T18:58:07.044029Z", + "shell.execute_reply": "2025-10-23T18:58:07.043228Z", + "shell.execute_reply.started": "2025-10-23T18:58:05.686961Z" + } + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Using model 'huggingface-llm-mistral-small-24B-Instruct-2501' with wildcard version identifier '*'. You can pin to version '3.0.1' for more stable results. Note that models may have different input/output signatures after a major version upgrade.\n" + ] + } + ], + "source": [ + "env = {\n", + " 'ENDPOINT_SERVER_TIMEOUT': '600',\n", + " 'SM_NUM_GPUS': json.dumps(4),\n", + " 'MESSAGES_API_ENABLED': 'true'\n", + "}\n", + "\n", + "model = JumpStartModel(\n", + " model_id=\"huggingface-llm-mistral-small-24B-Instruct-2501\",\n", + " enable_network_isolation=False,\n", + " env=env,\n", + " role=iam_role\n", + ")\n", + "\n", + "model.create()\n", + "model_name = model.name" + ] + }, + { + "cell_type": "markdown", + "id": "5cca4816-91d8-4ce0-874a-96ba082585fa", + "metadata": {}, + "source": [ + "### WAIT up to 5 minutes before creating Inference Component\n", + "\n", + "Typically, we need to wait up to 5 minutes for Endpoint creation before creating an Inference Component\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "f43aae8f-502f-4ab0-a4fc-fe8fbcbcdd54", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:08:58.723395Z", + "iopub.status.busy": "2025-10-23T19:08:58.722664Z", + "iopub.status.idle": "2025-10-23T19:08:59.327823Z", + "shell.execute_reply": "2025-10-23T19:08:59.327222Z", + "shell.execute_reply.started": "2025-10-23T19:08:58.723357Z" + } + }, + "outputs": [], + "source": [ + "# Create inference component\n", + "\n", + "mistral_7Bv03_ic = sagemaker_client.create_inference_component(\n", + " EndpointName=endpointName,\n", + " InferenceComponentName=inferenceComponentName,\n", + " RuntimeConfig={\n", + " 'CopyCount': 1\n", + " },\n", + " Specification={\n", + " 'ModelName': model_name,\n", + " 'StartupParameters': {\n", + " 'ModelDataDownloadTimeoutInSeconds': 3600,\n", + " 'ContainerStartupHealthCheckTimeoutInSeconds': 3600\n", + " },\n", + " 'ComputeResourceRequirements': {\n", + " 'MinMemoryRequiredInMb': 1024,\n", + " 'NumberOfAcceleratorDevicesRequired': 4,\n", + " }\n", + " },\n", + " Tags=[{\n", + " 'Key': 'Usage',\n", + " 'Value': 'Strands Agents'\n", + " }],\n", + " VariantName=\"AllTraffic\"\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "d7440010-016b-4d22-9532-a35426ce2c86", + "metadata": {}, + "source": [ + "
\n", + "⚠️ Note: Deployment of the Sagemaker Endpoint Inference Component can take 5~10 minutes. \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "6f1af96d-c8ff-4956-8272-c2bd9b6914cd", + "metadata": {}, + "source": [ + "## Must WAIT up to 10 minutes for Endpoint AutoScaling to complete\n", + "\n", + "**Notice**: If you get this error message below, you must WAIT for the endpoint to complete it's auto-scaling\n", + "\n", + "`ValidationError: An error occurred (ValidationError) when calling the InvokeEndpoint operation: Inference Component\n", + "has no capacity to process this request. ApplicationAutoScaling may be in-progress (if configured) or try to \n", + "increase the capacity by invoking UpdateInferenceComponentRuntimeConfig API.`\n", + "\n", + "If the cell below fails, you can simply retry after waiting." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "fd08268e", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:17:30.026103Z", + "iopub.status.busy": "2025-10-23T19:17:30.025372Z", + "iopub.status.idle": "2025-10-23T19:17:32.901765Z", + "shell.execute_reply": "2025-10-23T19:17:32.901217Z", + "shell.execute_reply.started": "2025-10-23T19:17:30.026075Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'id': 'chatcmpl-cfd4211fdae847d7ab0a21cb09e8d295', 'object': 'chat.completion', 'created': 1761247050, 'model': 'lmi', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'reasoning_content': None, 'content': 'The square root of 81 is 9.\\n\\nThe significance of this result is that 9 is the number that, when multiplied by itself, gives 81. In mathematical terms, if \\\\( x^2 = 81 \\\\), then \\\\( x = \\\\sqrt{81} = 9 \\\\). This is a fundamental concept in algebra and arithmetic, demonstrating the relationship between a number and its square root.', 'tool_calls': []}, 'logprobs': None, 'finish_reason': 'stop', 'stop_reason': None}], 'usage': {'prompt_tokens': 33, 'total_tokens': 120, 'completion_tokens': 87, 'prompt_tokens_details': None}, 'prompt_logprobs': None}\n" + ] + } + ], + "source": [ + "messages = [\n", + " {\"role\": \"system\", \"content\": \"You are a helpful assistant capable of performing math calculations.\"},\n", + " {\"role\": \"user\", \"content\": \"Calculate the square root of 81. Briefly explain the significance of the result.\"}\n", + "]\n", + "\n", + "payload = {\n", + " \"messages\": messages,\n", + " \"max_tokens\": 4000,\n", + " \"temperature\": 0.1,\n", + " \"top_p\": 0.9,\n", + "}\n", + "\n", + "response_model = sagemaker_runtime.invoke_endpoint(\n", + " InferenceComponentName=inferenceComponentName,\n", + " EndpointName=endpointName,\n", + " Body=json.dumps({\n", + " \"messages\": messages,\n", + " \"parameters\": {\n", + " \"do_sample\": True,\n", + " \"max_new_tokens\": 256,\n", + " }\n", + " }),\n", + " ContentType=\"application/json\"\n", + ")\n", + "\n", + "response = json.loads(response_model['Body'].read().decode('utf-8'))\n", + "print(response)" + ] + }, + { + "cell_type": "markdown", + "id": "c0a39f67-2169-4251-abca-49a9c17614fa", + "metadata": {}, + "source": [ + "### Save names of Endpoint, Endpoint Config, and Inference Component\n", + "\n", + "We save various attributes like endpoint name and inference component name using `store` magic command, as they will be needed in later notebooks." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "18e6de49-11f7-4e36-b7bb-322282a51e53", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:17:39.004479Z", + "iopub.status.busy": "2025-10-23T19:17:39.003837Z", + "iopub.status.idle": "2025-10-23T19:17:39.009923Z", + "shell.execute_reply": "2025-10-23T19:17:39.009369Z", + "shell.execute_reply.started": "2025-10-23T19:17:39.004457Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Endpoint name: strands-endpoint-001\n", + "Endpoint Config Name: strands-endpoint-config\n", + "Inference Component Name: mistral-24b-instruct-2501-ic\n", + "Stored 'MISTRAL_ENDPOINT_NAME' (str)\n", + "Stored 'MISTRAL_ENDPOINT_CONFIG_NAME' (str)\n", + "Stored 'MISTRAL_INFERENCE_COMPONENT_NAME' (str)\n" + ] + } + ], + "source": [ + "MISTRAL_ENDPOINT_NAME = endpointName\n", + "MISTRAL_ENDPOINT_CONFIG_NAME = endpointConfigName\n", + "MISTRAL_INFERENCE_COMPONENT_NAME = inferenceComponentName\n", + "\n", + "print(f\"Endpoint name: {MISTRAL_ENDPOINT_NAME}\")\n", + "print(f\"Endpoint Config Name: {MISTRAL_ENDPOINT_CONFIG_NAME}\")\n", + "print(f\"Inference Component Name: {MISTRAL_INFERENCE_COMPONENT_NAME}\")\n", + "\n", + "%store MISTRAL_ENDPOINT_NAME\n", + "%store MISTRAL_ENDPOINT_CONFIG_NAME\n", + "%store MISTRAL_INFERENCE_COMPONENT_NAME\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "81cf1157-7f7e-4926-aa35-f78f66b1f03b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/requirements-strands.txt b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/requirements-strands.txt new file mode 100644 index 0000000..7f4c0c5 --- /dev/null +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/requirements-strands.txt @@ -0,0 +1,25 @@ +strands-agents==1.4.0 +strands-agents[sagemaker] +strands-agents-tools>=0.2.3 +strands-agents-builder>=0.1.7 +yfinance==0.2.65 +matplotlib==3.10.3 +beautifulsoup4>=4.13.4 +pandas==2.3.0 +seaborn==0.13.2 +joblib==1.5.1 +requests>=2.32.4 +scikit-learn==1.7.0 +uv==0.8.6 +mem0ai==0.1.114 +opensearch-py +ddgs==9.3.1 +faiss-cpu==1.11.0 +sagemaker==2.249.0 +openai==1.99.3 +aiohttp==3.12.15 +boto3==1.39.8 +bedrock-agentcore==0.1.1 +bedrock-agentcore-starter-toolkit==0.1.5 +botocore==1.39.8 +litellm==1.72.2 diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents-mistral-llm.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents-mistral-llm.ipynb new file mode 100644 index 0000000..0fcd367 --- /dev/null +++ b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents-mistral-llm.ipynb @@ -0,0 +1,483 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d9a520cf-9179-4043-8a25-8529ecc98ee6", + "metadata": {}, + "source": [ + "# Running Strands Agents with Sagemaker Endpoint using Mistral LLM" + ] + }, + { + "cell_type": "markdown", + "id": "e7321015-e901-4e68-bf20-5c7cfdebd3fc", + "metadata": {}, + "source": [ + "## Purpose\n", + "\n", + "We will use the Strands Agent SDK to query SageMaker AI Inference Endpoints. We use the LLM `Mistral-Small-24B-Instruct-2501` from Sagemaker JumpStart model hub. We create a Strands agent and use it to invoke a previously created inference component.\n", + "\n", + "Inference Components are a feature of SageMakerAI announced at re:Invent 2023. Inference Components allow models to be deployed and scaled independent of their hosting infrastructure. They are a more efficient way to use the hardware that hosts GPU-accelerated models. We can deploy the Mistral model we just registered to an Inference Component on our host using the below code.\n", + "\n", + "## Prerequisites\n", + "\n", + "To use SageMaker AI endpoints in these examples, you will need to first deploy a managed endpoint. In this example, you will leverage an already-deployed endpoint running Mistral LLM on Sagemaker AI. Below, you will create and use a Strands Agent to invoke the Mistral LLM, and use the agent code to reason about math.\n", + "\n", + "## Dependencies\n", + "\n", + "
\n", + "⚠️ Important: (1) Make sure you've run the 0-setup/1-required-dependencies-strands.ipynb notebook before proceeding. If you haven't, close this notebook, run that notebook first, then come back here.\n", + "
\n", + "\n", + "
\n", + "⚠️ Important: (2) To use Amazon SageMaker AI for running the Inference Endpoint, make sure you've run the 0-setup/2-setup-mistral-sagemaker-endpoint.ipynb notebook before proceeding. If you haven't, close this notebook, run that notebook first, then come back here.\n", + "
\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "9b607abc-2377-45c2-882d-a6b32d9107c9", + "metadata": {}, + "source": [ + "## Preparation" + ] + }, + { + "cell_type": "markdown", + "id": "396f592f-0199-4863-a1c8-0c494f563357", + "metadata": {}, + "source": [ + "### Run this cell to make sure the Strands Agent libraries are installed" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "eb6136ff-d4c4-4522-bf47-059095eb8d0f", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:17:49.418610Z", + "iopub.status.busy": "2025-10-23T19:17:49.418291Z", + "iopub.status.idle": "2025-10-23T19:17:50.826194Z", + "shell.execute_reply": "2025-10-23T19:17:50.825519Z", + "shell.execute_reply.started": "2025-10-23T19:17:49.418585Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Name: strands-agents\n", + "Version: 1.4.0\n", + "Summary: A model-driven approach to building AI agents in just a few lines of code\n", + "Home-page: https://github.com/strands-agents/sdk-python\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder, strands-agents-tools\n", + "---\n", + "Name: strands-agents-tools\n", + "Version: 0.2.12\n", + "Summary: A collection of specialized tools for Strands Agents\n", + "Home-page: https://github.com/strands-agents/tools\n", + "Author: \n", + "Author-email: AWS \n", + "License: Apache-2.0\n", + "Location: /opt/conda/lib/python3.12/site-packages\n", + "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, requests, rich, slack-bolt, strands-agents, sympy, tenacity, typing-extensions, watchdog\n", + "Required-by: strands-agents-builder\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "%pip show strands-agents strands-agents-tools" + ] + }, + { + "cell_type": "markdown", + "id": "fad77170-f9e6-4693-8d7f-2ddfbc7e0c68", + "metadata": {}, + "source": [ + "### If Strands Agents libraries do not show above, then install them by running this cell" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3b3d9d50-df62-4eac-9ca5-f15e53d578a6", + "metadata": {}, + "outputs": [], + "source": [ + "# Uncomment line below to run pip install\n", + "# %pip install 'strands-agents[sagemaker]' strands-agents-tools" + ] + }, + { + "cell_type": "markdown", + "id": "d6b2d56d-6ee9-4892-ac90-ad947cc53926", + "metadata": {}, + "source": [ + "### Restore names of Endpoint, Endpoint Config, and Inference Component\n", + "\n", + "Previously run notebook should have stored these variables into local memory" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b4041914-1db7-4379-bbcb-bbafd92726ac", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:17:55.193156Z", + "iopub.status.busy": "2025-10-23T19:17:55.192788Z", + "iopub.status.idle": "2025-10-23T19:17:55.199145Z", + "shell.execute_reply": "2025-10-23T19:17:55.198569Z", + "shell.execute_reply.started": "2025-10-23T19:17:55.193129Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Endpoint name: strands-endpoint-001\n", + "Endpoint Config Name: strands-endpoint-config\n", + "Inference Component Name: mistral-24b-instruct-2501-ic\n" + ] + } + ], + "source": [ + "%store -r MISTRAL_ENDPOINT_NAME\n", + "print(f\"Endpoint name: {MISTRAL_ENDPOINT_NAME}\")\n", + "\n", + "%store -r MISTRAL_ENDPOINT_CONFIG_NAME\n", + "print(f\"Endpoint Config Name: {MISTRAL_ENDPOINT_CONFIG_NAME}\")\n", + "\n", + "%store -r MISTRAL_INFERENCE_COMPONENT_NAME\n", + "print(f\"Inference Component Name: {MISTRAL_INFERENCE_COMPONENT_NAME}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3b4b7db0-3116-4963-af9e-b5de8777cbc5", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:17:57.950206Z", + "iopub.status.busy": "2025-10-23T19:17:57.949879Z", + "iopub.status.idle": "2025-10-23T19:17:59.828217Z", + "shell.execute_reply": "2025-10-23T19:17:59.827621Z", + "shell.execute_reply.started": "2025-10-23T19:17:57.950185Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml\n", + "sagemaker.config INFO - Not applying SDK defaults from location: /home/sagemaker-user/.config/sagemaker/config.yaml\n" + ] + } + ], + "source": [ + "import boto3\n", + "import json\n", + "from sagemaker import get_execution_role\n", + "\n", + "# Setup role and sagemaker session\n", + "iam_role = get_execution_role()\n", + "boto_session = boto3.Session(region_name='us-west-2')\n" + ] + }, + { + "cell_type": "markdown", + "id": "19296faf-26f1-44fd-9faf-9ba5dd9a8fc7", + "metadata": { + "execution": { + "iopub.execute_input": "2025-09-10T18:39:31.994160Z", + "iopub.status.busy": "2025-09-10T18:39:31.993848Z", + "iopub.status.idle": "2025-09-10T18:39:32.003937Z", + "shell.execute_reply": "2025-09-10T18:39:32.003289Z", + "shell.execute_reply.started": "2025-09-10T18:39:31.994139Z" + } + }, + "source": [ + "## Create Strands Agent and Sagemaker AI Model\n", + "\n", + "First, we create an instance of **SageMakerAIModel** based on the Mistral LLM endpoint previously deployed. \n", + "Next, we create a Strand Agent that wraps that model and allows us to submit queries.\n", + "\n", + "More info: [see Strands Sagemaker Docs](https://strandsagents.com/latest/documentation/docs/user-guide/concepts/model-providers/sagemaker/)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d2d5c860-b3b5-4a5a-89eb-533ef70c3cf8", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:18:20.935239Z", + "iopub.status.busy": "2025-10-23T19:18:20.934724Z", + "iopub.status.idle": "2025-10-23T19:18:21.593629Z", + "shell.execute_reply": "2025-10-23T19:18:21.593149Z", + "shell.execute_reply.started": "2025-10-23T19:18:20.935216Z" + } + }, + "outputs": [], + "source": [ + "import strands\n", + "from strands import Agent\n", + "from strands.models.sagemaker import SageMakerAIModel\n", + "import logging\n", + "import sys\n", + "\n", + "logging.getLogger(\"strands\").setLevel(logging.INFO)\n", + "logging.basicConfig(\n", + " format=\"%(levelname)s | %(name)s | %(message)s\",\n", + " handlers=[logging.StreamHandler(sys.stdout)]\n", + ")\n", + "\n", + "model = SageMakerAIModel(\n", + " endpoint_config={\n", + " 'endpoint_name': MISTRAL_ENDPOINT_NAME,\n", + " 'region_name': 'us-west-2',\n", + " 'inference_component_name': MISTRAL_INFERENCE_COMPONENT_NAME,\n", + " },\n", + " payload_config={\n", + " 'max_tokens': 4000,\n", + " 'temperature': 0.1,\n", + " 'top_p': 0.9,\n", + " 'stream': False\n", + " },\n", + " boto_session=boto_session\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "54d94ed0-bce1-43e4-9e6f-e1940d625d42", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:24:49.616038Z", + "iopub.status.busy": "2025-10-23T19:24:49.615457Z", + "iopub.status.idle": "2025-10-23T19:24:49.619214Z", + "shell.execute_reply": "2025-10-23T19:24:49.618690Z", + "shell.execute_reply.started": "2025-10-23T19:24:49.616012Z" + } + }, + "outputs": [], + "source": [ + "messages = [\n", + " {\"role\": \"system\", \"content\": \"You are a helpful assistant capable of explaining physics concepts.\"},\n", + " {\"role\": \"user\", \"content\": \"Explain the basics of Einstein's Special Theory of Relativity. Also explain how it was proven via actual measurements.\"}\n", + "]\n", + "\n", + "payload = {\n", + " \"messages\": messages,\n", + " \"max_tokens\": 4000,\n", + " \"temperature\": 0.1,\n", + " \"top_p\": 0.9,\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "2329d2cd-597b-45af-ad33-fd364205f401", + "metadata": { + "execution": { + "iopub.execute_input": "2025-10-23T19:24:53.697655Z", + "iopub.status.busy": "2025-10-23T19:24:53.697325Z", + "iopub.status.idle": "2025-10-23T19:25:14.402253Z", + "shell.execute_reply": "2025-10-23T19:25:14.401636Z", + "shell.execute_reply.started": "2025-10-23T19:24:53.697634Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO | strands.models.sagemaker | payload=<{\n", + " \"messages\": [\n", + " {\n", + " \"role\": \"system\",\n", + " \"content\": \"You are a helpful assistant capable of explaining physics concepts.\"\n", + " },\n", + " {\n", + " \"role\": \"user\",\n", + " \"content\": [\n", + " {\n", + " \"text\": \"Explain the basics of Einstein's Special Theory of Relativity. Also explain how it was proven via actual measurements.\",\n", + " \"type\": \"text\"\n", + " }\n", + " ]\n", + " }\n", + " ],\n", + " \"max_tokens\": 4000,\n", + " \"temperature\": 0.1,\n", + " \"top_p\": 0.9,\n", + " \"stream\": false\n", + "}>\n", + "INFO | strands.models.sagemaker | response=<{\n", + " \"id\": \"chatcmpl-4f2db84c9278430e87541bf9d88f4499\",\n", + " \"object\": \"chat.completion\",\n", + " \"created\": 1761247493,\n", + " \"model\": \"lmi\",\n", + " \"choices\": [\n", + " {\n", + " \"index\": 0,\n", + " \"message\": {\n", + " \"role\": \"assistant\",\n", + " \"reasoning_content\": null,\n", + " \"content\": \"Einstein's Special Theory of Relativity, published in 1905, is a fundamental theory in physics that describes the relationship between space and time. Here are the basics:\\n\\n### Key Concepts:\\n\\n1. **Principle of Relativity**:\\n - The laws of physics are the same for all observers in uniform motion relative to one another. This means that there is no preferred inertial reference frame.\\n\\n2. **Constancy of the Speed of Light**:\\n - The speed of light in a vacuum is the same for all observers, regardless of their motion or the source of light. This speed is approximately 299,792,458 meters per second.\\n\\n3. **Time Dilation**:\\n - Moving clocks run slower than stationary ones. This means that time passes more slowly for an object in motion relative to a stationary observer.\\n\\n4. **Length Contraction**:\\n - Moving objects shorten in the direction of motion. This means that the length of an object is measured to be shorter in the direction of its motion relative to a stationary observer.\\n\\n5. **Relativistic Mass Increase**:\\n - The mass of an object increases with its velocity. This effect is more pronounced as the object approaches the speed of light.\\n\\n6. **Mass-Energy Equivalence**:\\n - Mass and energy are interchangeable. This is famously expressed by the equation \\\\( E = mc^2 \\\\), where \\\\( E \\\\) is energy, \\\\( m \\\\) is mass, and \\\\( c \\\\) is the speed of light.\\n\\n### Proof via Actual Measurements:\\n\\nThe predictions of Special Relativity have been extensively tested and confirmed through various experiments and observations:\\n\\n1. **Michelson-Morley Experiment (1887)**:\\n - This experiment aimed to detect the \\\"luminiferous aether,\\\" a hypothetical medium through which light was thought to travel. The null result of the experiment (no detection of aether) was consistent with the principle of relativity and the constancy of the speed of light.\\n\\n2. **Hafele-Keating Experiment (1971)**:\\n - This experiment involved flying cesium-beam atomic clocks around the world on commercial airliners. The clocks were compared to stationary clocks, and the results confirmed the predictions of time dilation due to both special and general relativity.\\n\\n3. **Particle Accelerators**:\\n - Experiments in particle accelerators, such as the Large Hadron Collider (LHC), have confirmed the effects of time dilation and relativistic mass increase. Particles moving at speeds close to the speed of light exhibit the predicted relativistic effects.\\n\\n4. **Muon Decay**:\\n - Muons are subatomic particles that decay quickly when at rest. However, when moving at high speeds (e.g., in the Earth's atmosphere), they live longer due to time dilation. This has been observed and confirmed in experiments.\\n\\n5. **GPS Systems**:\\n - Global Positioning System (GPS) satellites rely on the principles of special relativity to correct for time dilation effects. Without these corrections, the GPS system would not function accurately.\\n\\nThese experiments and observations provide strong evidence supporting the predictions of Einstein's Special Theory of Relativity, making it one of the most well-established theories in modern physics.\",\n", + " \"tool_calls\": []\n", + " },\n", + " \"logprobs\": null,\n", + " \"finish_reason\": \"stop\",\n", + " \"stop_reason\": null\n", + " }\n", + " ],\n", + " \"usage\": {\n", + " \"prompt_tokens\": 39,\n", + " \"total_tokens\": 704,\n", + " \"completion_tokens\": 665,\n", + " \"prompt_tokens_details\": null\n", + " },\n", + " \"prompt_logprobs\": null\n", + "}>\n", + "Einstein's Special Theory of Relativity, published in 1905, is a fundamental theory in physics that describes the relationship between space and time. Here are the basics:\n", + "\n", + "### Key Concepts:\n", + "\n", + "1. **Principle of Relativity**:\n", + " - The laws of physics are the same for all observers in uniform motion relative to one another. This means that there is no preferred inertial reference frame.\n", + "\n", + "2. **Constancy of the Speed of Light**:\n", + " - The speed of light in a vacuum is the same for all observers, regardless of their motion or the source of light. This speed is approximately 299,792,458 meters per second.\n", + "\n", + "3. **Time Dilation**:\n", + " - Moving clocks run slower than stationary ones. This means that time passes more slowly for an object in motion relative to a stationary observer.\n", + "\n", + "4. **Length Contraction**:\n", + " - Moving objects shorten in the direction of motion. This means that the length of an object is measured to be shorter in the direction of its motion relative to a stationary observer.\n", + "\n", + "5. **Relativistic Mass Increase**:\n", + " - The mass of an object increases with its velocity. This effect is more pronounced as the object approaches the speed of light.\n", + "\n", + "6. **Mass-Energy Equivalence**:\n", + " - Mass and energy are interchangeable. This is famously expressed by the equation \\( E = mc^2 \\), where \\( E \\) is energy, \\( m \\) is mass, and \\( c \\) is the speed of light.\n", + "\n", + "### Proof via Actual Measurements:\n", + "\n", + "The predictions of Special Relativity have been extensively tested and confirmed through various experiments and observations:\n", + "\n", + "1. **Michelson-Morley Experiment (1887)**:\n", + " - This experiment aimed to detect the \"luminiferous aether,\" a hypothetical medium through which light was thought to travel. The null result of the experiment (no detection of aether) was consistent with the principle of relativity and the constancy of the speed of light.\n", + "\n", + "2. **Hafele-Keating Experiment (1971)**:\n", + " - This experiment involved flying cesium-beam atomic clocks around the world on commercial airliners. The clocks were compared to stationary clocks, and the results confirmed the predictions of time dilation due to both special and general relativity.\n", + "\n", + "3. **Particle Accelerators**:\n", + " - Experiments in particle accelerators, such as the Large Hadron Collider (LHC), have confirmed the effects of time dilation and relativistic mass increase. Particles moving at speeds close to the speed of light exhibit the predicted relativistic effects.\n", + "\n", + "4. **Muon Decay**:\n", + " - Muons are subatomic particles that decay quickly when at rest. However, when moving at high speeds (e.g., in the Earth's atmosphere), they live longer due to time dilation. This has been observed and confirmed in experiments.\n", + "\n", + "5. **GPS Systems**:\n", + " - Global Positioning System (GPS) satellites rely on the principles of special relativity to correct for time dilation effects. Without these corrections, the GPS system would not function accurately.\n", + "\n", + "These experiments and observations provide strong evidence supporting the predictions of Einstein's Special Theory of Relativity, making it one of the most well-established theories in modern physics.Einstein's Special Theory of Relativity, published in 1905, is a fundamental theory in physics that describes the relationship between space and time. Here are the basics:\n", + "\n", + "### Key Concepts:\n", + "\n", + "1. **Principle of Relativity**:\n", + " - The laws of physics are the same for all observers in uniform motion relative to one another. This means that there is no preferred inertial reference frame.\n", + "\n", + "2. **Constancy of the Speed of Light**:\n", + " - The speed of light in a vacuum is the same for all observers, regardless of their motion or the source of light. This speed is approximately 299,792,458 meters per second.\n", + "\n", + "3. **Time Dilation**:\n", + " - Moving clocks run slower than stationary ones. This means that time passes more slowly for an object in motion relative to a stationary observer.\n", + "\n", + "4. **Length Contraction**:\n", + " - Moving objects shorten in the direction of motion. This means that the length of an object is measured to be shorter in the direction of its motion relative to a stationary observer.\n", + "\n", + "5. **Relativistic Mass Increase**:\n", + " - The mass of an object increases with its velocity. This effect is more pronounced as the object approaches the speed of light.\n", + "\n", + "6. **Mass-Energy Equivalence**:\n", + " - Mass and energy are interchangeable. This is famously expressed by the equation \\( E = mc^2 \\), where \\( E \\) is energy, \\( m \\) is mass, and \\( c \\) is the speed of light.\n", + "\n", + "### Proof via Actual Measurements:\n", + "\n", + "The predictions of Special Relativity have been extensively tested and confirmed through various experiments and observations:\n", + "\n", + "1. **Michelson-Morley Experiment (1887)**:\n", + " - This experiment aimed to detect the \"luminiferous aether,\" a hypothetical medium through which light was thought to travel. The null result of the experiment (no detection of aether) was consistent with the principle of relativity and the constancy of the speed of light.\n", + "\n", + "2. **Hafele-Keating Experiment (1971)**:\n", + " - This experiment involved flying cesium-beam atomic clocks around the world on commercial airliners. The clocks were compared to stationary clocks, and the results confirmed the predictions of time dilation due to both special and general relativity.\n", + "\n", + "3. **Particle Accelerators**:\n", + " - Experiments in particle accelerators, such as the Large Hadron Collider (LHC), have confirmed the effects of time dilation and relativistic mass increase. Particles moving at speeds close to the speed of light exhibit the predicted relativistic effects.\n", + "\n", + "4. **Muon Decay**:\n", + " - Muons are subatomic particles that decay quickly when at rest. However, when moving at high speeds (e.g., in the Earth's atmosphere), they live longer due to time dilation. This has been observed and confirmed in experiments.\n", + "\n", + "5. **GPS Systems**:\n", + " - Global Positioning System (GPS) satellites rely on the principles of special relativity to correct for time dilation effects. Without these corrections, the GPS system would not function accurately.\n", + "\n", + "These experiments and observations provide strong evidence supporting the predictions of Einstein's Special Theory of Relativity, making it one of the most well-established theories in modern physics.\n", + "\n" + ] + } + ], + "source": [ + "agent = Agent(\n", + " model=model,\n", + " system_prompt=messages[0][\"content\"]\n", + ")\n", + "\n", + "result = agent(messages[1][\"content\"])\n", + "print(result)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "864d8390-2618-416d-813e-5f20d3271f40", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 32014522320c8d04346bb40bd45ebc2c1260e01d Mon Sep 17 00:00:00 2001 From: Paul Hargis Date: Mon, 27 Oct 2025 12:05:11 -0500 Subject: [PATCH 4/5] Updated strands-agents folder with newer notebooks. Conflicts: workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb Last commands done (2 commands done): pick c8a2c3d # Created bootcamp folder for Strands agents notebooks. pick e5704fb # Updated strands-agents folder with newer notebooks. --- .../1-required-dependencies-strands.ipynb | 246 -------- .../2-setup-mistral-sagemaker-endpoint.ipynb | 554 ------------------ 2 files changed, 800 deletions(-) delete mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb delete mode 100644 workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb deleted file mode 100644 index 426e5e0..0000000 --- a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/1-required-dependencies-strands.ipynb +++ /dev/null @@ -1,246 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "e05d69d6", - "metadata": {}, - "source": [ - "# Installing Dependencies\n", - "\n", - "Please install the dependencies before proceeding with the rest of the workshop." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "18de50ca", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:26:53.038020Z", - "iopub.status.busy": "2025-09-10T15:26:53.037704Z", - "iopub.status.idle": "2025-09-10T15:26:53.185121Z", - "shell.execute_reply": "2025-09-10T15:26:53.184531Z", - "shell.execute_reply.started": "2025-09-10T15:26:53.037993Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "strands-agents==1.4.0\n", - "strands-agents[sagemaker]\n", - "strands-agents-tools>=0.2.3\n", - "strands-agents-builder>=0.1.7\n", - "yfinance==0.2.65\n", - "matplotlib==3.10.3\n", - "beautifulsoup4>=4.13.4\n", - "pandas==2.3.0\n", - "seaborn==0.13.2\n", - "joblib==1.5.1\n", - "requests>=2.32.4\n", - "scikit-learn==1.7.0\n", - "uv==0.8.6\n", - "mem0ai==0.1.114\n", - "opensearch-py\n", - "ddgs==9.3.1\n", - "faiss-cpu==1.11.0\n", - "sagemaker==2.249.0\n", - "openai==1.99.3\n", - "aiohttp==3.12.15\n", - "boto3==1.39.8\n", - "bedrock-agentcore==0.1.1\n", - "bedrock-agentcore-starter-toolkit==0.1.5\n", - "botocore==1.39.8\n", - "litellm==1.72.2\n" - ] - } - ], - "source": [ - "!cat requirements-strands.txt" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "d82dc1bd-c256-40a7-b25b-751ece4b43c1", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:26:55.416854Z", - "iopub.status.busy": "2025-09-10T15:26:55.416508Z", - "iopub.status.idle": "2025-09-10T15:26:55.974046Z", - "shell.execute_reply": "2025-09-10T15:26:55.973427Z", - "shell.execute_reply.started": "2025-09-10T15:26:55.416830Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[33mWARNING: Skipping autogluon-multimodal as it is not installed.\u001b[0m\u001b[33m\n", - "\u001b[0m\u001b[33mWARNING: Skipping autogluon-timeseries as it is not installed.\u001b[0m\u001b[33m\n", - "\u001b[0m\u001b[33mWARNING: Skipping autogluon-features as it is not installed.\u001b[0m\u001b[33m\n", - "\u001b[0m\u001b[33mWARNING: Skipping autogluon-common as it is not installed.\u001b[0m\u001b[33m\n", - "\u001b[0m\u001b[33mWARNING: Skipping autogluon-core as it is not installed.\u001b[0m\u001b[33m\n", - "\u001b[0mNote: you may need to restart the kernel to use updated packages.\n" - ] - } - ], - "source": [ - "# Warnings are safe to ignore\n", - "%pip uninstall -q -y autogluon-multimodal autogluon-timeseries autogluon-features autogluon-common autogluon-core" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "1453ae11-d805-4f94-a299-7198638b80bf", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:27:02.652613Z", - "iopub.status.busy": "2025-09-10T15:27:02.652276Z", - "iopub.status.idle": "2025-09-10T15:27:04.912916Z", - "shell.execute_reply": "2025-09-10T15:27:04.912260Z", - "shell.execute_reply.started": "2025-09-10T15:27:02.652587Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], - "source": [ - "%pip install -q -r requirements-strands.txt" - ] - }, - { - "cell_type": "markdown", - "id": "a3fd75f2", - "metadata": {}, - "source": [ - "### This cell will restart the kernel. Wait for the pop-up box to appear, then click \"OK\" before proceeding." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "b96ff09e", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:27:08.212243Z", - "iopub.status.busy": "2025-09-10T15:27:08.211902Z", - "iopub.status.idle": "2025-09-10T15:27:08.218540Z", - "shell.execute_reply": "2025-09-10T15:27:08.218046Z", - "shell.execute_reply.started": "2025-09-10T15:27:08.212217Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'status': 'ok', 'restart': True}" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from IPython import get_ipython\n", - "get_ipython().kernel.do_shutdown(True)" - ] - }, - { - "cell_type": "markdown", - "id": "351d1369-51aa-47bb-800b-653b3a734a8a", - "metadata": {}, - "source": [ - "### Cell below displays the installed versions of Strands libraries\n", - "\n", - "As a result of the `pip installs` above, this cell outputs the current versions of Strands libraries" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "9c692e9f-7072-4f90-aa8e-eda90ab04b3d", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:27:13.593844Z", - "iopub.status.busy": "2025-09-10T15:27:13.593542Z", - "iopub.status.idle": "2025-09-10T15:27:14.977405Z", - "shell.execute_reply": "2025-09-10T15:27:14.976815Z", - "shell.execute_reply.started": "2025-09-10T15:27:13.593821Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Name: strands-agents\n", - "Version: 1.4.0\n", - "Summary: A model-driven approach to building AI agents in just a few lines of code\n", - "Home-page: https://github.com/strands-agents/sdk-python\n", - "Author: \n", - "Author-email: AWS \n", - "License: Apache-2.0\n", - "Location: /opt/conda/lib/python3.12/site-packages\n", - "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", - "Required-by: strands-agents-builder, strands-agents-tools\n", - "---\n", - "Name: strands-agents-tools\n", - "Version: 0.2.6\n", - "Summary: A collection of specialized tools for Strands Agents\n", - "Home-page: https://github.com/strands-agents/tools\n", - "Author: \n", - "Author-email: AWS \n", - "License: Apache-2.0\n", - "Location: /opt/conda/lib/python3.12/site-packages\n", - "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, readabilipy, requests, rich, slack-bolt, strands-agents, sympy, tenacity, watchdog\n", - "Required-by: strands-agents-builder\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], - "source": [ - "%pip show strands-agents strands-agents-tools" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c9687e1a-9b01-4a48-ba06-c370158f1caf", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.9" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb deleted file mode 100644 index afe1cbb..0000000 --- a/workshops/diy-agents-with-sagemaker-and-bedrock/0-setup/2-setup-mistral-sagemaker-endpoint.ipynb +++ /dev/null @@ -1,554 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "586f2662-a568-4c29-af10-7bcb2eadbf30", - "metadata": {}, - "source": [ - "# Deploying an LLM to Amazon SageMaker AI real-time endpoint\n", - "\n", - "## Prerequisites\n", - "\n", - "To use SageMaker AI endpoints in these examples, you will need to first deploy a managed endpoint. In this example you will deploy an endpoint through SageMaker Jumpstart, a feature that helps machine learning practitioners quickly get started with hundreds of production-ready models in SageMaker AI.\n", - "\n", - "## Dependencies\n", - "\n", - "
\n", - "⚠️ Important: Make sure you've run the 1-required-dependencies-strands.ipynb notebook in this folder before proceeding. If you haven't, close this notebook, run the previous one first, then come back to this.\n", - "
\n", - "\n", - "## Create Sagemaker Endpoint\n", - "\n", - "In this notebook, we first create an endpoint config that defines parameters for the endpoint. Then we specify an inference component that will field our requests. This component will create and kick-off the Sagemaker endpoint after some delay.\n", - "\n", - "**NOTE**: In order to deploy a Sagemaker Endpoint on a larger instance type, such as `ml.g5.48xlarge`, you may have to request a quota increase for your account. Please refer to AWS documentation on how to [increase quotas](https://docs.aws.amazon.com/general/latest/gr/sagemaker.html). \n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "0f49d687-9592-4d6d-98e6-0e3a191f9fa1", - "metadata": {}, - "source": [ - "### Run this cell to make sure the Strands Agent libraries are installed" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "b2ce612f-74cb-4c44-9483-a019bfa006d5", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:27:34.854067Z", - "iopub.status.busy": "2025-09-10T15:27:34.853759Z", - "iopub.status.idle": "2025-09-10T15:27:36.244146Z", - "shell.execute_reply": "2025-09-10T15:27:36.243506Z", - "shell.execute_reply.started": "2025-09-10T15:27:34.854045Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Name: strands-agents\n", - "Version: 1.4.0\n", - "Summary: A model-driven approach to building AI agents in just a few lines of code\n", - "Home-page: https://github.com/strands-agents/sdk-python\n", - "Author: \n", - "Author-email: AWS \n", - "License: Apache-2.0\n", - "Location: /opt/conda/lib/python3.12/site-packages\n", - "Requires: boto3, botocore, docstring-parser, mcp, opentelemetry-api, opentelemetry-instrumentation-threading, opentelemetry-sdk, pydantic, typing-extensions, watchdog\n", - "Required-by: strands-agents-builder, strands-agents-tools\n", - "---\n", - "Name: strands-agents-tools\n", - "Version: 0.2.6\n", - "Summary: A collection of specialized tools for Strands Agents\n", - "Home-page: https://github.com/strands-agents/tools\n", - "Author: \n", - "Author-email: AWS \n", - "License: Apache-2.0\n", - "Location: /opt/conda/lib/python3.12/site-packages\n", - "Requires: aiohttp, aws-requests-auth, botocore, dill, markdownify, pillow, prompt-toolkit, pyjwt, readabilipy, requests, rich, slack-bolt, strands-agents, sympy, tenacity, watchdog\n", - "Required-by: strands-agents-builder\n", - "Note: you may need to restart the kernel to use updated packages.\n" - ] - } - ], - "source": [ - "%pip show strands-agents strands-agents-tools" - ] - }, - { - "cell_type": "markdown", - "id": "b35c2bba-157b-49f5-9cf0-aaacf8f6347a", - "metadata": {}, - "source": [ - "### If Strands Agents libraries do not show above, then install them by running this cell" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "b3530b42-c71f-4d70-8856-60f8e24603e8", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:27:39.751870Z", - "iopub.status.busy": "2025-09-10T15:27:39.751511Z", - "iopub.status.idle": "2025-09-10T15:27:39.755015Z", - "shell.execute_reply": "2025-09-10T15:27:39.754435Z", - "shell.execute_reply.started": "2025-09-10T15:27:39.751844Z" - } - }, - "outputs": [], - "source": [ - "# Uncomment line below to run pip install\n", - "# %pip install 'strands-agents[sagemaker]' strands-agents-tools" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "3e8e0da6-0c35-484b-85dc-0510d0742b8d", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:27:40.658240Z", - "iopub.status.busy": "2025-09-10T15:27:40.657911Z", - "iopub.status.idle": "2025-09-10T15:27:42.625298Z", - "shell.execute_reply": "2025-09-10T15:27:42.624515Z", - "shell.execute_reply.started": "2025-09-10T15:27:40.658218Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "sagemaker.config INFO - Not applying SDK defaults from location: /etc/xdg/sagemaker/config.yaml\n", - "sagemaker.config INFO - Not applying SDK defaults from location: /home/sagemaker-user/.config/sagemaker/config.yaml\n" - ] - } - ], - "source": [ - "import boto3\n", - "import json\n", - "from sagemaker import get_execution_role\n", - "from sagemaker.jumpstart.model import JumpStartModel\n", - "\n", - "# Setup role and sagemaker session\n", - "iam_role = get_execution_role()\n", - "boto_session = boto3.Session(region_name='us-west-2')\n", - "sagemaker_client = boto_session.client('sagemaker')\n", - "sagemaker_runtime = boto3.client(\"sagemaker-runtime\") \n", - "\n", - "# Names for endpoint config and endpoint\n", - "endpointName='strands-endpoint-001'\n", - "endpointConfigName='strands-endpoint-config'\n", - "inferenceComponentName='mistral-24b-instruct-2501-ic'\n" - ] - }, - { - "cell_type": "markdown", - "id": "c2bdb040-cb4d-464c-9c58-58c938e5e283", - "metadata": {}, - "source": [ - "## Delete Resources if they already exist\n", - "\n", - "**Note**: If you re-run this notebook, or see failures to create resources, run the next 3 cells to delete previously created resources." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "47f59cb0-e525-4d3b-b2f7-faa551fa967a", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:32:35.816143Z", - "iopub.status.busy": "2025-09-10T15:32:35.815819Z", - "iopub.status.idle": "2025-09-10T15:32:35.932134Z", - "shell.execute_reply": "2025-09-10T15:32:35.931582Z", - "shell.execute_reply.started": "2025-09-10T15:32:35.816121Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'ResponseMetadata': {'RequestId': 'b8a68ac1-efe8-4b98-9f8e-ccb90d8974a2',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': 'b8a68ac1-efe8-4b98-9f8e-ccb90d8974a2',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'date': 'Wed, 10 Sep 2025 15:32:35 GMT',\n", - " 'content-length': '0'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Run this line if the endpoint already exists\n", - "sagemaker_client.delete_endpoint(EndpointName=endpointName)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "9185be4a-8252-4951-a0c0-de9de0505112", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:32:42.162578Z", - "iopub.status.busy": "2025-09-10T15:32:42.162257Z", - "iopub.status.idle": "2025-09-10T15:32:42.360272Z", - "shell.execute_reply": "2025-09-10T15:32:42.359820Z", - "shell.execute_reply.started": "2025-09-10T15:32:42.162558Z" - } - }, - "outputs": [ - { - "data": { - "text/plain": [ - "{'ResponseMetadata': {'RequestId': '776861f6-f561-45b9-a37b-2c23c9c06b19',\n", - " 'HTTPStatusCode': 200,\n", - " 'HTTPHeaders': {'x-amzn-requestid': '776861f6-f561-45b9-a37b-2c23c9c06b19',\n", - " 'content-type': 'application/x-amz-json-1.1',\n", - " 'date': 'Wed, 10 Sep 2025 15:32:42 GMT',\n", - " 'content-length': '0'},\n", - " 'RetryAttempts': 0}}" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Run this line if the endpoint config already exists\n", - "sagemaker_client.delete_endpoint_config(EndpointConfigName=endpointConfigName)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "24591a94-1ff5-4d12-a5ad-f32f75ad84df", - "metadata": {}, - "outputs": [], - "source": [ - "# Run this code to delete inference component (if exists)\n", - "sagemaker_client.delete_inference_component(InferenceComponentName=inferenceComponentName)" - ] - }, - { - "cell_type": "markdown", - "id": "f0b8cfd4-b13a-4e4b-8dc3-48150f783536", - "metadata": {}, - "source": [ - "## Create Endpoint Config, Endpoint, and Inference Component" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "6d0587aa-3647-44b0-a29b-9ce65239c05b", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:34:16.883968Z", - "iopub.status.busy": "2025-09-10T15:34:16.883648Z", - "iopub.status.idle": "2025-09-10T15:34:17.202421Z", - "shell.execute_reply": "2025-09-10T15:34:17.201912Z", - "shell.execute_reply.started": "2025-09-10T15:34:16.883948Z" - } - }, - "outputs": [], - "source": [ - "# Create endpoint config\n", - "\n", - "endpoint_config = sagemaker_client.create_endpoint_config(\n", - " EndpointConfigName=endpointConfigName,\n", - " EnableNetworkIsolation=False,\n", - " ExecutionRoleArn=iam_role,\n", - " ProductionVariants=[\n", - " {\n", - " \"VariantName\": 'AllTraffic',\n", - " \"InstanceType\": 'ml.g5.48xlarge',\n", - " \"InitialInstanceCount\": 1,\n", - " \"ModelDataDownloadTimeoutInSeconds\": 3600,\n", - " \"ContainerStartupHealthCheckTimeoutInSeconds\": 3600,\n", - " \"ManagedInstanceScaling\": {\n", - " \"Status\": \"ENABLED\",\n", - " \"MinInstanceCount\": 0,\n", - " \"MaxInstanceCount\": 2,\n", - " },\n", - " \"RoutingConfig\": {\"RoutingStrategy\": \"LEAST_OUTSTANDING_REQUESTS\"},\n", - " }\n", - " ],\n", - ")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "65f574c2-6b35-4dc1-aeab-b35cf7214794", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:34:21.458940Z", - "iopub.status.busy": "2025-09-10T15:34:21.458634Z", - "iopub.status.idle": "2025-09-10T15:34:21.914548Z", - "shell.execute_reply": "2025-09-10T15:34:21.914051Z", - "shell.execute_reply.started": "2025-09-10T15:34:21.458920Z" - } - }, - "outputs": [], - "source": [ - "# Create endpoint\n", - "endpoint = sagemaker_client.create_endpoint(\n", - " EndpointName=endpointName,\n", - " EndpointConfigName=endpointConfigName\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "0e9a7f7c-429b-47e4-9cdc-b2b57821a7c2", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:34:25.695975Z", - "iopub.status.busy": "2025-09-10T15:34:25.695657Z", - "iopub.status.idle": "2025-09-10T15:34:26.994556Z", - "shell.execute_reply": "2025-09-10T15:34:26.994046Z", - "shell.execute_reply.started": "2025-09-10T15:34:25.695956Z" - } - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Using model 'huggingface-llm-mistral-small-24B-Instruct-2501' with wildcard version identifier '*'. You can pin to version '3.0.0' for more stable results. Note that models may have different input/output signatures after a major version upgrade.\n" - ] - } - ], - "source": [ - "env = {\n", - " 'ENDPOINT_SERVER_TIMEOUT': '600',\n", - " 'SM_NUM_GPUS': json.dumps(4),\n", - " 'MESSAGES_API_ENABLED': 'true'\n", - "}\n", - "\n", - "model = JumpStartModel(\n", - " model_id=\"huggingface-llm-mistral-small-24B-Instruct-2501\",\n", - " enable_network_isolation=False,\n", - " env=env,\n", - " role=iam_role\n", - ")\n", - "\n", - "model.create()\n", - "model_name = model.name" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "f43aae8f-502f-4ab0-a4fc-fe8fbcbcdd54", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T15:34:39.669261Z", - "iopub.status.busy": "2025-09-10T15:34:39.668914Z", - "iopub.status.idle": "2025-09-10T15:34:40.315449Z", - "shell.execute_reply": "2025-09-10T15:34:40.314936Z", - "shell.execute_reply.started": "2025-09-10T15:34:39.669240Z" - } - }, - "outputs": [], - "source": [ - "# Create inference component\n", - "\n", - "mistral_7Bv03_ic = sagemaker_client.create_inference_component(\n", - " EndpointName=endpointName,\n", - " InferenceComponentName=inferenceComponentName,\n", - " RuntimeConfig={\n", - " 'CopyCount': 1\n", - " },\n", - " Specification={\n", - " 'ModelName': model_name,\n", - " 'StartupParameters': {\n", - " 'ModelDataDownloadTimeoutInSeconds': 3600,\n", - " 'ContainerStartupHealthCheckTimeoutInSeconds': 3600\n", - " },\n", - " 'ComputeResourceRequirements': {\n", - " 'MinMemoryRequiredInMb': 1024,\n", - " 'NumberOfAcceleratorDevicesRequired': 4,\n", - " }\n", - " },\n", - " Tags=[{\n", - " 'Key': 'Usage',\n", - " 'Value': 'Strands Agents'\n", - " }],\n", - " VariantName=\"AllTraffic\"\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "d7440010-016b-4d22-9532-a35426ce2c86", - "metadata": {}, - "source": [ - "
\n", - "⚠️ Note: Deployment of the Sagemaker Endpoint Inference Component will take 5~10 minutes. \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "6f1af96d-c8ff-4956-8272-c2bd9b6914cd", - "metadata": {}, - "source": [ - "## Must WAIT up to 10 minutes for Endpoint AutoScaling to complete\n", - "\n", - "**Notice**: If you get this error message below, you must WAIT for the endpoint to complete it's auto-scaling\n", - "\n", - "`ValidationError: An error occurred (ValidationError) when calling the InvokeEndpoint operation: Inference Component\n", - "has no capacity to process this request. ApplicationAutoScaling may be in-progress (if configured) or try to \n", - "increase the capacity by invoking UpdateInferenceComponentRuntimeConfig API.`\n", - "\n", - "If the cell below fails, you can simply retry after waiting." - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "fd08268e", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T16:04:59.071151Z", - "iopub.status.busy": "2025-09-10T16:04:59.070822Z", - "iopub.status.idle": "2025-09-10T16:05:01.988520Z", - "shell.execute_reply": "2025-09-10T16:05:01.988009Z", - "shell.execute_reply.started": "2025-09-10T16:04:59.071131Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'id': 'chatcmpl-19101479311344f58381c4a5a3e75e47', 'object': 'chat.completion', 'created': 1757520299, 'model': 'lmi', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'reasoning_content': None, 'content': 'The square root of 81 is 9.\\n\\nThe significance of this result is that 9 is the number that, when multiplied by itself, gives 81. In mathematical terms, if \\\\( x^2 = 81 \\\\), then \\\\( x = \\\\sqrt{81} = 9 \\\\). This is a fundamental concept in algebra and arithmetic, demonstrating the relationship between a number and its square root.', 'tool_calls': []}, 'logprobs': None, 'finish_reason': 'stop', 'stop_reason': None}], 'usage': {'prompt_tokens': 33, 'total_tokens': 120, 'completion_tokens': 87, 'prompt_tokens_details': None}, 'prompt_logprobs': None}\n" - ] - } - ], - "source": [ - "messages = [\n", - " {\"role\": \"system\", \"content\": \"You are a helpful assistant capable of performing math calculations.\"},\n", - " {\"role\": \"user\", \"content\": \"Calculate the square root of 81. Briefly explain the significance of the result.\"}\n", - "]\n", - "\n", - "payload = {\n", - " \"messages\": messages,\n", - " \"max_tokens\": 4000,\n", - " \"temperature\": 0.1,\n", - " \"top_p\": 0.9,\n", - "}\n", - "\n", - "response_model = sagemaker_runtime.invoke_endpoint(\n", - " InferenceComponentName=inferenceComponentName,\n", - " EndpointName=endpointName,\n", - " Body=json.dumps({\n", - " \"messages\": messages,\n", - " \"parameters\": {\n", - " \"do_sample\": True,\n", - " \"max_new_tokens\": 256,\n", - " }\n", - " }),\n", - " ContentType=\"application/json\"\n", - ")\n", - "\n", - "response = json.loads(response_model['Body'].read().decode('utf-8'))\n", - "print(response)" - ] - }, - { - "cell_type": "markdown", - "id": "c0a39f67-2169-4251-abca-49a9c17614fa", - "metadata": {}, - "source": [ - "### Save names of Endpoint, Endpoint Config, and Inference Component\n", - "\n", - "We save various attributes like endpoint name and inference component name using `store` magic command, as they will be needed in later notebooks." - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "18e6de49-11f7-4e36-b7bb-322282a51e53", - "metadata": { - "execution": { - "iopub.execute_input": "2025-09-10T16:05:07.423227Z", - "iopub.status.busy": "2025-09-10T16:05:07.422911Z", - "iopub.status.idle": "2025-09-10T16:05:07.428807Z", - "shell.execute_reply": "2025-09-10T16:05:07.428336Z", - "shell.execute_reply.started": "2025-09-10T16:05:07.423207Z" - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Endpoint name: strands-endpoint-001\n", - "Endpoint Config Name: strands-endpoint-config\n", - "Inference Component Name: mistral-24b-instruct-2501-ic\n", - "Stored 'MISTRAL_ENDPOINT_NAME' (str)\n", - "Stored 'MISTRAL_ENDPOINT_CONFIG_NAME' (str)\n", - "Stored 'MISTRAL_INFERENCE_COMPONENT_NAME' (str)\n" - ] - } - ], - "source": [ - "MISTRAL_ENDPOINT_NAME = endpointName\n", - "MISTRAL_ENDPOINT_CONFIG_NAME = endpointConfigName\n", - "MISTRAL_INFERENCE_COMPONENT_NAME = inferenceComponentName\n", - "\n", - "print(f\"Endpoint name: {MISTRAL_ENDPOINT_NAME}\")\n", - "print(f\"Endpoint Config Name: {MISTRAL_ENDPOINT_CONFIG_NAME}\")\n", - "print(f\"Inference Component Name: {MISTRAL_INFERENCE_COMPONENT_NAME}\")\n", - "\n", - "%store MISTRAL_ENDPOINT_NAME\n", - "%store MISTRAL_ENDPOINT_CONFIG_NAME\n", - "%store MISTRAL_INFERENCE_COMPONENT_NAME\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "81cf1157-7f7e-4926-aa35-f78f66b1f03b", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.9" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 387f1e0937b17af36e8b28121f060b8dadf0bd59 Mon Sep 17 00:00:00 2001 From: Paul Hargis Date: Mon, 27 Oct 2025 12:12:23 -0500 Subject: [PATCH 5/5] Moved Strands notebooks into folder. --- .../{ => strands-agents}/1-required-dependencies-strands.ipynb | 0 .../{ => strands-agents}/2-setup-mistral-sagemaker-endpoint.ipynb | 0 .../bootcamp/{ => strands-agents}/requirements-strands.txt | 0 .../{ => strands-agents}/strands-agents-mistral-llm.ipynb | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/{ => strands-agents}/1-required-dependencies-strands.ipynb (100%) rename workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/{ => strands-agents}/2-setup-mistral-sagemaker-endpoint.ipynb (100%) rename workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/{ => strands-agents}/requirements-strands.txt (100%) rename workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/{ => strands-agents}/strands-agents-mistral-llm.ipynb (100%) diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/1-required-dependencies-strands.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/1-required-dependencies-strands.ipynb similarity index 100% rename from workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/1-required-dependencies-strands.ipynb rename to workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/1-required-dependencies-strands.ipynb diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/2-setup-mistral-sagemaker-endpoint.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/2-setup-mistral-sagemaker-endpoint.ipynb similarity index 100% rename from workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/2-setup-mistral-sagemaker-endpoint.ipynb rename to workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/2-setup-mistral-sagemaker-endpoint.ipynb diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/requirements-strands.txt b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/requirements-strands.txt similarity index 100% rename from workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/requirements-strands.txt rename to workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/requirements-strands.txt diff --git a/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents-mistral-llm.ipynb b/workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/strands-agents-mistral-llm.ipynb similarity index 100% rename from workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents-mistral-llm.ipynb rename to workshops/diy-agents-with-sagemaker-and-bedrock/bootcamp/strands-agents/strands-agents-mistral-llm.ipynb