Mintplex-Labs / anything-llm

The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, and more.
https://anythingllm.com
MIT License
24.37k stars 2.44k forks source link

[BUG]: Agent can't find active connection to PostgreSQL database #2228

Closed sprathod369 closed 1 month ago

sprathod369 commented 1 month ago

How are you running AnythingLLM?

Docker (local)

What happened?

This is a very interesting tool and project, especially the agent functionality. I've setup AnythingLLM using docker compose and running the latest available AnythingLLM version 1.2.1 (not sure why the documentation site says v1.6.4 is live but I cannot find this docker image tag) I also have Ollama docker setup on the same machine and llama3.1:8b-instruct-q8_0 model running successfully.

After setting up a SQL Connector (PostgreSQL) the agent is unaware of this active connection to the database. The connection is named “mydatabase”. The details provided and configured to the SQL agent is fine as I am able to connect to the same postgresql database using VS. Code. The PostgreSQL database is running as a docker container on another VM.

If I ask the agent for the list of the tables of the database, it just hallucinates or mentions below response . It’s seems agent is not coming into play nor are any tools invoked looking at the logs.

Prompt @agent Using mydatabase give me the names of any 5 tables from dtrack database Agent @agent invoked. Swapping over to agent chat. Type /exit to exit agent execution loop early.

Response To access the database, I’ll need to use some tools. It seems like you want me to interact with a database named dtrack. However, I don’t have direct access to your local database. But if you’d like, we can simulate this using a text-based interface…….

The following are the logs from AnythingLLM :

[backend] info: [TELEMETRY SENT] {"event":"sent_chat","distinctId":"e8da662b-8ee7-42b2-b469-85077ee8c2c0","properties"{"multiUserMode":true,"LLMSelection":"ollama","Embedder":"native","VectorDbSelection":"lancedb","multiModal":false,"TTSSelcton":"native","runtime":"docker"}}
[backend] info: [Event Logged] - sent_chat
[backend] info: [AgentHandler] Start 4d54846d-4bb1-44c3-829f-47f25202630f::ollama:llama3.1:8b-instruct-q8_0
[backend] info: [TELEMETRY SENT] {"event":"agent_chat_started","distinctId":"e8da662b-8ee7-42b2-b46985077ee8c2c0","properties":{"runtime":"docker"}}
[backend] info: [AgentHandler] Attached websocket plugin to Agent cluster
[backend] info: [AgentHandler] Attached chat-history plugin to Agent cluster
[backend] info: [AgentHandler] Attaching user and default agent to Agent cluster.
[backend] info: [AgentHandler] Attached rag-memory plugin to Agent cluster
[backend] info: [AgentHandler] Attached document-summarizer plugin to Agent cluster
[backend] info: [AgentHandler] Attached web-scraping plugin to Agent cluster
[backend] info: [AgentHandler] Attached save-file-to-browser plugin to Agent cluster
[backend] info: [AgentHandler] Attached create-chart plugin to Agent cluster
[backend] info: [AgentHandler] Attached web-browsing plugin to Agent cluster
[backend] info: [AgentHandler] Attached sql-agent:sql-list-databases plugin to Agent cluster
[backend] info: [AgentHandler] Attached sql-agent:sql-list-tables plugin to Agent cluster
[backend] info: [AgentHandler] Attached sql-agent:sql-get-table-schema plugin to Agent cluster
[backend] info: [AgentHandler] Attached sql-agent:sql-query plugin to Agent cluster
[backend] info: [AgentLLM - llama3.1:8b-instruct-q8_0] Invalid function tool call: Missing name or arguments in function call..
[backend] info: [AgentLLM - llama3.1:8b-instruct-q8_0] Will assume chat completion without tool call inputs.

Any inputs / suggestions will be appreciated.

Are there known steps to reproduce?

No response

timothycarambat commented 1 month ago

I've setup AnythingLLM using docker compose and running the latest available AnythingLLM version 1.2.1 (not sure why the documentation site says v1.6.4 is live but I cannot find this docker image tag)

v1.6.4 is for desktop - the Docker version is 1.2.1 currently.

After setting up a SQL Connector (PostgreSQL) the agent is unaware of this active connection to the database. The connection is named “mydatabase”. The details provided and configured to the SQL agent is fine as I am able to connect to the same postgresql database using VS. Code. The PostgreSQL database is running as a docker container on another VM.

The issue here sounds like the connection string is not valid for the PG connection. Since you are communicating docker<>docker the issue might be if you are using localhost as the host in the connection string. However, before looking into that further the main issues seems agent JSON generation.

[backend] info: [AgentLLM - llama3.1:8b-instruct-q8_0] Invalid function tool call: Missing name or arguments in function call.. [backend] info: [AgentLLM - llama3.1:8b-instruct-q8_0] Will assume chat completion without tool call inputs.

This implies the agent "sees" the tool, but cannot form a valid JSON call - we can add some debugging here to more easily tail the issues but the valid JSON response to list-tables looks like

{
"name": "sql-list-tables",
"arguments": {
 "database_id": "mydatabase",
 }
}

Sometimes, with OSS LLM debugging can also be done by clearing the chat window + asking a super direct question to agent.

eg: @agent List all of the tables for the mydatabase db @agent List all connected databases you can access (calls func with no params - will test just connection string)

typically a bad connection issue due to connection string would throw a different answer, but this looks to be just agents not being "smart" enough to detect a valid tool.

Closing for now until a bug is uncovered - seems behavior oriented right now.