mindsdb_python_sdk icon indicating copy to clipboard operation
mindsdb_python_sdk copied to clipboard

KeyError: 'tables' when listing agents with SQL skills created via CREATE AGENT

Open guglielmo opened this issue 7 months ago • 0 comments

My Environment

  • Python version: 3.12.11
  • Operating system: Linux 6.12.12-061212-generic (Ubuntu-based)
  • Mindsdb Python SDK version: 3.4.4
  • Additional info if applicable: MindsDB Cloud instance, self hosted at mindsdb.openpolis.io

When attempting to list agents using server.agents.list(), the SDK throws a KeyError: 'tables' for agents that have SQL skills created through the SQL interface.

Steps to Reproduce:

  1. Create an agent using SQL with table references:
CREATE AGENT agent_001
USING
    model = {
        "provider": "google",
        "model_name": "gemini-2.0-flash",
        "api_key": "your_api_key"
    },
    data = {
         "tables": ["sales_manager_data.public.prospects_details", "sales_manager_data.public.call_summaries"]
    },
    prompt_template='
        sales_manager_data.public.prospects_details stores prospects data
        sales_manager_data.public.call_summaries stores calls from companies data
    ';
  1. Try to list agents via Python SDK:
import mindsdb_sdk
server = mindsdb_sdk.connect('https://your-instance.com', login='user', password='pass')
agents = server.agents.list()  # This throws KeyError: 'tables'

Error Details:

Traceback (most recent call last):
  File "<string>", line 16, in <module>
  File "/path/to/mindsdb_sdk/agents.py", line 233, in list
    return [Agent.from_json(agent, self) for agent in data]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/mindsdb_sdk/agents.py", line 203, in from_json
    [Skill.from_json(skill) for skill in json['skills']],
     ^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/mindsdb_sdk/skills.py", line 57, in from_json
    return SQLSkill(name, params['tables'], params['database'], params.get('description', ''))
                          ~~~~~~^^^^^^^^^^
KeyError: 'tables'

Root Cause Analysis:

When agents are created via SQL, MindsDB stores the table information in the skill params as include_tables, but the SDK's SQLSkill.from_json() method expects the key to be tables.

Actual skill JSON structure from MindsDB:

{
  "type": "sql",
  "params": {
    "database": null,
    "description": "Auto-generated SQL skill for agent agent_001",
    "include_tables": [
      "sales_manager_data.public.prospects_details", 
      "sales_manager_data.public.call_summaries"
    ],
    "knowledge_base_database": "mindsdb",
    "type": "sql"
  }
}

Expected by SDK (skills.py:57):

return SQLSkill(name, params['tables'], params['database'], params.get('description', ''))

Suggested Fix:

The SQLSkill.from_json() method should handle both tables and include_tables keys:

# In skills.py around line 57
tables = params.get('tables') or params.get('include_tables', [])
return SQLSkill(name, tables, params['database'], params.get('description', ''))

This appears to be a version compatibility issue between how MindsDB server stores agent skills and how the SDK expects to parse them.

guglielmo avatar Jul 13 '25 10:07 guglielmo