Closed parthbhandari01 closed 1 week ago
Bump Wondering the same. I have tried but they appear incompatible with CrewAI unlike LangChain tools.
Bump, tried and failed:
from langchain_community.agent_toolkits.sql.base import create_sql_agent
from langchain_community.utilities.sql_database import SQLDatabase
from langchain_openai import ChatOpenAI
from crewai import Agent
from crewai.agent import CrewAgentExecutor
db = SQLDatabase.from_uri("postgresql://localhost:5432/app")
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
langchain_executor = create_sql_agent(llm, db=db, agent_type="openai-tools", verbose=True)
executor = CrewAgentExecutor.from_agent_and_tools(
agent=langchain_executor.agent,
tools=langchain_executor.tools,
verbose=True
)
db_agent = Agent(
role="Database Admin",
goal="Interact with SQL database",
backstory="I am a database admin who can interact with SQL databases to run queries and fetch data",
tools=executor.tools,
agent_executor=executor,
verbose=True,
allow_delegation=True
)
This snippet however doesn't work and goes into a loop, and the agent tries to fix the Action input
[DEBUG]: == Working Agent: Database Admin
[INFO]: == Starting Task: Find total number of active users
> Entering new CrewAgentExecutor chain...
I need to check the available tables in the database to see if there is a table that contains information about the users.
Action:
sql_db_list_tables
Action Input:
""
Thought:
I apologize for the mistake. I should have provided the input as a dictionary. Let's fix that.
Action:
sql_db_list_tables
Action Input:
{}
user_permissions, users
Thought:
There is a table named 'users'. I need to check the schema of this table to see if there is a column that indicates user activity.
Action:
sql_db_schema
Action Input:
{"tables": "users"} <==== this key is wrong, it should be table_names
I encountered an error while trying to use the tool. This was the error: InfoSQLDatabaseTool._run() got an unexpected keyword argument 'tables'.
Tool sql_db_schema accepts these inputs: Input to this tool is a comma-separated list of tables, output is the schema and sample rows for those tables. Be sure that the tables actually exist by calling sql_db_list_tables first! Example Input: table1, table2, table3
According to the expected types on the input here:
When I run langchain_executor.invoke("Find total number of active users")
, it works flawlessly.
What would be the best way to not re-invent the prompts for existing langchain agents, and still use these agents as part of the Crew?
How we can execute the sql query in database which is generated by the llm using agent ????
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
I have a query: can we use the native pre-built LangChain agents along with custom agents created in crewAI?
For e.g., instead of creating Agents and providing them roles, can we use LangChain agents like CSV agents or SQL agents to fetch data and do some tasks?