### Quick Start: Basic Agent Setup Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/overview.md Defines a simple agent with a basic entrypoint. Use this for initial setup and testing. ```python from bedrock_agentcore import BedrockAgentCoreApp app = BedrockAgentCoreApp() @app.entrypoint def my_agent(payload): return {"result": f"Hello {payload.get('name', 'World')}!"} if __name__ == "__main__": app.run() ``` -------------------------------- ### Initial Setup for Bedrock AgentCore CLI Starter Toolkit Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/CONTRIBUTING.md Clone the repository, create a virtual environment using `uv`, activate it, and sync dependencies. Install pre-commit hooks for automated checks. This is a one-time setup. ```bash git clone https://github.com/aws/bedrock-agentcore-starter-toolkit.git cd bedrock-agentcore-starter-toolkit uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv sync # Install pre-commit hooks (one-time) pre-commit install ``` -------------------------------- ### Install Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/policy/quickstart.md Install the necessary Python packages for the AgentCore Policy quickstart. This includes boto3 for AWS interaction, the starter toolkit, and the requests library. ```bash pip install boto3 pip install bedrock-agentcore-starter-toolkit pip install requests ``` -------------------------------- ### Install Starter Toolkit (Python) with uv Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/README.md Installs the Starter Toolkit for Python. This involves installing uv, creating a Python 3.10 virtual environment, and then installing the toolkit using uv. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```bash uv venv --python 3.10 source .venv/bin/activate ``` ```bash uv pip install bedrock-agentcore-starter-toolkit ``` -------------------------------- ### Troubleshoot Memory Configuration: Nuclear Option - Fresh Project Setup Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/agentcore-quickstart-example.md As a last resort, create a completely new project directory, set up a virtual environment, and install the necessary packages. This ensures a clean slate for the toolkit. ```bash cd .. ``` ```bash mkdir fresh-agentcore-project && cd fresh-agentcore-project ``` ```bash python3 -m venv .venv ``` ```bash source .venv/bin/activate ``` ```bash pip install --no-cache-dir "bedrock-agentcore-starter-toolkit>=0.1.21" strands-agents boto3 ``` -------------------------------- ### Basic Agent Import Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/import-agent/configuration.md A minimal example demonstrating the required parameters for importing an agent and specifying the target platform. ```bash agentcore import-agent \ --agent-id ABCD1234 \ --agent-alias-id TSTALIASID \ --target-platform strands ``` -------------------------------- ### Run the OpenAI Agents Example with Bedrock Agent Core Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/openai/openai-agent-readme.md Execute the provided Python script to run the OpenAI agents integration example. This command assumes you have completed the setup and configuration steps. ```bash python main.py --agent-id "YOUR_AGENT_ID" --agent-version "YOUR_AGENT_VERSION" --openai-api-key "YOUR_OPENAI_API_KEY" ``` -------------------------------- ### List Online Evaluation Configurations Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/evaluation/quickstart.md Lists all available online evaluation configurations. Use this to get an overview of your existing setups. ```bash agentcore eval online list ``` -------------------------------- ### Verify Toolkit Installation Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/evaluation/quickstart.md Verify the installation of the AgentCore starter toolkit by checking the help command for the evaluation CLI. This confirms the toolkit is ready for use. ```bash agentcore eval --help ``` -------------------------------- ### Install Starter Toolkit (Python) with pip Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/README.md Installs the Starter Toolkit for Python using pip. Ensure you have a Python 3.10 virtual environment activated before running this command. ```bash pip install bedrock-agentcore-starter-toolkit ``` -------------------------------- ### Start Local Development Server Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/create/quickstart.md Navigate to the src directory, set up a virtual environment, and activate it. Then, start the local development server using agentcore dev for hot-reloading. ```bash cd src python3 -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate cd .. agentcore dev ``` -------------------------------- ### AutoGen Agent Hello World Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/autogen/autogen-agent.md This Python script demonstrates a basic 'Hello World' agent using the AutoGen framework integrated with AWS Bedrock Agent Core. It requires AutoGen to be installed. ```python from autogen import UserProxyAgent, config_list_from_json, GroupChat, GroupChatManager config_list = config_list_from_json(env_or_file="OAI_CONFIG_LIST") user_proxy = UserProxyAgent( name="user_proxy", is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), human_input_mode="NEVER", code_execution_config=False, ) agent1 = UserProxyAgent( name="agent1", human_input_mode="NEVER", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config=False, ) agent2 = UserProxyAgent( name="agent2", human_input_mode="NEVER", max_consecutive_auto_reply=10, is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"), code_execution_config=False, ) groupchat = GroupChat( agents=[user_proxy, agent1, agent2], messages=[], max_round=12, ) m = GroupChatManager(groupchat, llm_config=config_list[0]) user_proxy.initiate_chat( m, message="Hello, agent1 and agent2! Please tell me a joke.", ) ``` -------------------------------- ### Verify Starter Toolkit Installation Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/quickstart.md Checks if the AgentCore starter toolkit CLI is installed and accessible. ```bash agentcore --help ``` -------------------------------- ### Async Task Management with Strands AI Framework Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/async.md This example integrates asynchronous task management with the Strands AI framework. It demonstrates starting a background task, tracking its status, and responding to the user immediately. Requires importing threading, time, Agent, tool, and BedrockAgentCoreApp. ```python import threading import time from strands import Agent, tool from bedrock_agentcore import BedrockAgentCoreApp # Initialize app with debug mode for task management app = BedrockAgentCoreApp(debug=True) @tool def start_background_task(duration: int = 5) -> str: """Start a simple background task that runs for specified duration.""" # Start tracking the async task task_id = app.add_async_task("background_processing", {"duration": duration}) # Run task in background thread def background_work(): time.sleep(duration) # Simulate work app.complete_async_task(task_id) # Mark as complete threading.Thread(target=background_work, daemon=True).start() return f"Started background task (ID: {task_id}) for {duration} seconds. Agent status is now BUSY." # Create agent with the tool agent = Agent(tools=[start_background_task]) @app.entrypoint def main(payload): """Main entrypoint - handles user messages.""" user_message = payload.get("prompt", "Try: start_background_task(3)") return {"message": agent(user_message).message} if __name__ == "__main__": print("šŸš€ Simple Async Strands Example") print("Test: curl -X POST http://localhost:8080/invocations -H 'Content-Type: application/json' -d '{\"prompt\": \"start a 3 second task\"}'") app.run() ``` -------------------------------- ### Terraform Example Variables Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/infrastructure-as-code/terraform/mcp-server-agentcore-runtime/mcp-server-terraform-deploy-sample.md An example file showing how to set values for the Terraform variables. ```hcl vpc_id = "vpc-xxxxxxxxxxxxxxxxx" subnet_ids = ["subnet-xxxxxxxxxxxxxxxxx", "subnet-yyyyyyyyyyyyyyyyy"] ``` -------------------------------- ### Configure Agent with Memory Enabled (Interactive) Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/api-reference/cli.md Configure an agent and interactively set up memory. Prompts will guide you through selecting existing memory, creating new memory (STM only or STM+LTM), or skipping memory setup. ```bash # Interactive mode - prompts for memory setup agentcore configure --entrypoint agent.py ``` -------------------------------- ### Install AgentCore Starter Toolkit Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/agentcore-quickstart-example.md Installs the necessary Python packages for the AgentCore starter toolkit. Ensure you are using Python 3.10 or newer and have created a virtual environment. ```bash # Create virtual environment python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate # Install required packages (version 0.1.21 or later) pip install "bedrock-agentcore-starter-toolkit>=0.1.21" strands-agents strands-agents-tools boto3 ``` -------------------------------- ### Install MkDocs with uv Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/README.md Installs MkDocs using the uv package manager. Ensure Python 3.10+ is installed. ```bash uv pip install mkdocs ``` -------------------------------- ### Install AgentCore CLI Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/mcp/agentcore_runtime_deployment.md Install the AgentCore starter toolkit CLI using pip. This command is required for configuring and deploying your agent. ```bash pip install bedrock-agentcore-starter-toolkit ``` -------------------------------- ### Set up Project Environment and Install Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/builtin-tools/quickstart-code-interpreter.md These bash commands set up a new project directory, create a virtual environment, activate it, and install the required Python packages for AgentCore tools and the Strands agent framework. ```bash mkdir agentcore-tools-quickstart cd agentcore-tools-quickstart python3 -m venv .venv source .venv/bin/activate ``` ```bash pip install bedrock-agentcore strands-agents strands-agents-tools ``` -------------------------------- ### Install SDK and Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/identity/quickstart.md Installs the AgentCore SDK, boto3, and other necessary Python packages using pip. Also creates a requirements.txt file for deployment. ```bash mkdir agentcore-identity-quickstart cd agentcore-identity-quickstart python3 -m venv .venv source .venv/bin/activate pip install bedrock-agentcore boto3 strands-agents bedrock-agentcore-starter-toolkit pyjwt ``` ```text bedrock-agentcore boto3 pyjwt strands-agents bedrock-agentcore-starter-toolkit ``` -------------------------------- ### Create Virtual Environment and Install Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/builtin-tools/quickstart-browser.md Set up a Python virtual environment and install necessary packages for AgentCore Browser, Nova Act, Rich, and Boto3. This ensures all required libraries are available for your project. ```bash mkdir agentcore-browser-quickstart cd agentcore-browser-quickstart python3 -m venv .venv source .venv/bin/activate ``` ```bash pip install bedrock-agentcore nova-act rich boto3 ``` -------------------------------- ### Install AgentCore CLI Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/README.md Install the recommended AgentCore CLI globally using npm. This is the preferred tool for new projects. ```bash npm install -g @aws/agentcore ``` -------------------------------- ### Save Configuration and Print Summary Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/policy/quickstart.md Saves the agent setup configuration to a JSON file and prints a summary of the setup details, including gateway URL, policy engine ID, and refund limit. It also suggests the next step to test the policy. ```python print("āœ“ Policy Engine attached to Gateway\n") # Step 8: Save configuration config = { "gateway_url": gateway["gatewayUrl"], "gateway_id": gateway["gatewayId"], "gateway_arn": gateway["gatewayArn"], "policy_engine_id": engine["policyEngineId"], "policy_engine_arn": engine["policyEngineArn"], "policy_id": policy["policyId"], "region": region, "client_info": cognito_response["client_info"], "refund_limit": refund_limit } with open("config.json", "w") as f: json.dump(config, f, indent=2) print("=" * 60) print("āœ… Setup complete!") print(f"Gateway URL: {gateway['gatewayUrl']}") print(f"Policy Engine ID: {engine['policyEngineId']}") print(f"Refund limit: ${refund_limit}") print("\nConfiguration saved to: config.json") print("\nNext step: Run 'python test_policy.py' to test your Policy") print("=" * 60) return config if __name__ == "__main__": setup_policy() ``` -------------------------------- ### Install Claude Agent SDK Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/claude-sdk/claude-agent-readme.md Install the necessary SDK for interacting with Claude agents. Ensure you have Python and pip installed. ```bash pip install "claude-agent>=0.1.0" ``` -------------------------------- ### Initialize Gateway Setup Function Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/gateway/quickstart.md Defines the main setup function and initializes the AWS region. It also sets up the GatewayClient and configures its logging level. ```python def setup_gateway(): # Configuration region = "us-east-1" # Change to your preferred region print("šŸš€ Setting up AgentCore Gateway...") print(f"Region: {region}\n") # Initialize client client = GatewayClient(region_name=region) client.logger.setLevel(logging.INFO) ``` -------------------------------- ### Install AgentCore CLI Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/overrides/main.html Command to install the AgentCore CLI globally. ```bash npm install -g @aws/agentcore ``` -------------------------------- ### Install Dependencies for Code Interpreter Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/builtin-tools/quickstart-code-interpreter.md Set up a Python virtual environment and install the necessary packages for using Bedrock AgentCore and boto3. ```bash mkdir agentcore-tools-quickstart cd agentcore-tools-quickstart python3 -m venv .venv source .venv/bin/activate ``` ```bash pip install bedrock-agentcore boto3 ``` -------------------------------- ### Install LlamaIndex and Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/llamaindex/llama-agent-readme.md Install the LlamaIndex library and any necessary dependencies for agent integration. Ensure you have Python 3.8+. ```bash pip install llama-index "llama-index-llms-bedrock>=0.1.10" "llama-index-embeddings-bedrock>=0.1.7" ``` -------------------------------- ### Example Terraform Variables Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/infrastructure-as-code/terraform/end-to-end-weather-agent/weather-agent-terraform-deploy-sample.md Provides example values for Terraform variables, demonstrating how to configure the deployment for a specific environment. ```hcl # Example terraform.tfvars file # aws_region = "us-west-2" # bedrock_agent_name = "my-custom-agent" # bedrock_agent_id = "my-custom-agent-id" # bedrock_kb_name = "my-custom-kb" # bedrock_kb_id = "my-custom-kb-id" # bedrock_agent_lambda_function_name = "my-custom-lambda" # bedrock_agent_foundation_model = "anthropic.claude-3-opus-20240229-v1:0" ``` -------------------------------- ### Complete Example: Weather Agent Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/gateway-integration.md This snippet shows the imports for a complete weather agent example using Bedrock Agent Core and GatewayClient. It sets up necessary libraries for integration. ```python from bedrock_agentcore.gateway import GatewayClient import json import asyncio import httpx ``` -------------------------------- ### Execute Setup Script Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/policy/quickstart.md Command to run the Python setup script for AWS Bedrock Agent Core. The script takes approximately 2-3 minutes to complete. ```bash python setup_policy.py ``` -------------------------------- ### Example Update Gateway Request Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/gateway/quickstart.md A simplified example of an update request for a Bedrock Gateway, demonstrating required fields and placeholders for dynamic values. ```python # an example of an update request example_update_gw_request = { "gatewayIdentifier": "", "name": "TestGateway", "roleArn": "", "protocolType": "MCP", "authorizerType": "CUSTOM_JWT", "authorizerConfiguration": { "customJWTAuthorizer": { "discoveryUrl": "", "allowedScopes": [""], "customClaims": ["{}"], "allowedClients": [""] } } } ``` -------------------------------- ### Python Script to Setup Gateway with Policy Engine Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/policy/quickstart.md This script automates the setup of an AWS Bedrock Agent Core Gateway integrated with a Policy Engine. It requires the `bedrock_agentcore_starter_toolkit` and `boto3` libraries. Run this script first to establish the necessary infrastructure. ```python """ Setup script to create Gateway with Policy Engine Run this first: python setup_policy.py """ from bedrock_agentcore_starter_toolkit.operations.gateway.client import GatewayClient from bedrock_agentcore_starter_toolkit.operations.policy.client import PolicyClient from bedrock_agentcore_starter_toolkit.utils.lambda_utils import create_lambda_function import boto3 import json import logging import time def setup_policy(): # Configuration region = "us-west-2" refund_limit = 1000 print("šŸš€ Setting up AgentCore Gateway with Policy Engine...") print(f"Region: {region}\n") # Initialize clients gateway_client = GatewayClient(region_name=region) gateway_client.logger.setLevel(logging.INFO) policy_client = PolicyClient(region_name=region) policy_client.logger.setLevel(logging.INFO) # Step 1: Create OAuth authorizer print("Step 1: Creating OAuth authorization server...") cognito_response = gateway_client.create_oauth_authorizer_with_cognito("PolicyGateway") print("āœ“ Authorization server created\n") # Step 2: Create Gateway print("Step 2: Creating Gateway...") gateway = gateway_client.create_mcp_gateway( name=None, role_arn=None, authorizer_config=cognito_response["authorizer_config"], enable_semantic_search=False, ) print(f"āœ“ Gateway created: {gateway['gatewayUrl']}\n") # Fix IAM permissions gateway_client.fix_iam_permissions(gateway) print("ā³ Waiting 30s for IAM propagation...") time.sleep(30) print("āœ“ IAM permissions configured\n") # Step 3: Create Lambda function with refund tool print("Step 3: Creating Lambda function with refund tool...") refund_lambda_code = """ def lambda_handler(event, context): amount = event.get('amount', 0) return { "status": "success", "message": f"Refund of ${amount} processed successfully", "amount": amount } """ session = boto3.Session(region_name=region) lambda_arn = create_lambda_function( session=session, logger=gateway_client.logger, function_name=f"RefundTool-{int(time.time())}", lambda_code=refund_lambda_code, runtime="python3.13", handler="lambda_function.lambda_handler", gateway_role_arn=gateway["roleArn"], description="Refund tool for policy demo", ) print("āœ“ Lambda function created\n") # Step 4: Add Lambda target with refund tool schema print("Step 4: Adding Lambda target with refund tool schema...") lambda_target = gateway_client.create_mcp_gateway_target( gateway=gateway, name="RefundTarget", target_type="lambda", target_payload={ "lambdaArn": lambda_arn, "toolSchema": { "inlinePayload": [ { "name": "process_refund", "description": "Process a customer refund", "inputSchema": { "type": "object", "properties": { "amount": { "type": "integer", "description": "Refund amount in dollars" } }, "required": ["amount"], }, } ] }, }, credentials=None, ) print("āœ“ Lambda target added\n") # Step 5: Create Policy Engine print("Step 5: Creating Policy Engine...") engine = policy_client.create_or_get_policy_engine( name="RefundPolicyEngine", description="Policy engine to regulate refund operations" ) print(f"āœ“ Policy Engine: {engine['policyEngineId']}\n") # Step 6: Create Cedar policy print(f"Step 6: Creating Cedar policy (refund limit: ${refund_limit})...") cedar_statement = ( f"permit(principal, " f'action == AgentCore::Action::"RefundTarget___process_refund", ' f'resource == AgentCore::Gateway::"{gateway["gatewayArn"]}") ' "when { context.input.amount < " + str(refund_limit) + " };" ) policy = policy_client.create_or_get_policy( policy_engine_id=engine["policyEngineId"], name="refund_limit_policy", description=f"Allow refunds under ${refund_limit}", definition={"cedar": {"statement": cedar_statement}}, ) print(f"āœ“ Policy: {policy['policyId']}\n") # Step 7: Attach Policy Engine to Gateway print("Step 7: Attaching Policy Engine to Gateway (ENFORCE mode)...") gateway_client.update_gateway_policy_engine( gateway_identifier=gateway["gatewayId"], policy_engine_arn=engine["policyEngineArn"], mode="ENFORCE" ) ``` -------------------------------- ### Example Gateway Create Request Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/gateway/quickstart.md A simplified example of a request payload for creating a Bedrock Agentcore Gateway. Ensure placeholder values like ARN and URL are replaced. ```python # an example of a create request example_create_gw_request = { "name": "TestGateway", "roleArn": "", "protocolType": "MCP", "authorizerType": "CUSTOM_JWT", "authorizerConfiguration": { "customJWTAuthorizer": { "discoveryUrl": "", "allowedScopes": [""], "customClaims": ["{}"], "allowedClients": [""] } } } ``` -------------------------------- ### Install ADK Python Package Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/adk/adk-agent-readme.md Install the Amazon Bedrock Agent Development Kit (ADK) Python package to get started with agentic framework integrations. ```bash pip install amazon-bedrock-agent-developer-kit ``` -------------------------------- ### OpenAI Agents Handoff Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/openai/openai-agent-handoff-example.md Demonstrates how to implement a handoff mechanism between an OpenAI Agent and an AWS Bedrock Agent. This example requires the OpenAI Python client library. ```python from openai import OpenAI from typing import Dict, Any from langchain_core.runnables import Runnable def get_openai_agent_client() -> OpenAI: return OpenAI() def get_openai_agent_response(client: OpenAI, prompt: str) -> Dict[str, Any]: completion = client.chat.completions.create( model="gpt-4", messages=[ {"role": "system", "content": "You are a helpful assistant that translates user requests into API calls."}, {"role": "user", "content": prompt}, ], ) return completion.model_dump() def openai_agent_handoff_example() -> None: client = get_openai_agent_client() prompt = "What is the weather in San Francisco?" response = get_openai_agent_response(client, prompt) print(f"OpenAI Agent Response: {response['choices'][0]['message']['content']}") if __name__ == "__main__": openai_agent_handoff_example() ``` -------------------------------- ### Configure Deployment Options Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/import-agent/quickstart.md These examples show the interactive prompts for configuring deployment options, including deploying to AgentCore Runtime and how the agent should run. ```bash ? Deploy to AgentCore Runtime? [y/N]: Y ? How would you like to run the agent? > Run on AgentCore Runtime Install dependencies and run locally Don't run now ``` -------------------------------- ### Serve MkDocs Locally Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/README.md Starts a local development server for previewing the documentation. The server will be accessible at http://127.0.0.1:8000/. ```bash mkdocs serve ``` -------------------------------- ### LlamaIndex Llama Agent Hello World Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/llamaindex/llama-agent.md A basic example demonstrating how to set up a LlamaIndex agent with Amazon Bedrock. Ensure you have the necessary LlamaIndex and Bedrock libraries installed. ```python from llama_index.llms.bedrock import Bedrock from llama_index.agent import ReActAgent from llama_index.tools import FunctionTool import boto3 # Initialize Bedrock client bedrock_runtime = boto3.client( service_name="bedrock-runtime", region_name="us-east-1", # Replace with your desired region ) # Initialize Bedrock LLM llm = Bedrock(client=bedrock_runtime, model="anthropic.claude-v1") # Replace with your desired model # Define a simple tool def multiply(a: int, b: int) -> int: """Multiplies two integers.""" return a * b # Create a FunctionTool from the function multiply_tool = FunctionTool.from_defaults( fn=multiply, name="multiply_two_numbers", description="Multiplies two integers.", ) # Initialize the ReAct Agent agent = ReActAgent.from_tools(tools=[multiply_tool], llm=llm, verbose=True) # Query the agent response = agent.query("What is 2 * 3?") print(f"Agent response: {response}") ``` -------------------------------- ### Get Online Evaluation Configuration Details Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/evaluation/quickstart.md Retrieves detailed information about a specific online evaluation configuration using its ID. Replace the example ID with your actual configuration ID. ```bash agentcore eval online get --config-id production_eval_config-2HeyEjChSQ ``` -------------------------------- ### Troubleshoot Memory Configuration: Reinstall Starter Toolkit Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/agentcore-quickstart-example.md Force a reinstallation of the starter toolkit within the local virtual environment with precedence. This ensures the latest compatible version is used. ```bash pip install --force-reinstall --no-cache-dir "bedrock-agentcore-starter-toolkit>=0.1.21" ``` -------------------------------- ### Install A2A Packages Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/a2a.md Installs the necessary Python packages for A2A development with AgentCore. ```bash pip install strands-agents[a2a] pip install bedrock-agentcore pip install strands-agents-tools ``` -------------------------------- ### Set up Python Virtual Environment Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/builtin-tools/quickstart-browser.md Create a project folder, set up a Python virtual environment, and activate it. This ensures project dependencies are isolated. ```bash mkdir agentcore-browser-quickstart cd agentcore-browser-quickstart python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Install CrewAI and CrewAI-Tools Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/runtime-framework-agents.md Install the necessary libraries for building CrewAI agents with Bedrock. ```bash pip install crewai crewai-tools ``` -------------------------------- ### Setup and Verify Package Import Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/tests_integ/notebook/evaluation_inegration_test_.ipynb This snippet demonstrates how to set up the Python path to import the local package and verifies that the correct package and its methods are accessible. ```python import sys from pathlib import Path import bedrock_agentcore_starter_toolkit from bedrock_agentcore_starter_toolkit import Evaluation # Setup: Add local package to path # Get repository root (goes up from notebook -> tests_integ -> repo root) repo_root = Path.cwd().parent.parent sys.path.insert(0, str(repo_root / "src")) print(f"Added to path: {repo_root / 'src'}") # Now import from local package # Verify correct package print(f"\nāœ… Using package from: {bedrock_agentcore_starter_toolkit.__file__}") # Verify get_latest_session exists eval_test = Evaluation(region="us-east-1") has_method = hasattr(eval_test, "get_latest_session") print(f"āœ… Has get_latest_session method: {has_method}") if not has_method: print("\nāŒ ERROR: Wrong package! Not using bedrock-agentcore-starter-toolkit-evaluation") ``` -------------------------------- ### AgentCore Deployment Output Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/agentcore-quickstart-example.md Observe the expected output during deployment, which includes memory creation progress and confirmation of deployment to the AgentCore runtime. ```text Creating memory resource for agent: agentcore_starter_strands ā³ Creating memory resource (this may take 30-180 seconds)... Created memory: agentcore_starter_strands_mem-abc123 Waiting for memory agentcore_starter_strands_mem-abc123 to return to ACTIVE state... ā³ Memory: CREATING (61s elapsed) ā³ Memory: CREATING (92s elapsed) ā³ Memory: CREATING (123s elapsed) āœ… Memory is ACTIVE (took 159s) āœ… Memory created and active: agentcore_starter_strands_mem-abc123 Observability is enabled, configuring Transaction Search... āœ… Transaction Search configured: resource_policy, trace_destination, indexing_rule šŸ” GenAI Observability Dashboard: https://console.aws.amazon.com/cloudwatch/home?region=us-west-2#gen-ai-observability/agent-core āœ… Container deployed to Bedrock AgentCore Agent ARN: arn:aws:bedrock-agentcore:us-west-2:123456789:runtime/agentcore_starter_strands-xyz ``` -------------------------------- ### Install LangGraph and Langchain-AWS Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/runtime-framework-agents.md Install the necessary libraries for building LangGraph agents with Bedrock. ```bash pip install langchain-aws langgraph ``` -------------------------------- ### Run Gateway Setup Script Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/memory_gateway_agent.md Executes the Python script 'setup_gateway.py' to set up the gateway with a calculator tool and save the configuration to 'gateway_config.json'. This is a command-line instruction. ```bash python setup_gateway.py ``` -------------------------------- ### Configure, Launch, and Invoke Agent from Notebook Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/notebook.md Use the Runtime class to configure an agent by specifying the entrypoint and execution role, launch it locally for testing, and then invoke it with a specific prompt to see the response. ```python from bedrock_agentcore_starter_toolkit.notebook import Runtime runtime = Runtime() # Configure runtime.configure( entrypoint="my_agent.py", execution_role="arn:aws:iam::123456789012:role/MyRole" ) # Launch locally for testing runtime.launch(local=True) # Test the agent response = runtime.invoke({"prompt": "Test from notebook"}) print(response) # {"result": "You said: Test from notebook"} ``` -------------------------------- ### Install Required Python Packages Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/quickstart.md Installs the necessary libraries for Bedrock AgentCore and Strands Agents. ```bash pip install bedrock-agentcore strands-agents bedrock-agentcore-starter-toolkit ``` -------------------------------- ### Install Playwright Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/builtin-tools/quickstart-browser.md Install the Playwright library using pip. This is necessary for connecting to the browser session. ```bash pip install playwright ``` -------------------------------- ### Create Project Directory and Virtual Environment Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/quickstart.md Sets up a new project folder and activates a Python virtual environment. Ensure you are in the correct directory before running. ```bash mkdir agentcore-runtime-quickstart cd agentcore-runtime-quickstart python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Terraform Variables Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/infrastructure-as-code/terraform/basic-runtime/basic-terraform-deploy-sample.md An example tfvars file showing how to set values for the Terraform variables. ```hcl aws_region = "us-east-1" agent_name = "my-custom-agent" agent_description = "My custom agent for specific tasks." enable_data_access = true s3_bucket_name = "my-unique-data-bucket-12345" ecr_repository_name = "my-agent-repo" codebuild_project_name = "my-agent-build-project" ``` -------------------------------- ### Terraform Variables Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/infrastructure-as-code/terraform/multi-agent-runtime/multi-agent-terraform-deploy-sample.md Example values for Terraform variables, including AWS region and model ARN. ```hcl region = "us-east-1" account_id = "123456789012" model_arn = "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-v1" ``` -------------------------------- ### Select Target Platform Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/import-agent/quickstart.md This example shows the interactive prompt for selecting the target platform for the imported agent, such as Strands or LangChain/LangGraph. ```bash ? Choose target platform: > strands (1.0.x) langchain (0.3.x) + langgraph (0.5.x) ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/observability/quickstart.md Sets up a new directory and initializes a Python virtual environment for the project. Activate the environment before proceeding with installations. ```bash mkdir agentcore-observability-quickstart cd agentcore-observability-quickstart python3 -m venv .venv source .venv/bin/activate ``` -------------------------------- ### Install AgentCore Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/identity/quickstart-with-cli.md Install the necessary libraries for AgentCore Identity, including bedrock-agentcore, bedrock-agentcore-starter-toolkit, strands-agents, and boto3. ```bash mkdir agentcore-identity-demo cd agentcore-identity-demo python3 -m venv .venv source .venv/bin/activate pip install bedrock-agentcore bedrock-agentcore-starter-toolkit strands-agents boto3 ``` -------------------------------- ### Use Descriptive Names and Namespaces Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/src/bedrock_agentcore_starter_toolkit/operations/memory/README.md Illustrates the best practice of using clear, descriptive names and namespaces for strategies to improve organization and clarity, showing an example with namespaces. ```python # āœ… Recommended: Clear, descriptive names semantic = SemanticStrategy( name="CustomerSupportSemantics", description="Extract semantic information from customer support conversations", namespaces=["support/semantics/{actorId}/{sessionId}/"] ) # āŒ Avoid: Generic names semantic = SemanticStrategy(name="Strategy1") ``` -------------------------------- ### Configure Agent with Basic Options Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/api-reference/cli.md Use this command to configure agents and runtime environments. Specify the Python entrypoint file for your agent. ```bash agentcore configure [OPTIONS] ``` -------------------------------- ### AgentCore Starter Requirements File Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/agentcore-quickstart-example.md Lists the Python packages required for the AgentCore starter toolkit project. Ensure these are installed in your virtual environment. ```text strands-agents bedrock-agentcore strands-agents-tools ``` -------------------------------- ### Install Strands Agents with OTEL Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/observability/quickstart.md Installs the Strands Agents library with OpenTelemetry (OTEL) extra dependencies required for observability. ```bash pip install 'strands-agents[otel]' ``` -------------------------------- ### Install AgentCore Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/memory/quickstart.md Installs the necessary libraries for AgentCore memory functionality. Ensure you have Python 3.10+ and AWS credentials configured. ```bash mkdir agentcore-memory-quickstart cd agentcore-memory-quickstart python -m venv .venv source .venv/bin/activate pip install bedrock-agentcore pip install bedrock-agentcore-starter-toolkit ``` -------------------------------- ### Setup Virtual Environment Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/policy/quickstart.md Run these commands in your terminal to create and activate a Python virtual environment for the project. Adjust the activation command for Windows if necessary. ```bash mkdir agentcore-policy-quickstart cd agentcore-policy-quickstart python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate ``` -------------------------------- ### Initialize and Test AgentCore Runtime in Notebook Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/runtime/notebook.md Import the Runtime class, initialize it, configure your agent with an entrypoint and execution role, and then test it locally by launching a container and invoking it with a prompt. ```python # Import the notebook Runtime class from bedrock_agentcore_starter_toolkit.notebook import Runtime # Initialize runtime = Runtime() # Configure your agent config = runtime.configure( entrypoint="my_agent.py", execution_role="arn:aws:iam::123456789012:role/MyExecutionRole" ) # Test locally local_result = runtime.launch(local=True) print(f"Local container: {local_result.tag}") # Test your agent response = runtime.invoke({"prompt": "Hello from notebook!"}) print(response) ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/gateway/quickstart.md Sets up a new project directory and creates a Python virtual environment for managing dependencies. Activate the environment before installing packages. ```bash mkdir agentcore-gateway-quickstart cd agentcore-gateway-quickstart python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate ``` -------------------------------- ### Install AutoGen and Dependencies Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/examples/integrations/agentic-frameworks/autogen/autogen-agent-readme.md Install the AutoGen library and any other necessary Python packages for agent development. Ensure you have a compatible Python version. ```bash pip install pyautogen ``` -------------------------------- ### JWT Token Example Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/policy/overview.md An example JWT token containing OAuth claims about the user, including subject, username, scopes, and role. ```json { "sub": "user-123", "username": "refund-agent", "scope": "refund:write admin:read", "role": "admin" } ``` -------------------------------- ### CDK Deployment Commands Source: https://github.com/aws/bedrock-agentcore-starter-toolkit/blob/main/documentation/docs/user-guide/create/quickstart.md Commands to install dependencies, synthesize, and deploy the project using AWS CDK. Ensure Node.js 18+ is installed. ```bash cd cdk npm install npm run cdk synth npm run cdk:deploy ```