Skip to content

feat(manage_tools): add runtime tool management capabilities#390

Open
cagataycali wants to merge 2 commits intostrands-agents:mainfrom
cagataycali:feat/manage-tools
Open

feat(manage_tools): add runtime tool management capabilities#390
cagataycali wants to merge 2 commits intostrands-agents:mainfrom
cagataycali:feat/manage-tools

Conversation

@cagataycali
Copy link
Copy Markdown
Contributor

Summary

Add manage_tools tool for dynamic tool management at runtime - a package manager for AI agent tools.

Features

  • list: Display all currently registered tools
  • add: Load tools from packages, files, URLs, or GitHub
  • remove: Unregister tools by name
  • reload: Hot-reload tools to pick up code changes
  • create: Generate new tools from Python code on-the-fly
  • fetch: Download and load tools from remote URLs
  • discover: List all available tools in a module with introspection
  • sandbox: Validate code in isolated subprocess before loading

Key Highlights

  • Package manager for AI agent tools - expand capabilities without restarts
  • Auto-installation of missing PyPI packages via pip or uv
  • Sandbox testing validates code before loading into agent
  • GitHub blob URL auto-conversion to raw URLs
  • Comprehensive test coverage

Environment Variables

Variable Description Default
STRANDS_AUTO_INSTALL_TOOLS Enable automatic package installation false
STRANDS_PACKAGE_INSTALLER Package installer (pip or uv) pip
STRANDS_INSTALL_TIMEOUT Installation timeout (seconds) 300
STRANDS_DISABLE_LOAD_TOOL Disable dynamic tool loading false
STRANDS_TOOLS_CACHE_DIR Cache directory for fetched tools temp dir

Usage Examples

from strands import Agent
from strands_tools import manage_tools

agent = Agent(tools=[manage_tools])

# List registered tools
agent.tool.manage_tools(action="list")

# Add a tool from a package
agent.tool.manage_tools(action="add", tools="strands_tools.calculator")

# Add with auto-installation
agent.tool.manage_tools(action="add", tools="strands_mlx.dataset_splitter", install=True)

# Discover available tools in a module
agent.tool.manage_tools(action="discover", tools="strands_tools", verbose=True)

# Create a custom tool at runtime
agent.tool.manage_tools(
    action="create",
    code='''
    from strands import tool

    @tool
    def multiply(a: int, b: int) -> int:
        """Multiply two integers."""
        return a * b
    '''
)

# Fetch from GitHub
agent.tool.manage_tools(
    action="fetch",
    url="https://github.com/user/repo/blob/main/my_tool.py"
)

# Sandbox test code before loading
agent.tool.manage_tools(action="sandbox", code="from strands import tool\n...")

# Remove tools
agent.tool.manage_tools(action="remove", tools="calculator")

# Hot-reload tools
agent.tool.manage_tools(action="reload", tools="shell")

Testing

  • Comprehensive test suite with high coverage
  • Tests cover all actions, helper functions, and edge cases
  • Sandbox testing validation
  • Package installation mocking

Checklist

  • Code follows project style guidelines
  • Tests pass locally
  • Documentation included in docstrings
  • No breaking changes

Add manage_tools tool for dynamic tool management at runtime without restarts.

Features:
- list: Display all currently registered tools
- add: Load tools from packages, files, URLs, or GitHub
- remove: Unregister tools by name
- reload: Hot-reload tools to pick up code changes
- create: Generate new tools from Python code on-the-fly
- fetch: Download and load tools from remote URLs
- discover: List all available tools in a module with introspection
- sandbox: Validate code in isolated subprocess before loading

Key highlights:
- Package manager for AI agent tools
- Auto-installation of missing PyPI packages via pip or uv
- Sandbox testing validates code before loading into agent
- GitHub blob URL auto-conversion to raw URLs
- Configurable via environment variables:
  - STRANDS_AUTO_INSTALL_TOOLS: Enable automatic package installation
  - STRANDS_PACKAGE_INSTALLER: Choose pip or uv
  - STRANDS_INSTALL_TIMEOUT: Package installation timeout
  - STRANDS_DISABLE_LOAD_TOOL: Disable dynamic tool loading
  - STRANDS_TOOLS_CACHE_DIR: Cache directory for fetched tools
- Comprehensive test coverage
Use repr() to properly escape file paths on Windows, preventing
unicode escape sequence errors when paths contain backslashes
like C:\Users\... where \U is interpreted as \UXXXXXXXX.
return cache_dir


def _fetch_from_url(url: str) -> str:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we had some secruity issues related to url, we need to restrict urls, do validations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

network limitations should be applied on runtime level, not on tool to be secure. for example, shell tool have unrestricted access to shell but OS layer determine that operation is successful or not, same applies for this tool

@mkmeral
Copy link
Copy Markdown
Contributor

mkmeral commented Mar 19, 2026

/strands review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants