admin管理员组

文章数量:1295332

I'm building a multi-agent workflow using crewAi that consists of two main parts:

  1. SQL Query Generation:
    I have one agent that uses custom SQL tools (based on crewAi) to generate SQL queries. For example, I use tools like these:

    @tool("list_tables")
    def list_tables() -> str:
        """List the available tables in the database"""
        return ListSQLDatabaseTool(db=db).invoke("")
    
    @tool("tables_schema")
    def tables_schema(tables: str) -> str:
        """
        Input: a comma-separated list of tables.
        Output: the schema and sample rows for those tables.
        """
        tool_instance = InfoSQLDatabaseTool(db=db)
        return tool_instance.invoke(tables)
    
    @tool("execute_sql")
    def execute_sql(sql_query: str) -> str:
        """Execute a SQL query against the database and return the result."""
        return QuerySQLDataBaseTool(db=db).invoke(sql_query)
    
    @tool("check_sql")
    def check_sql(sql_query: str) -> str:
        """
        Check the SQL query for common errors before executing it.
        Input: a string containing the SQL query.
        """
        return QuerySQLCheckerTool(db=db, llm=LLM).invoke({"query": sql_query})
    
  2. Data Analysis and Graph Generation:
    I then have a separate Python Code Interpreter Agent to analyze the SQL results and generate graphs. I get the SQL query from the previous agent and do the analysis using python. I instantiate the agent like this:

    coding_agent = Agent(
        role="Python Code Interpreter Agent",
        goal="Run code to achieve a task given by the user",
        backstory="You are an agent that helps users run Python code.",
        allow_code_execution=True,
        llm=LLM,
    )
    

My local MySQL database is running with the connection string:

SQL_LOCALHOST = "mysql+mysqldb://root:[email protected]:3306/analytics_db"

Issues

  1. ModuleNotFoundError:
    When executing code within the Code Interpreter Agent, I encounter the following error:

ModuleNotFoundError: No module named 'MySQLdb'

It appears that the CrewAi Code Interpreter's Docker image does not have the MySQLdb

  1. Database Connection:
    I want the crewAi code interpreter to connect to my local running DB.

Is there a recommended way to install the required MySQLdb module (or mysqlclient) in the Code Interpreter's Docker image? What steps should I take to modify the image or the environment to support this module?

Alternatively, is it better to way to accomplish this task (Analyze DB using user query)

本文标签: pythonCrewAi Code Interpreter Agent to connect to my local MySQL databaseStack Overflow