Skip to content

[BUG] Unable to directly invoke tools with a hyphen with the tool name #139

Closed
@zastrowm

Description

@zastrowm

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.2

Python Version

3.12

Operating System

macos

Installation Method

pip

Steps to Reproduce

Add a tool with a hyphen in the name

from strands import Agent, tool

@tool(name="example-tool")
def example_tool():
    return "done"

agent = Agent(
    tools=[example_tool],
    model=ollama_model,
)
agent.tool.example_tool() # doesn't work to call the function
agent.tool.example-tool() # not valid syntax

Notice that there's no way to directly invoke that tool

Expected Behavior

There should be a way to invoke a tool with a hyphen in the name

Actual Behavior

There is no way

Additional Context

No response

Possible Solution

Allow subscripting of any name by implementing __getitem__ for looking up tools. That would enable this format:

agent.tool["example-tool"]() 

Alternatively, we could normalize the name of tools with dashes to underscores:

agent.tool.example_tool() 

The only downside there would be if there are two tools with similar names, but that's probably rare enough to not be a significant issue.

Related Issues

#54

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions