Skip to content

Use @tool with a member function? #9404

Answered by dosubot bot
rlnasuti asked this question in Q&A
Aug 17, 2023 · 5 comments · 15 replies
Discussion options

You must be logged in to vote

🤖

Hello,

The issue you're encountering is due to the fact that the @tool decorator is not designed to be used with instance methods, which require a self parameter. When you use the @tool decorator on an instance method, the AgentExecutor tries to supply the self parameter, leading to the TypeError you're seeing.

One way to work around this is to use the @staticmethod decorator in conjunction with the @tool decorator. This tells Python that the method does not require access to any instance or class-specific data, allowing it to be called without an instance of the class. Here's an example:

class MyClass:
    @staticmethod
    @tool("my_tool", return_direct=True)
    def my_method(input: str

Replies: 5 comments 15 replies

Comment options

You must be logged in to vote
8 replies
@Paul-Williamson-90
Comment options

@meet1919
Comment options

@Paul-Williamson-90
Comment options

@KshitizHelix
Comment options

@kanwalgupta
Comment options

Answer selected by rlnasuti
Comment options

You must be logged in to vote
4 replies
@meet1919
Comment options

@rd-0015
Comment options

@faizan2sheikh
Comment options

@faizan2sheikh
Comment options

Comment options

You must be logged in to vote
1 reply
@meet1919
Comment options

Comment options

You must be logged in to vote
2 replies
@ahmedmoorsy
Comment options

@itsparser
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet