Mintplex-Labs / anything-llm

The all-in-one Desktop & Docker AI application with full RAG and AI Agent capabilities.
https://useanything.com
MIT License
17k stars 1.82k forks source link

[BUG]: Agent can't find active connection to MySQL database #1805

Closed CedricGoby closed 4 days ago

CedricGoby commented 4 days ago

How are you running AnythingLLM?

Docker (local)

What happened?

After setting up a SQL Connector (MySQL) the agent answer there is no active connection to the database if I ask for the list of the tables of the database.

I'm using the MistralAI API with mistral-large-2402 model.

This is the logs from AnythingLLM :

[Event Logged] - sent_chat
[AgentHandler] Start 46b3df8f-f99b-4099-b1e6-688241ebfe71::mistral:mistral-large-2402
[TELEMETRY SENT] {
  event: 'agent_chat_started',
  distinctId: 'f322ff19-73c2-47a9-8aa2-32c59ce7d737',
  properties: { runtime: 'docker' }
}
[AgentHandler] Attached websocket plugin to Agent cluster
[AgentHandler] Attached chat-history plugin to Agent cluster
[AgentHandler] Attaching user and default agent to Agent cluster.
[AgentHandler] Attached rag-memory plugin to Agent cluster
[AgentHandler] Attached document-summarizer plugin to Agent cluster
[AgentHandler] Attached web-scraping plugin to Agent cluster
[AgentHandler] Attached sql-agent:sql-list-databases plugin to Agent cluster
[AgentHandler] Attached sql-agent:sql-list-tables plugin to Agent cluster
[AgentHandler] Attached sql-agent:sql-get-table-schema plugin to Agent cluster
[AgentHandler] Attached sql-agent:sql-query plugin to Agent cluster
[AgentLLM - mistral-large-2402] Valid tool call found - running sql-list-tables.
[AgentHandler] [debug]: @agent is attempting to call `sql-list-tables` tool
[AgentHandler] Using the sql-list-tables tool.
[AgentHandler] sql-list-tables failed to find config!. mydatabase
[AgentLLM - mistral-large-2402] Function tool with exact arguments has already been called this stack.
[AgentLLM - mistral-large-2402] Will assume chat completion without tool call inputs.

Are there known steps to reproduce?

# AI Stack
# Licence : GPL-3+ (https://www.gnu.org/licenses/gpl-3.0.txt)
# Auteur : Cédric Goby

services:
  # AnythingLLM
  # https://github.com/Mintplex-Labs/anything-llm/blob/master/docker/HOW_TO_USE_DOCKER.md
  # https://hub.docker.com/r/mintplexlabs/anythingllm/tags
  anything_llm:
    image: mintplexlabs/anythingllm:master
    container_name: anything_llm
    ports:
      - "3001:3001"
    cap_add:
      - SYS_ADMIN
    networks:
      - frontend
    volumes:
      - "$HOME/Documents/DEV/IA/Desktop/anything-llm/persistent:/app/server/storage"
      - "$HOME/Documents/DEV/IA/Desktop/anything-llm/persistent/.env:/app/server/.env"
    environment:
      - STORAGE_DIR=/app/server/storage

  # Chroma
  # https://github.com/chroma-core/chroma/blob/main/docker-compose.yml
  # https://hub.docker.com/r/chromadb/chroma/tags
  chroma:
    image: chromadb/chroma:0.5.1.dev173
    container_name: chroma
    ports:
      - "8000:8000"
    networks:
      - frontend
    volumes:
      - "$HOME/Documents/DEV/IA/Desktop/chroma/persistent:/chroma/chroma"

  # PostgreSQL (pour VectorAdmin)
  # https://github.com/docker-library/docs/blob/master/postgres/README.md
  # https://hub.docker.com/_/postgres/tags
  postgres:
    image: postgres:13.15-bookworm
    container_name: vectoradmin_postgres
    ports:
      - "5432:5432"
    networks:
      - frontend
    volumes:
      - $HOME/Documents/DEV/IA/Desktop/vectoradmin/postgresql/persistent:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: vectoradmin
      POSTGRES_PASSWORD: password
      POSTGRES_DB: vdbms

  # VectorAdmin
  # https://github.com/Mintplex-Labs/vector-admin/blob/master/docker/DOCKER.md
  # https://hub.docker.com/r/mintplexlabs/vectoradmin/tags
  vectoradmin:
    image: mintplexlabs/vectoradmin
    container_name: vectoradmin
    ports:
      - "3002:3002"
    networks:
      - frontend
    volumes:
      - "$HOME/Documents/DEV/IA/Desktop/vectoradmin/persistent/backend/storage:/app/backend/storage"
      #- "$HOME/Documents/DEV/IA/Desktop/vectoradmin/persistent/.env:/app/backend/.env"
      - "$HOME/Documents/DEV/IA/Desktop/vectoradmin/persistent/document-processor/hotdir:/app/document-processor/hotdir"
    environment:
      - SERVER_PORT=3002
      - JWT_SECRET=password
      - INNGEST_EVENT_KEY=background_workers
      - INNGEST_SIGNING_KEY=password
      - INNGEST_LANDING_PAGE=true
      - DATABASE_CONNECTION_STRING=postgresql://vectoradmin:password@postgres:5432/vdbms
      - DISABLE_TELEMETRY="true"
    depends_on:
      - postgres

# MySQL
# https://dev.mysql.com/doc/refman/8.0/en/docker-mysql-more-topics.html
  mysql:
    image: mysql:8.0.33
    container_name: mysql
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
    command: --default-authentication-plugin=caching_sha2_password
    restart: always
    networks:
      - frontend
    volumes:
      - "$HOME/Documents/DEV/IA/Desktop/mysql/persistent/data:/var/lib/mysql"
      - "$HOME/Documents/DEV/IA/Desktop/mysql/persistent/config:/etc/mysql/conf.d"

# SERVICE PHPMYADMIN
# https://github.com/phpmyadmin/docker
  phpmyadmin:
    image: phpmyadmin:5.2.1-apache
    container_name: phpmyadmin
    ports:
      - "8080:80"
    networks:
      - frontend
    environment:
      PMA_ARBITRARY: 1
    restart: always

networks:
  frontend:
    external: true

If you look at the capabilities of the agent you don't see SQL Connector :

Capture d’écran du 2024-07-03 11-21-58

You can verify that the database is reachable from inside the AnythingLLM container with the same database connection settings :

me@my-laptop:~$ docker exec -u root -it anything_llm bash

root@6099cb6fb8d9:/app# apt update
...
root@6099cb6fb8d9:/app# apt install default-mysql-client
...
root@6099cb6fb8d9:/app# mysql -uroot -p -h 172.20.0.5 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 87
Server version: 8.0.33 MySQL Community Server - GPL
...
mysql>

The database is also reachable using phpmyadmin (http://localhost:8080/)

Can someone help me ?

timothycarambat commented 4 days ago

Looks like the tool call is actually working as intended, but the JSON formed back from the model while passing the schema requirement still has a value of {database_id: "mydatabase"}

When you setup the database - what is in this field? If it is not mydatabase the connector alias wont be found and the model is basically hallucinating the database id. We give it the list of all databases but you can more explicit in your prompt to encourage the model to make a valid call.

eg: Using <connector alias> give me xyz

Screenshot 2024-07-03 at 11 57 28 AM

related docs: https://docs.useanything.com/agent-not-using-tools

CedricGoby commented 3 days ago

Thank you very much. Setting "Connection name" to "mydatabase" and be more explicit in the prompt did the trick.