Skip to content

Tool Methods in Python Class Missing self Argument When Used in Custom Agents #29004

Answered by quartermaine
quartermaine asked this question in Q&A
Discussion options

You must be logged in to vote

I managed to find the solution by making each tool a separate class. Below is an example of how I structured the tools:

Tool Classes

Each tool is implemented as a standalone class, with attributes for its name, functionality, and description. This encapsulation provides clarity and modularity.

class ListTablesTool:
    def __init__(self, db_connection):
        self.name = "list_tables"
        self.func = self.list_tables
        self.description = "Lists the available tables in the database"
        self.db_connection = db_connection

    def list_tables(self) -> str:
        """List the available tables in the database"""
        return ListSQLDatabaseTool(db=self.db_connection).invoke…

Replies: 3 comments 10 replies

Comment options

You must be logged in to vote
10 replies
@dosubot
Comment options

@quartermaine
Comment options

@dosubot
Comment options

@quartermaine
Comment options

@dosubot
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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