### Environment Variable Management Examples Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Provides examples for listing AWS-related variables, getting the current working directory, and setting an API key. ```python # List all AWS-related variables environment(action="list", prefix="AWS_") # Get current working directory environment(action="get", name="PWD") # Set API key for current session environment(action="set", name="API_KEY", value="sk-...") ``` -------------------------------- ### Development Install Strands Agents Tools Source: https://github.com/strands-agents/tools/blob/main/README.md Set up the development environment by cloning the repository, creating a virtual environment, and installing in development mode. ```bash # Clone the repository git clone https://github.com/strands-agents/tools.git cd tools # Create and activate virtual environment python3 -m venv .venv source .venv/bin/activate # On Windows: venv\Scripts\activate # Install in development mode pip install -e ".[dev]" # Install pre-commit hooks pre-commit install ``` -------------------------------- ### Install Optional Tool Dependencies Source: https://github.com/strands-agents/tools/blob/main/README.md Install additional dependencies for specific optional tools. ```bash pip install strands-agents-tools[mem0_memory, use_browser, rss, use_computer] ``` -------------------------------- ### Custom Tool Format Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md This is an example of how to format a custom tool file. It includes the necessary import and decorator for a tool function. ```python # sentiment_analyzer.py from strands import tool @tool def analyze_sentiment(text: str) -> dict: """Analyze sentiment of text.""" # Implementation return { "status": "success", "content": [{"text": f"Sentiment: positive"}] } ``` -------------------------------- ### Install Diagram Tool Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs the diagram generation tool. Use this to create diagrams for AWS, network, UML, and more. ```bash pip install strands-agents-tools[diagram] ``` -------------------------------- ### Install Desktop Automation Tool Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs the 'use_computer' tool for desktop automation. This allows agents to interact with the user's desktop environment. ```bash pip install strands-agents-tools[use_computer] ``` -------------------------------- ### Install All Optional Features Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs all available optional features for Strands Agents Tools. This is a comprehensive installation for full functionality. ```bash pip install strands-agents-tools[all] ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/strands-agents/tools/blob/main/CONTRIBUTING.md Installs the project's development dependencies using pip. This is a prerequisite for setting up the local development environment. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Install TwelveLabs Video Tools Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs the TwelveLabs tools for video analysis and search. Use this for semantic search and chat functionalities on video content. ```bash pip install strands-agents-tools[twelvelabs] ``` -------------------------------- ### Install All Memory Backends Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs all available memory backends for Strands Agents Tools. This is useful for projects requiring diverse memory solutions. ```bash pip install strands-agents-tools[mem0_memory,mongodb_memory,elasticsearch_memory] ``` -------------------------------- ### Install strands-agents-tools Source: https://github.com/strands-agents/tools/blob/main/docs/stability_ai_tool.md Install the necessary package to add Stability AI as a tool to Strands Agents. ```bash pip install strands-agents-tools ``` -------------------------------- ### Install Pre-commit Hooks (Simplified) Source: https://github.com/strands-agents/tools/blob/main/CONTRIBUTING.md Installs the pre-commit hook for the project. This is a simpler command that achieves the same goal as the more verbose version, ensuring hooks are active. ```bash pre-commit install ``` -------------------------------- ### Install RSS Feed Tool Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs the tool for handling RSS feeds. This is useful for integrating news or content updates into agents. ```bash pip install strands-agents-tools[rss] ``` -------------------------------- ### Install A2A Client Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs the A2A client for agent-to-agent communication. This is essential for distributed agent systems. ```bash pip install strands-agents-tools[a2a_client] ``` -------------------------------- ### InitSessionAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Creates a new browser session. Requires a unique session_name and a description for the session's purpose. ```json { "action": { "type": "init_session", "session_name": "web-scraping-task", # Pattern: ^[a-z0-9-]+$, 10-36 chars "description": "Scrape product data from website" } } ``` -------------------------------- ### Install Browser Automation Tools Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs tools for browser automation, including local Chromium support. Use this for web scraping or automated browser interactions. ```bash pip install strands-agents-tools[local_chromium_browser,agent_core_browser] ``` -------------------------------- ### Basic Agent Setup with Elasticsearch Memory Tool Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Demonstrates how to create an agent and use the Elasticsearch Memory Tool directly. Configuration parameters like cloud ID and API key are passed as arguments. ```python from strands import Agent from strands_tools.elasticsearch_memory import elasticsearch_memory # Create an agent with the direct tool agent = Agent(tools=[elasticsearch_memory]) # Use the tool with configuration parameters result = agent.tool.elasticsearch_memory( action="record", content="User prefers vegetarian pizza with extra cheese", cloud_id="your-elasticsearch-cloud-id", api_key="your-elasticsearch-api-key", index_name="my_memories", namespace="user_123" ) ``` -------------------------------- ### Install Code Interpreter Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs the code interpreter tool, enabling complex data operations within agents. This is recommended for data analysis tasks. ```bash pip install strands-agents-tools[agent_core_code_interpreter] ``` -------------------------------- ### NavigateAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Navigates the browser to a specified URL within a given session. ```json { "action": { "type": "navigate", "session_name": "web-scraping-task", "url": "https://example.com/products" } } ``` -------------------------------- ### AgentCore Memory Tool Setup Source: https://github.com/strands-agents/tools/blob/main/README.md Initializes the AgentCoreMemoryToolProvider with required memory, actor, and session IDs. Region is optional. ```python from strands import Agent from strands_tools.agent_core_memory import AgentCoreMemoryToolProvider provider = AgentCoreMemoryToolProvider( memory_id="memory-123abc", # Required actor_id="user-456", # Required session_id="session-789", # Required namespace="default", # Required region="us-west-2" # Optional, defaults to us-west-2 ) agent = Agent(tools=provider.tools) ``` -------------------------------- ### Create a Web Scraping Workflow Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Build a workflow for web scraping using browser tools. This example initializes a session, navigates to a URL, and retrieves HTML content. ```python workflow( action="create", name="scrape_products", steps=[ { "tool": "browser", "parameters": { "action": { "type": "init_session", "session_name": "scraper", "description": "Product scraping" } } }, { "tool": "browser", "parameters": { "action": { "type": "navigate", "session_name": "scraper", "url": "https://example.com/products" } } }, { "tool": "browser", "parameters": { "action": { "type": "get_html", "session_name": "scraper" } } } ] ) ``` -------------------------------- ### Successful Record Response Example Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md An example of a successful response after storing a memory. It includes the status, content, and details of the stored memory. ```json { "status": "success", "content": [ { "text": "Memory stored successfully: {\"memory_id\": \"mem_1704567890123_abc12345\", \"content\": \"User prefers vegetarian pizza\", \"namespace\": \"user_123\", \"timestamp\": \"2024-01-06T20:31:30.123456Z\", \"result\": \"created\"}" } ] } ``` -------------------------------- ### Connection Error Handling Example Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Demonstrates handling connection errors by providing invalid credentials. The tool returns an error status with a message indicating connection failure. ```python # Invalid credentials result = agent.tool.elasticsearch_memory( action="record", content="test", cloud_id="invalid-cloud-id", api_key="invalid-api-key" ) # Returns: {"status": "error", "content": [{"text": "Unable to connect to Elasticsearch cluster"}]} ``` -------------------------------- ### Install Missing Optional Dependency Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Installs a specific missing optional dependency, such as 'mem0_memory', to resolve ImportError. Use this to fix module not found errors. ```bash pip install strands-agents-tools[mem0_memory] ``` -------------------------------- ### Set Up Pre-commit Hooks Source: https://github.com/strands-agents/tools/blob/main/CONTRIBUTING.md Installs pre-commit hooks to automatically run formatters and conventional commit checks before each commit. This ensures code consistency and adherence to project standards. ```bash pre-commit install -t pre-commit -t commit-msg ``` -------------------------------- ### Configure AgentCoreBrowser Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Instantiate AgentCoreBrowser specifying the AWS region. Ensure the 'agent_core_browser' extra is installed. ```python from strands_tools.browser import AgentCoreBrowser browser = AgentCoreBrowser(region="us-west-2") ``` -------------------------------- ### Configure User-Specific Memory Settings Source: https://github.com/strands-agents/tools/blob/main/docs/mongodb_memory_tool.md Provides an example of creating reusable configuration objects for user-specific memory operations. This includes defining base connection details and generating user-specific collection and namespace settings. ```python # Create a base configuration base_config = { "cluster_uri": "mongodb+srv://user:password@cluster.mongodb.net/", "database_name": "memory_db", "region": "us-east-1" } # User-specific configuration def get_user_config(user_id): return { **base_config, "collection_name": "user_memories", "namespace": f"user_{user_id}" } # Usage user_config = get_user_config("alice") result = agent.tool.mongodb_memory( action="record", content="Alice likes Italian food", **user_config ) ``` -------------------------------- ### Successful Retrieve Response Example Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md An example of a successful response after retrieving memories. It shows the status, content, and details of the retrieved memories, including scores and total count. ```json { "status": "success", "content": [ { "text": "Memories retrieved successfully: {\"memories\": [{\"memory_id\": \"mem_123\", \"content\": \"User prefers vegetarian pizza\", \"timestamp\": \"2024-01-06T20:31:30Z\", \"metadata\": {\"category\": \"food\"}, \"score\": 0.95}], \"total\": 1, \"max_score\": 0.95}" } ] } ``` -------------------------------- ### Configure MongoDB Memory via Constructor Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Instantiate MongoDBMemory with connection details. Ensure the 'mongodb_memory' extra is installed. ```python from strands_tools import mongodb_memory memory_tool = MongoDBMemory( connection_string="mongodb+srv://user:pass@cluster.mongodb.net/", database_name="memories", collection_name="agent_memories" ) ``` -------------------------------- ### PressKeyAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Simulates pressing a keyboard key within a browser session. Supports various key names like 'Enter', 'Tab', etc. ```json { "action": { "type": "press_key", "session_name": "web-scraping-task", "key": "Enter" } } ``` -------------------------------- ### Initialize A2AClientToolProvider and Agent Source: https://github.com/strands-agents/tools/blob/main/README.md Discover and communicate with A2A-compliant agents. This setup is used for sending messages between agents. ```python provider = A2AClientToolProvider(known_agent_urls=["http://localhost:9000"]) agent = Agent(tools=provider.tools) ``` -------------------------------- ### Configure HTTP Request Authentication Tokens Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Set up authentication tokens for specific domains using HTTP_REQUEST_TOKEN_CONFIG. This example configures tokens for GitHub and GitLab. ```python from strands_tools.http_request import HTTP_REQUEST_TOKEN_CONFIG HTTP_REQUEST_TOKEN_CONFIG["GITHUB_TOKEN"] = ["api.github.com"] HTTP_REQUEST_TOKEN_CONFIG["GITLAB_TOKEN"] = ["gitlab.com"] ``` -------------------------------- ### AWS Config Configuration Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Example of AWS configuration settings including region and output format for default and named profiles. ```ini [default] region = us-west-2 output = json [profile profile-name] region = us-east-1 output = json ``` -------------------------------- ### HTTP Requests with Strands Agent Source: https://github.com/strands-agents/tools/blob/main/README.md Shows how to make GET and POST HTTP requests, including authentication and content type specification. Also demonstrates converting HTML webpages to markdown. ```python from strands import Agent from strands_tools import http_request import json agent = Agent(tools=[http_request]) # Make a simple GET request response = agent.tool.http_request( method="GET", url="https://api.example.com/data" ) # POST request with authentication response = agent.tool.http_request( method="POST", url="https://api.example.com/resource", headers={"Content-Type": "application/json"}, body=json.dumps({"key": "value"}), auth_type="Bearer", auth_token="your_token_here" ) # Convert HTML webpages to markdown for better readability response = agent.tool.http_request( method="GET", url="https://example.com/article", convert_to_markdown=True ) ``` -------------------------------- ### Get Content with Exa Source: https://github.com/strands-agents/tools/blob/main/README.md Extracts full content and summaries from specific URLs. Includes live crawling fallback and summarization options. ```python agent.tool.exa_get_contents(urls=["https://example.com/article"], text=True, summary={"query": "key points"}) ``` -------------------------------- ### Configure LocalChromiumBrowser Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Initialize LocalChromiumBrowser with specific settings for headless mode, user data directory, viewport, and timeout. Ensure the 'local_chromium_browser' extra is installed. ```python from strands_tools.browser import LocalChromiumBrowser browser = LocalChromiumBrowser( headless=True, user_data_dir="/path/to/user/data", viewport={"width": 1920, "height": 1080}, timeout=30000 ) ``` -------------------------------- ### Code Execution Error Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Demonstrates an ExecutionError from AgentCoreCodeInterpreter, indicating a failure during code execution. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: Code execution failed: NameError: name 'undefined_var' is not defined" } ] } ``` -------------------------------- ### Knowledge Base Not Found Error Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Shows an APIError from the Memory Service indicating that a specified Knowledge Base was not found. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: Knowledge base not found: my1234kb" } ] } ``` -------------------------------- ### Get Specific Environment Variable Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Retrieves the value of a specific environment variable by its name. Examples include fetching the HOME directory or AWS region. ```python environment(action="get", name="HOME") environment(action="get", name="AWS_REGION") ``` -------------------------------- ### Record Data with Structured Metadata Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Shows how to attach structured metadata to memory records for enhanced organization and retrieval. Includes examples of type, project, priority, due date, and assignment. ```python # Use structured metadata for better organization result = agent.tool.elasticsearch_memory( action="record", content="Important project deadline", metadata={ "type": "deadline", "project": "project_alpha", "priority": "high", "due_date": "2024-02-01", "assigned_to": ["alice", "bob"] }, **config ) ``` -------------------------------- ### Get Current Time in Specific Timezone Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Retrieves the current time in ISO 8601 format for a specified IANA timezone. Examples include US/Pacific, Europe/London, and Asia/Tokyo. ```python current_time(timezone="US/Pacific") current_time(timezone="Europe/London") current_time(timezone="Asia/Tokyo") ``` -------------------------------- ### AWS Credentials Configuration Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Example of AWS credentials configuration using INI format for default and named profiles. ```ini [default] aws_access_key_id = AKIAIOSFODNN7EXAMPLE aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY [profile-name] aws_access_key_id = AKIAIOSFODNN7EXAMPLE aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY ``` -------------------------------- ### Multi-Tab Comparison Workflow Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Demonstrates setting up multiple tabs for comparison: creating new tabs, navigating each to a different URL. ```python browser.browser({ "action": { "type": "new_tab", "session_name": "comparison", "tab_id": "site-a" } }) ``` ```python browser.browser({ "action": { "type": "navigate", "session_name": "comparison", "url": "https://site-a.com" } }) ``` ```python browser.browser({ "action": { "type": "new_tab", "session_name": "comparison", "tab_id": "site-b" } }) ``` ```python browser.browser({ "action": { "type": "navigate", "session_name": "comparison", "url": "https://site-b.com" } }) ``` -------------------------------- ### Agent Tool Initialization Source: https://github.com/strands-agents/tools/blob/main/_autodocs/tool-signatures.md Shows how to initialize an Agent with a specific list of tools. This allows the agent to utilize the provided tools for its operations. ```python from strands import Agent agent = Agent(tools=[file_read, file_write, http_request]) agent.tool.file_read(...) ``` -------------------------------- ### Install Python Packages Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/code-interpreter.md Installs Python packages using pip, such as 'beautifulsoup4' and 'requests', for web scraping and HTTP requests. ```python code_interpreter.code_interpreter({ "action": { "type": "executeCommand", "command": "pip install beautifulsoup4 requests" } }) ``` -------------------------------- ### Create a Data Pipeline Workflow Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Use the 'workflow' function with 'action="create"' to define a new workflow. This example shows a data pipeline involving reading a CSV, processing it with Python, and writing results to JSON. ```python workflow( action="create", name="data_pipeline", steps=[ { "tool": "file_read", "parameters": { "path": "input_data.csv", "mode": "view" } }, { "tool": "python_repl", "parameters": { "code": "import pandas as pd\ndf = pd.read_csv('input_data.csv')" } }, { "tool": "file_write", "parameters": { "path": "output_data.json", "content": "results" } } ] ) ``` -------------------------------- ### Execute HTTP Request with Digest Authentication Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/http-client.md This example demonstrates digest authentication. You need to provide the `username`, `password`, and `realm` within the `digest_auth` object. ```python http_request( tool={ "toolUseId": "abc123", "input": { "method": "GET", "url": "https://api.example.com/data", "auth_type": "digest", "digest_auth": { "username": "user", "password": "pass", "realm": "example.com" } } } ) ``` -------------------------------- ### Get Specific Memory by ID with AgentCore Source: https://github.com/strands-agents/tools/blob/main/README.md Retrieves a single memory record using its unique ID. Uses the 'get' action. ```python # Get a specific memory by ID result = agent.tool.agent_core_memory( action="get", memory_record_id="mr-12345" ) ``` -------------------------------- ### ScreenshotAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Captures a screenshot of the current page within a browser session. An optional path can be provided to save the screenshot to a file. ```json { "action": { "type": "screenshot", "session_name": "web-scraping-task", "path": "/path/to/screenshot.png" # Optional } } ``` -------------------------------- ### Install MongoDB Memory Tool Dependencies Source: https://github.com/strands-agents/tools/blob/main/docs/mongodb_memory_tool.md Installs the necessary Python dependencies for the MongoDB Atlas Memory Tool, including the pymongo client. ```bash pip install strands-agents-tools[mongodb_memory] ``` -------------------------------- ### Configure and Use Environment Variable for Token Authentication Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/http-client.md This example shows how to configure the tool to use tokens stored in environment variables for authentication. First, configure the `HTTP_REQUEST_TOKEN_CONFIG` dictionary with environment variable names and associated domains. Then, use `auth_env_var` in your `http_request` call. ```python from strands_tools.http_request import HTTP_REQUEST_TOKEN_CONFIG HTTP_REQUEST_TOKEN_CONFIG["GITHUB_TOKEN"] = ["api.github.com"] HTTP_REQUEST_TOKEN_CONFIG["GITLAB_TOKEN"] = ["gitlab.com"] ``` ```python http_request( tool={ "toolUseId": "abc123", "input": { "method": "GET", "url": "https://api.github.com/user", "auth_type": "token", "auth_env_var": "GITHUB_TOKEN" } } ) ``` -------------------------------- ### Browser Initialize Session Action Source: https://github.com/strands-agents/tools/blob/main/README.md Initializes a new browser session with a given name and description. This must be done before other browser actions. ```python # Initialize a session first result = agent.tool.browser({ "action": { "type": "initSession", "session_name": "main-session", "description": "Web automation session" } }) ``` -------------------------------- ### Use Computer: Open Application Source: https://github.com/strands-agents/tools/blob/main/README.md Open a specified application on the computer. ```python from strands import Agent from strands_tools import use_computer agent = Agent(tools=[use_computer]) result = agent.tool.use_computer(action="open_app", app_name="Calculator") ``` -------------------------------- ### Install Elasticsearch Memory Tool Dependencies Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Install the necessary Python package for the Elasticsearch Memory Tool. This includes the Elasticsearch Python client. ```bash pip install strands-agents-tools[elasticsearch_memory] ``` -------------------------------- ### Initialize LocalChromiumBrowser Tool Source: https://github.com/strands-agents/tools/blob/main/README.md Sets up the LocalChromiumBrowser tool for web automation. Requires importing the tool and initializing the Agent with it. ```python from strands import Agent from strands_tools.browser import LocalChromiumBrowser # Create browser tool browser = LocalChromiumBrowser() agent = Agent(tools=[browser.browser]) ``` -------------------------------- ### File Operations with Strands Agent Source: https://github.com/strands-agents/tools/blob/main/README.md Demonstrates how to use file_read, file_write, and editor tools with a Strands Agent. Ensure the agent is initialized with the necessary file operation tools. ```python from strands import Agent from strands_tools import file_read, file_write, editor agent = Agent(tools=[file_read, file_write, editor]) agent.tool.file_read(path="config.json") agent.tool.file_write(path="output.txt", content="Hello, world!") agent.tool.editor(command="view", path="script.py") ``` -------------------------------- ### current_time Source: https://github.com/strands-agents/tools/blob/main/_autodocs/tool-signatures.md Gets the current time, with an optional timezone. ```APIDOC ## current_time ### Description Retrieves the current system time. ### Parameters - **timezone** (str) - Optional - The desired timezone (default: UTC). ``` -------------------------------- ### Create Nested Agent Instances with Use Agent Tool Source: https://github.com/strands-agents/tools/blob/main/README.md Create nested agent instances with model switching, multi-model workflows, and cost optimization using the use_agent tool. Specify prompts, system prompts, and model providers. ```python agent.tool.use_agent(prompt="Analyze this code", system_prompt="You are a code analyst.", model_provider="bedrock") ``` -------------------------------- ### BackAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Navigates to the previous page in the browser history for the specified session. ```json { "action": { "type": "back", "session_name": "web-scraping-task" } } ``` -------------------------------- ### Proxy Configuration Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/http-client.md Sets up proxy servers for HTTP and HTTPS requests. ```APIDOC ## Proxy Configuration ### Description Configure proxy servers to route HTTP and HTTPS traffic. ### Method GET ### Endpoint https://example.com/api ### Parameters #### Request Body - **proxies** (object) - Optional - A dictionary mapping protocol to proxy URL. - **https** (string) - Optional - The proxy URL for HTTPS traffic. - **http** (string) - Optional - The proxy URL for HTTP traffic. ### Request Example ```json { "toolUseId": "abc123", "input": { "method": "GET", "url": "https://example.com/api", "proxies": { "https": "https://proxy.example.com:8080", "http": "http://proxy.example.com:8080" } } } ``` ``` -------------------------------- ### Dynamic MCP Client Integration Source: https://github.com/strands-agents/tools/blob/main/README.md Shows how to connect to custom MCP servers (stdio, SSE, HTTP) and interact with remote tools. Includes security warnings about autonomous connections to external servers. Tools can be loaded directly into the agent's registry. ```python from strands import Agent from strands_tools import mcp_client agent = Agent(tools=[mcp_client]) # Connect to a custom MCP server via stdio agent.tool.mcp_client( action="connect", connection_id="my_tools", transport="stdio", command="python", args=["my_mcp_server.py"] ) # List available tools on the server tools = agent.tool.mcp_client( action="list_tools", connection_id="my_tools" ) # Call a tool from the MCP server result = agent.tool.mcp_client( action="call_tool", connection_id="my_tools", tool_name="calculate", tool_args={"x": 10, "y": 20} ) # Connect to a SSE-based server agent.tool.mcp_client( action="connect", connection_id="web_server", transport="sse", server_url="http://localhost:8080/sse" ) # Connect to a streamable HTTP server agent.tool.mcp_client( action="connect", connection_id="http_server", transport="streamable_http", server_url="https://api.example.com/mcp", headers={"Authorization": "Bearer token"}, timeout=60 ) # Load MCP tools into agent's registry for direct access # ⚠️ WARNING: This loads external tools directly into the agent agent.tool.mcp_client( action="load_tools", connection_id="my_tools" ) # Now you can call MCP tools directly as: agent.tool.calculate(x=10, y=20) ``` -------------------------------- ### RefreshAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Reloads the current page within the specified browser session. ```json { "action": { "type": "refresh", "session_name": "web-scraping-task" } } ``` -------------------------------- ### Configure AgentCoreCodeInterpreter Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Initialize AgentCoreCodeInterpreter with the AWS region. Ensure the 'agent_core_code_interpreter' extra is installed. ```python from strands_tools.code_interpreter import AgentCoreCodeInterpreter interpreter = AgentCoreCodeInterpreter( region="us-west-2" ) ``` -------------------------------- ### Organize Data with Namespaces Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Demonstrates different strategies for using the namespace parameter to isolate data for users, sessions, organizations, or features. Essential for multi-tenant applications. ```python # User-based namespaces user_namespace = f"user_{user_id}" # Session-based namespaces session_namespace = f"session_{session_id}" # Hierarchical namespaces org_user_namespace = f"org_{org_id}_user_{user_id}" # Feature-based namespaces chat_namespace = "feature_chat" task_namespace = "feature_tasks" ``` -------------------------------- ### Get Cookies Action Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Retrieves all cookies associated with the current page in a specified session. ```python { "action": { "type": "get_cookies", "session_name": "web-scraping-task" } } ``` -------------------------------- ### Current Time Tool Signature Source: https://github.com/strands-agents/tools/blob/main/_autodocs/tool-signatures.md Signature for getting the current time, with an optional timezone parameter. ```python @tool def current_time(timezone: str = None) -> dict ``` -------------------------------- ### Initialize and Execute Code in Code Interpreter Source: https://github.com/strands-agents/tools/blob/main/README.md Set up a sandboxed environment for executing Python code and manage sessions for data analysis. ```python from strands import Agent from strands_tools.code_interpreter import AgentCoreCodeInterpreter # Create the code interpreter tool bedrock_agent_core_code_interpreter = AgentCoreCodeInterpreter(region="us-west-2") agent = Agent(tools=[bedrock_agent_core_code_interpreter.code_interpreter]) # Create a session agent.tool.code_interpreter({ "action": { "type": "initSession", "description": "Data analysis session", "session_name": "analysis-session" } }) # Execute Python code agent.tool.code_interpreter({ "action": { "type": "executeCode", "session_name": "analysis-session", "code": "print('Hello from sandbox!')", "language": "python" } }) ``` -------------------------------- ### Initialize Agent with Stability AI Tool Source: https://github.com/strands-agents/tools/blob/main/docs/stability_ai_tool.md Create a Strands agent and include the `generate_image_stability` tool. The agent does not need to be explicitly passed your API key. ```python import os from strands import Agent from strands_tools import generate_image_stability agent = Agent(tools=[generate_image_stability]) ``` -------------------------------- ### ClickAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Clicks on a specific element identified by a CSS selector within a browser session. ```json { "action": { "type": "click", "session_name": "web-scraping-task", "selector": "button.submit" } } ``` -------------------------------- ### Create Base and User-Specific Configurations Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Defines a base configuration and a function to create user-specific configurations by merging the base with user details. Useful for managing distinct settings for different users or tenants. ```python base_config = { "cloud_id": "your-cloud-id", "api_key": "your-api-key", "region": "us-east-1" } def get_user_config(user_id): return { **base_config, "index_name": "user_memories", "namespace": f"user_{user_id}" } user_config = get_user_config("alice") result = agent.tool.elasticsearch_memory( action="record", content="Alice likes Italian food", **user_config ) ``` -------------------------------- ### Use Computer: Get Mouse Position Source: https://github.com/strands-agents/tools/blob/main/README.md Retrieve the current position of the mouse cursor on the computer screen. ```python from strands import Agent from strands_tools import use_computer agent = Agent(tools=[use_computer]) # Find mouse position result = agent.tool.use_computer(action="mouse_position") ``` -------------------------------- ### Get Specific Memory by ID Source: https://github.com/strands-agents/tools/blob/main/docs/mongodb_memory_tool.md Retrieve a single memory from MongoDB using its unique memory ID. ```python # Retrieve a specific memory by ID result = agent.tool.mongodb_memory( action="get", memory_id="mem_1704567890123_abc12345", cluster_uri="mongodb+srv://user:password@cluster.mongodb.net/", database_name="memory_db", collection_name="memories", namespace="user_123" ) ``` -------------------------------- ### agent.tool.use_llm Source: https://github.com/strands-agents/tools/blob/main/README.md Creates nested AI loops with customized system prompts for specialized tasks. ```APIDOC ## agent.tool.use_llm ### Description Creates nested AI loops with customized system prompts for specialized tasks. ### Method `agent.tool.use_llm(prompt="Analyze this data", system_prompt="You are a data analyst")` ### Parameters - **prompt** (string) - Required - The prompt for the LLM. - **system_prompt** (string) - Optional - The system prompt to customize the LLM's behavior. ``` -------------------------------- ### environment Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Manage and inspect environment variables safely. Supports listing, getting, setting, and deleting variables. ```APIDOC ## environment ### Description Manage and inspect environment variables safely. Supports operations like listing, getting, setting, and deleting variables. ### Method Not applicable (Python function) ### Parameters #### Query Parameters - **action** (string) - Required - Operation to perform: list, get, set, delete. - **prefix** (string) - Optional - Filter results by prefix (for list action). - **name** (string) - Optional - Variable name (for get, set, delete actions). - **value** (string) - Optional - Variable value (for set action). ### Actions #### list List environment variables, optionally filtered by prefix. ```python # List all environment variables environment(action="list") # List variables starting with AWS_ environment(action="list", prefix="AWS_") ``` #### get Get a specific environment variable. ```python environment(action="get", name="HOME") environment(action="get", name="AWS_REGION") ``` #### set Set an environment variable. ```python environment(action="set", name="MY_VAR", value="my_value") ``` #### delete Unset an environment variable. ```python environment(action="delete", name="MY_VAR") ``` ### Usage Example ```python # List all AWS-related variables environment(action="list", prefix="AWS_") # Get current working directory environment(action="get", name="PWD") # Set API key for current session environment(action="set", name="API_KEY", value="sk-...") ``` ``` -------------------------------- ### TypeAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Enters text into an input field identified by a CSS selector within a browser session. ```json { "action": { "type": "type", "session_name": "web-scraping-task", "selector": "input[type='search']", "text": "laptop" } } ``` -------------------------------- ### Element Not Found Error Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Shows a SelectorNotFound error when a CSS selector does not match any elements in LocalChromiumBrowser. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: No element found matching selector: button.submit" } ] } ``` -------------------------------- ### Create Nested AI Loops with Use LLM Tool Source: https://github.com/strands-agents/tools/blob/main/README.md Create nested AI loops with customized system prompts for specialized tasks using the use_llm tool. Specify the user prompt and system prompt. ```python agent.tool.use_llm(prompt="Analyze this data", system_prompt="You are a data analyst") ``` -------------------------------- ### Session Validation Error Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Illustrates a ValidationError for an invalid session name format when interacting with LocalChromiumBrowser. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: Invalid session_name. Must match pattern ^[a-z0-9-]+$ and be 10-36 characters" } ] } ``` -------------------------------- ### List All Environment Variables Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Lists all environment variables. This action is useful for inspecting the current environment settings. ```python environment(action="list") ``` -------------------------------- ### Initialize and Navigate Browser Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Use LocalChromiumBrowser to initialize a session, navigate to a URL, and extract text content from an element. ```python from strands_tools.browser import LocalChromiumBrowser browser = LocalChromiumBrowser() # Initialize session browser.browser({ "action": { "type": "init_session", "session_name": "my-session", "description": "Web scraping task" } }) # Navigate and extract browser.browser({ "action": { "type": "navigate", "session_name": "my-session", "url": "https://example.com" } }) browser.browser({ "action": { "type": "get_text", "session_name": "my-session", "selector": "h1" } }) ``` -------------------------------- ### GetTextAction Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Extracts the text content from a specific element identified by a CSS selector within a browser session. ```json { "action": { "type": "get_text", "session_name": "web-scraping-task", "selector": "h1.title" } } ``` -------------------------------- ### Read File with Syntax Highlighting Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md Use this snippet to read a file and display its content with syntax highlighting. The 'strands' library must be imported, and an Agent initialized with file operation tools. ```python # Read with syntax highlighting agent.tool.file_read( path="script.py", mode="view" ) ``` -------------------------------- ### Initialize Mem0 Memory Tool Source: https://github.com/strands-agents/tools/blob/main/_autodocs/configuration.md Instantiate the AgentCoreMem0MemoryTool with API key, user ID, and agent ID. This is required for using the Mem0 memory service. ```python from strands_tools import mem0_memory mem0_memory = AgentCoreMem0MemoryTool( api_key="your-mem0-api-key", user_id="user-identifier", agent_id="agent-identifier" ) ``` -------------------------------- ### File Content Validation Error Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Represents a ContentValidationError in AgentCoreCodeInterpreter when both text and blob are provided for file content. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: FileContent validation failed: Both text and blob cannot be provided" } ] } ``` -------------------------------- ### Basic Image Generation with Agent Source: https://github.com/strands-agents/tools/blob/main/docs/stability_ai_tool.md Use the agent to generate an image by providing only the text prompt. The agent will utilize the configured Stability AI tool. ```python agent("Generate an image of a futuristic robot in a cyberpunk city") ``` -------------------------------- ### Write Content to a File Source: https://github.com/strands-agents/tools/blob/main/_autodocs/README.md This snippet shows how to write content to a file, including a confirmation step. Ensure the 'strands' library is imported and the Agent is set up with file operation tools. ```python # Write with confirmation agent.tool.file_write( path="output.txt", content="Hello, world!" ) ``` -------------------------------- ### Make HTTP Request Source: https://github.com/strands-agents/tools/blob/main/README.md Performs HTTP requests to APIs or web services. Supports various methods like GET. ```python agent.tool.http_request(method="GET", url="https://api.example.com/data") ``` -------------------------------- ### Environment Management Tool Signature Source: https://github.com/strands-agents/tools/blob/main/_autodocs/tool-signatures.md Signature for managing environment variables. Supports 'list', 'get', 'set', and 'delete' actions. ```python @tool def environment(action: str, prefix: str = None, name: str = None, value: str = None) -> dict ``` -------------------------------- ### Desktop GUI Automation with Use Computer Tool Source: https://github.com/strands-agents/tools/blob/main/README.md Perform desktop automation, GUI interaction, and screen capture using the use_computer tool. Specify the action, coordinates, and application name. ```python agent.tool.use_computer(action="click", x=100, y=200, app_name="Chrome") ``` -------------------------------- ### List Environment Variables Source: https://github.com/strands-agents/tools/blob/main/README.md Manages environment variables and configuration settings. Can list variables with a specified prefix. ```python agent.tool.environment(action="list", prefix="AWS_") ``` -------------------------------- ### current_time Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md Get the current time in ISO 8601 format for a specified timezone. It supports various IANA timezone identifiers. ```APIDOC ## current_time ### Description Get the current time in ISO 8601 format for a specified timezone. ### Method Not applicable (Python function) ### Parameters #### Query Parameters - **timezone** (string) - Optional - IANA timezone (e.g., "US/Pacific", "Europe/London", "Asia/Tokyo") - Defaults to UTC ### Response #### Success Response - **status** (string) - Indicates the status of the operation, e.g., "success". - **content** (list) - A list containing a dictionary with a "text" field showing the formatted time. ### Response Example ```json { "status": "success", "content": [{"text": "2024-01-15T14:30:45.123456Z (UTC)\n2024-01-15T06:30:45.123456-08:00 (US/Pacific)"}] } ``` ### Usage Examples ```python # Get current UTC time current_time() # Get time in specific timezone current_time(timezone="US/Pacific") current_time(timezone="Europe/London") current_time(timezone="Asia/Tokyo") ``` ``` -------------------------------- ### Analyze Data and Handoff to User Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/utility-tools.md This snippet shows how to use the python_repl tool for data analysis and then hand off the results to the user for confirmation. ```python analysis_result = agent.tool.python_repl(code="...") user_response = agent.tool.handoff_to_user( message=f"Analysis complete. Results:\n{analysis_result}\n\nPlease confirm next steps." ) if "approve" in user_response.lower(): # Proceed with next steps pass ``` -------------------------------- ### AWS Credential Chain Error Example Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Illustrates an authentication error where AWS credentials could not be found in the credential chain. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: AWS authentication error: No AWS credentials found in the credential chain" } ] } ``` -------------------------------- ### Initialize Elasticsearch Memory Tool Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/memory-tools.md Initialize the Elasticsearch Memory tool with your cloud ID and API key. Then, associate it with an agent. ```python from strands_tools import ElasticsearchMemory memory_tool = ElasticsearchMemory( cloud_id="your-elastic-cloud-id", api_key="your-elastic-api-key" ) agent = Agent(tools=[memory_tool.memory_tool]) ``` -------------------------------- ### Calculator Numerical Evaluation Error Response Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Example of an error response when the calculator fails to evaluate a numerical result for an expression. ```python { "status": "error", "content": [{"text": "Error: Could not evaluate numerically: ..."}] } ``` -------------------------------- ### Shell Command Execution Source: https://github.com/strands-agents/tools/blob/main/README.md Demonstrates executing shell commands using the `shell` tool. Supports single commands, sequences of commands, and ignoring errors. Note that this tool is not compatible with Windows. ```python from strands import Agent from strands_tools import shell agent = Agent(tools=[shell]) # Execute a single command result = agent.tool.shell(command="ls -la") # Execute a sequence of commands results = agent.tool.shell(command=["mkdir -p test_dir", "cd test_dir", "touch test.txt"]) # Execute commands with error handling agent.tool.shell(command="risky-command", ignore_errors=True) ``` -------------------------------- ### Crawl Website with Tavily Source: https://github.com/strands-agents/tools/blob/main/README.md Intelligently crawls websites starting from a base URL. Supports filtering and extraction with a maximum depth. ```python agent.tool.tavily_crawl(url="www.tavily.com", max_depth=2, instructions="Find API docs") ``` -------------------------------- ### List Memories with Pagination Source: https://github.com/strands-agents/tools/blob/main/docs/mongodb_memory_tool.md Retrieve a list of memories from MongoDB with pagination, specifying the maximum results and a next token to start from. ```python # List with pagination result = agent.tool.mongodb_memory( action="list", max_results=10, next_token="10", # Start from the 11th result cluster_uri="mongodb+srv://user:password@cluster.mongodb.net/", database_name="memory_db", collection_name="memories", namespace="user_123" ) ``` -------------------------------- ### Handle Missing Connection Parameters Source: https://github.com/strands-agents/tools/blob/main/docs/mongodb_memory_tool.md Demonstrates error handling when essential connection parameters like 'cluster_uri' are missing for a memory record action. The tool returns an error status and message. ```python # Missing connection parameters result = memory_tool.record_memory(content="test") # Returns: {"status": "error", "content": [{"text": "cluster_uri is required"}]} ``` -------------------------------- ### Initialize Code Interpreter Session Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/code-interpreter.md Initializes a new session for code interpretation, useful for starting data analysis tasks. ```python code_interpreter.code_interpreter({ "action": { "type": "initSession", "description": "Analyze sales data" } }) ``` -------------------------------- ### Initialize A2A Client and Interact with Agents Source: https://github.com/strands-agents/tools/blob/main/README.md Initialize the A2A client provider with known agent URLs and use natural language to interact with A2A agents. The agent automatically uses tools for discovery and messaging. ```python from strands import Agent from strands_tools.a2a_client import A2AClientToolProvider # Initialize the A2A client provider with known agent URLs provider = A2AClientToolProvider(known_agent_urls=["http://localhost:9000"]) agent = Agent(tools=provider.tools) # Use natural language to interact with A2A agents response = agent("discover available agents and send a greeting message") ``` -------------------------------- ### Get Current Time with Timezone Source: https://github.com/strands-agents/tools/blob/main/README.md Retrieve the current time in ISO 8601 format for a specified timezone using the current_time tool. ```python agent.tool.current_time(timezone="US/Pacific") ``` -------------------------------- ### Get File Statistics Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/file-operations.md Displays file statistics like size and line count. Ensure the path points to the desired file. ```python file_read( tool={ "toolUseId": "abc123", "input": { "path": "/path/to/file.txt", "mode": "stats" } } ) ``` -------------------------------- ### Web Scraping Workflow Source: https://github.com/strands-agents/tools/blob/main/_autodocs/api-reference/browser-automation.md Demonstrates a basic web scraping workflow: initializing a session, navigating to a URL, and extracting text content based on a CSS selector. ```python browser.browser({ "action": { "type": "init_session", "session_name": "scraper-001", "description": "Scrape product listings" } }) ``` ```python browser.browser({ "action": { "type": "navigate", "session_name": "scraper-001", "url": "https://example.com/products" } }) ``` ```python browser.browser({ "action": { "type": "get_text", "session_name": "scraper-001", "selector": "div.product-list" } }) ``` -------------------------------- ### Run Integration Tests with Hatch Source: https://github.com/strands-agents/tools/blob/main/CONTRIBUTING.md Execute integration tests to verify the behavior of the system in a more realistic environment. ```bash hatch run test-integ ``` -------------------------------- ### HTTP Request Authentication Error Response Source: https://github.com/strands-agents/tools/blob/main/_autodocs/errors.md Example of an error response when authentication fails due to missing or misconfigured environment variables. ```python { "toolUseId": "", "status": "error", "content": [ { "text": "Error: Environment variable 'GITHUB_TOKEN' is not listed in HTTP_REQUEST_TOKEN_CONFIG..." } ] } ``` -------------------------------- ### Initialize Graph Tool for Multi-Agent DAGs Source: https://github.com/strands-agents/tools/blob/main/README.md Initialize the graph tool for creating deterministic DAG-based multi-agent pipelines. This tool uses task-based execution with output propagation. ```python from strands import Agent from strands_tools.graph import graph agent = Agent(tools=[graph]) ``` -------------------------------- ### Create Videos with Nova Reels Source: https://github.com/strands-agents/tools/blob/main/README.md Generates high-quality videos using Amazon Bedrock Nova Reel. Parameters can be configured via environment variables. ```python agent.tool.nova_reels(action="create", text="A cinematic shot of mountains", s3_bucket="my-bucket") ``` -------------------------------- ### List Memories with Pagination Source: https://github.com/strands-agents/tools/blob/main/docs/elasticsearch_memory_tool.md Retrieves a paginated list of memories from Elasticsearch. Use `next_token` to specify the starting point for subsequent results. ```python # List with pagination result = agent.tool.elasticsearch_memory( action="list", max_results=10, next_token="10", # Start from the 11th result cloud_id="your-cloud-id", api_key="your-api-key", index_name="memories", namespace="user_123" ) ``` -------------------------------- ### Exa Search and Contents Source: https://github.com/strands-agents/tools/blob/main/README.md Demonstrates using Exa tools for web search and retrieving content. The `exa_search` tool supports text-based results and defaults to an auto mode for optimal search. ```python from strands import Agent from strands_tools.exa import exa_search, exa_get_contents agent = Agent(tools=[exa_search, exa_get_contents]) # Basic search (auto mode is default and recommended) result = agent.tool.exa_search( query="Best project management software", text=True ) ```