Skip to content

[BUG] Class Method with @tool decorator is not getting accepted as Tool #199

Open
@Ponprabhakar-pg

Description

@Ponprabhakar-pg

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.7

Python Version

3.12

Operating System

MACOS 14.7.4

Installation Method

pip

Steps to Reproduce

  1. Define a class and a method inside it.
  2. Decorate the method with @tool.
  3. Instantiate an Agent and pass the decorated method via tools=[self.reasoning_plan_generator].
  4. Trigger the agent with a query.

Example:
`import os
from strands import Agent, tool

from common.aws.strands.utils.models import bedrock_model
from common.aws.strands.flows.procure_scenario_planning.prompts import *

class ProcureScenarioPlanning:

def __init__(self):
    pass

@tool
def reasoning_plan_generator(self, query: str):
    """
    Expert in generating reason and plan for execution
    """
    agent = Agent(
        system_prompt=f"{procure_reasoning_prompt(self.db_schema)}",
        messages=self.messages,
        callback_handler=self.event_loop_handler.record_event,
        model=bedrock_model,
    )
    agent_response = agent(query)
    return str(agent_response)


def start_flow(self, user_query: str):
    self.db_schema = [] #schema data will be provided
    handler_agent = Agent(
        system_prompt=f"You are a intelligent nlp based router agent with logistics procurement knowledge. You will receive query from user, analyse the query if you think its not a hi hello general question pass the user to summary_generator directly, No matter what always call the summary_generator, else pass the query to reasoning_plan_generator, get the reasoning-plan, then pass the generated reasoning-plan to code_generator_executor and finally call the summary_generator.",
        messages=[],
        tools=[self.reasoning_plan_generator],
        model=bedrock_model,
    )

    return handler_agent(user_query)

procure_scenario_planning = ProcureScenarioPlanning()
result = procure_scenario_planning.start_flow("get me a sample shipment?")
print(result)
`

Error:
tool=<<bound method ProcureScenarioPlanning.reasoning_plan_generator of <common.aws.strands.flows.procure_scenario_planning.ProcureScenarioPlanning object at 0x10bb3cf20>>> | unrecognized tool specification

Expected Behavior

The method reasoning_plan_generator decorated with @tool should be accepted and invoked as a valid tool by the Agent.

Actual Behavior

The method reasoning_plan_generator decorated with @tool is not accepted as valid tool and getting the below error.

tool=<<bound method ProcureScenarioPlanning.reasoning_plan_generator of <common.aws.strands.flows.procure_scenario_planning.ProcureScenarioPlanning object at 0x10bb3cf20>>> | unrecognized tool specification

Additional Context

No response

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions