Strands Agents Tools

repository·main·Indexed 19 days ago

https://github.com/strands-agents/tools

A collection of specialized, experimental tools for AI agents to interact with the real world. It provides capabilities for file operations, shell integration, Python execution, AWS integration, and web infrastructure via Tavily and Exa. The suite includes advanced orchestration features such as Swarm Intelligence, Multi-Agent Graphs (DAG-based pipelines), and a Dynamic MCP Client for connecting to external Model Context Protocol servers.

Tokens
29.5K
Snippets
77
Records
123
Agent score
77%

What's inside strands-agents-tools

  1. Overview of Strands Agents Tools

    main

    Strands Agents Tools is a community-driven project providing a set of tools designed to bridge the gap between large language models (LLMs) and practical applications. It enables agents to perform a wide range of tasks including file operations, system execution, API interactions, and more.

    Note: The tools in this repository are experimental. Because they grant agents powerful capabilities (e.g., executing code, accessing file systems, calling AWS APIs, and automating browsers/desktops), they carry significant security implications. Users should perform independent security reviews before production use.

  2. Overview of available strands-agents-tools

    main

    The strands-agents-tools package provides a wide variety of tools for agents, ranging from file manipulation and web searching to cloud service interaction and memory management.

    Key Tool Categories

    • File Operations: file_read, file_write (Note: editor is deprecated).
    • Web & Search: http_request, tavily_search, tavily_extract, tavily_crawl, tavily_map, exa_search, exa_get_contents, bright_data, rss.
    • Code & Computation: python_repl, code_interpreter, calculator.
    • Cloud & AWS: use_aws, retrieve (Bedrock Knowledge Bases), nova_reels, agent_core_memory, memory (Bedrock Knowledge Bases).
    • Memory Systems: mem0_memory, mongodb_memory, elasticsearch_memory.
    • Agent Orchestration: swarm, agent_graph, graph, workflow, use_llm, use_agent, batch.
    • System & Environment: environment, current_time, sleep (Deprecated), cron (Not on Windows).
    • Communication & UI: slack, speak, handoff_to_user, diagram.
    • Automation: browser, use_computer.
    • Specialized: mcp_client (Security Warning: can connect to external servers), search_video, chat_video.

    Note: Tools marked with * (e.g., shell*, python_repl*, cron*) do not work on Windows. Tools marked with ⚠️ are deprecated.

    ToolAgent Usage ExampleUse Case
    a2a_clientprovider = A2AClientToolProvider(known_agent_urls=["http://localhost:9000"]); agent = Agent(tools=provider.tools)Discover and communicate with A2A-compliant agents
    file_readagent.tool.file_read(path="path/to/file.txt")Reading configuration files, parsing code
    file_writeagent.tool.file_write(path="path/to/file.txt", content="file content")Writing results to files
    http_requestagent.tool.http_request(method="GET", url="https://api.example.com/data")Making API calls
    tavily_searchagent.tool.tavily_search(query="What is AI?", search_depth="advanced")Real-time web search
    code_interpretercode_interpreter = AgentCoreCodeInterpreter(region="us-west-2"); agent = Agent(tools=[code_interpreter.code_interpreter])Execute code in isolated sandboxes
    mem0_memoryagent.tool.mem0_memory(action="store", content="Remember I like tennis")Store user/agent memories
    mcp_clientagent.tool.mcp_client(action="connect", connection_id="my_server", transport="stdio", command="python", args=["server.py"])Connect to external MCP servers (⚠️ SECURITY RISK)
    batchagent.tool.batch(invocations=[{"name": "current_time", "arguments": {"timezone": "Europe/London"}}, {"name": "stop", "arguments": {}}])Call multiple tools in parallel
  3. Features of Strands Agents Tools

    main

    Strands Agents Tools provides a diverse set of capabilities for AI agents, including:

    • File Operations: Read, write, and edit files with syntax highlighting and intelligent modifications.
    • Shell Integration: Securely execute and interact with shell commands.
    • Memory: Persistent storage for user and agent memories using Mem0, Amazon Bedrock Knowledge Bases, Elasticsearch, or MongoDB Atlas.
    • Web Infrastructure: Web searches, content extraction, and crawling via Tavily and Exa.
    • HTTP Client: API requests with comprehensive authentication support.
    • Slack Client: Real-time Slack events, message processing, and API access.
    • Python Execution: Run Python code with state persistence, safety features, and user confirmation.
    • Mathematical Tools: Advanced calculations and symbolic math.
    • AWS Integration: Access to AWS services.
    • Media Processing: Image generation/processing, video generation, and audio output.
    • Environment Management: Safe handling of environment variables.
    • Task & Journaling: Structured logging/journaling and cron-based task scheduling.
    • Advanced Reasoning & Coordination: Tools for complex reasoning, Swarm Intelligence (parallel problem solving with shared memory), and Multi-Agent Graphs (deterministic DAG-based pipelines).
    • Agentic Capabilities:
      • Agent as Tool: Create nested agent instances with model switching.
      • Batch Tool: Call multiple tools in parallel.
      • Browser Tool: Automated actions via Chromium.
      • Computer Tool: Desktop automation (mouse, keyboard, screenshots).
    • Specialized Tools: AWS/UML diagram generation, RSS Feed management, and a Dynamic MCP Client for connecting to external MCP servers.
  4. Optimize MongoDBMemoryTool performance

    main

    To ensure efficient use of the MongoDBMemoryTool, consider the following:

    • Embedding Generation: Embeddings are generated using the Amazon Bedrock Titan model. Since every record and retrieve operation requires embedding generation, implement caching strategies for frequently accessed queries to reduce latency and costs.
    • Index Optimization: The tool uses cosine similarity for semantic matching and creates optimized vector search indices. Ensure Atlas Search is enabled and indices are properly configured.
    • Pagination: For large result sets, use the max_results parameter to control batch size and the next_token parameter to enable efficient pagination via skip/limit logic.
  5. Integrate Dynamic MCP Clients

    main

    The mcp_client tool allows agents to autonomously connect to external Model Context Protocol (MCP) servers at runtime.

    SECURITY WARNING: This allows agents to connect to external servers and execute untrusted code. Use with extreme caution in production.

    Supported transports:

    • stdio: Connect via command and arguments (e.g., running a local python script).
    • sse: Connect via a Server-Sent Events URL.
    • streamable_http: Connect via a streamable HTTP endpoint with optional headers and timeout.

    Actions:

    • connect: Establish a connection using a connection_id.
    • list_tools: List tools available on a connected server.
    • call_tool: Execute a specific tool on the server.
    • load_tools: Load MCP tools directly into the agent's registry for direct access (e.g., agent.tool.tool_name()).
    from strands import Agent
    from strands_tools import mcp_client
    
    agent = Agent(tools=[mcp_client])
    
    # Connect via stdio
    agent.tool.mcp_client(
        action="connect",
        connection_id="my_tools",
        transport="stdio",
        command="python",
        args=["my_mcp_server.py"]
    )
    
    # List tools
    tools = agent.tool.mcp_client(
        action="list_tools",
        connection_id="my_tools"
    )
    
    # Call a tool
    result = agent.tool.mcp_client(
        action="call_tool",
        connection_id="my_tools",
        tool_name="calculate",
        tool_args={"x": 10, "y": 20}
    )
    
    # Load tools for direct access
    agent.tool.mcp_client(action="load_tools", connection_id="my_tools")
    # Now call directly: agent.tool.calculate(x=10, y=20)
  6. How the Elasticsearch Memory Tool security model works

    main

    The tool uses a direct tool pattern designed to prevent prompt injection or model manipulation from accessing unauthorized data.

    Connection credentials (cloud_id/es_url/api_key), the target index_name, and the namespace are never exposed as agent-facing tool parameters. The agent is only permitted to choose the action and its associated payload (content, query, or memory_id).

    There are two ways to implement this:

    1. Class-based (Recommended for multi-tenant): You instantiate ElasticsearchMemoryTool per user/principal, binding their specific namespace and credentials at construction. The agent then uses the .elasticsearch_memory method of that instance.
    2. Standalone function (Single-tenant): You use the module-level elasticsearch_memory function. This reads all configuration (connection, index, namespace, and embeddings) from environment variables. It is intended for single-tenant applications.
  7. Configure the Mem0 Memory Tool

    main

    The Mem0MemoryTool provides memory management with a security model that isolates tenants by using user_id or agent_id which are never exposed to the agent itself.

    Backend Selection Logic

    • Mem0 Platform: Set MEM0_API_KEY.
    • OpenSearch: Set OPENSEARCH_HOST (Recommended for AWS).
    • FAISS: Default if neither of the above are set (requires faiss-cpu).
    • Neptune Analytics: Set NEPTUNE_ANALYTICS_GRAPH_IDENTIFIER to enable as a graph store for enhanced recall.

    Usage Patterns

    Multi-tenant (Recommended): Bind identity per authenticated principal by passing user_id to the constructor.

    Single-tenant: Use the standalone function with MEM0_USER_ID or MEM0_AGENT_ID environment variables.

    Key Environment Variables

    VariableDescriptionDefault
    MEM0_USER_IDUser ID for standalone operationsNone
    MEM0_AGENT_IDAgent ID for standalone operationsNone
    MEM0_API_KEYMem0 Platform API keyNone
    OPENSEARCH_HOSTOpenSearch Host URLNone
    NEPTUNE_ANALYTICS_GRAPH_IDENTIFIERNeptune Analytics Graph IdentifierNone
    MEM0_LLM_PROVIDERLLM provider for memory processingaws_bedrock
    MEM0_EMBEDDER_PROVIDEREmbedder provider for vector embeddingsaws_bedrock
    from strands import Agent
    from strands_tools.mem0_memory import Mem0MemoryTool, mem0_memory
    
    # Multi-tenant (recommended): bind identity per authenticated principal
    tool = Mem0MemoryTool(user_id=f"user_{authenticated_user_id}")
    agent = Agent(tools=[tool.mem0_memory])
    agent.tool.mem0_memory(action="store", content="User prefers vegetarian pizza")
    
    # Single-tenant: use the standalone function with env vars (MEM0_USER_ID / MEM0_AGENT_ID)
    agent = Agent(tools=[mem0_memory])
    agent.tool.mem0_memory(action="store", content="User prefers vegetarian pizza")
  8. How the MongoDB Atlas Memory Tool security model works

    main

    The tool uses a security model designed to prevent prompt injection or model errors from accessing unauthorized data.

    Connection credentials, the target database/collection, and the tenant namespace are never exposed as agent-facing tool parameters. The agent is only permitted to choose the action and its associated content, query, or memory_id.

    This ensures that an agent cannot redirect memory operations to a different cluster or access/delete memories belonging to a different namespace by manipulating tool arguments.

  9. Configure namespaces for logical grouping

    main

    The namespace is a document field used for logical grouping and query filtering within a collection. It is bound to the MongoDBMemoryTool instance at construction time and is not controllable by the agent. This ensures security by isolating data per user or session.

    Namespace Patterns

    • User-based: f"user_{user_id}"
    • Session-based: f"session_{session_id}"
    • Hierarchical: f"org_{org_id}_user_{user_id}"
    • Feature-based: "feature_chat" or "feature_tasks"
    # Bind a specific namespace during tool construction
    memory_tool = MongoDBMemoryTool(
        cluster_uri="mongodb+srv://user:password@cluster.mongodb.net/",
        database_name="memory_db",
        collection_name="memories",
        namespace=f"user_{user_id}",
    )
  10. Performance and Security considerations for Elasticsearch Memory

    main

    Performance

    • Embedding Generation: Uses Amazon Bedrock Titan. Each record/retrieve operation requires embedding generation; consider caching frequently accessed queries.
    • Index Optimization: Uses cosine similarity for semantic matching.
    • Pagination: Use max_results to control batch size and next_token for efficient pagination of large result sets.

    Security

    • API Key Management: Store keys in environment variables or secrets managers. Use least-privilege keys and rotate them regularly.
    • Data Privacy: Always bind the namespace at construction time. Never expose the namespace as an agent-controllable parameter.
    • Network Security: Use HTTPS for all connections and consider VPC/private networking for production environments.
  11. Organize memory data using namespaces

    main

    The namespace parameter is used for data isolation and multi-tenant memory management. It is bound to the ElasticsearchMemoryTool instance at construction and is not agent-controllable, which ensures security by preventing an agent from accessing other users' data.

    Common namespace patterns include:

    • User-based: f"user_{user_id}"
    • Session-based: f"session_{session_id}"
    • Hierarchical: f"org_{org_id}_user_{user_id}"
    • Feature-based: "feature_chat" or "feature_tasks"
    # Bind the chosen namespace when constructing the tool
    memory_tool = ElasticsearchMemoryTool(
        cloud_id="your-cloud-id",
        api_key="your-api-key",
        namespace="user_123",
    )
  12. Use Semantic Memory with Elasticsearch or MongoDB Atlas

    main

    Both elasticsearch_memory and mongodb_memory provide semantic (vector) memory capabilities for agents. These tools require AWS credentials to generate embeddings via Amazon Bedrock Titan models.

    Key Concepts:

    • Provider Setup: Use ElasticsearchMemoryTool or MongoDBMemoryTool to bind connection details (cluster URI, API keys, index/collection names) and a namespace (to isolate user data).
    • Actions:
      • record: Store content with optional metadata.
      • retrieve: Perform semantic search using a query.
      • list: List memories with pagination.
      • get: Retrieve a specific memory by memory_id.
      • delete: Remove a memory by memory_id.

    Single-tenant mode: You can use the standalone tools (elasticsearch_memory or mongodb_memory) which rely on environment variables for configuration.

    from strands import Agent
    from strands_tools.elasticsearch_memory import ElasticsearchMemoryTool
    
    # Setup provider
    memory_tool = ElasticsearchMemoryTool(
        cloud_id="your-id",
        api_key="your-key",
        index_name="memories",
        namespace="user_123",
    )
    agent = Agent(tools=[memory_tool.elasticsearch_memory])
    
    # Record memory
    agent.tool.elasticsearch_memory(
        action="record",
        content="User prefers vegetarian pizza",
        metadata={"category": "food"}
    )
    
    # Semantic retrieval
    result = agent.tool.elasticsearch_memory(
        action="retrieve",
        query="dietary preferences"
    )