mindsdb / mindsdb/mindsdb_python_sdk

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

Open
#201 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
44
Forks
16
Avg merge
6h 53m
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in skills.py around SQLSkill.from_json(), then trace the agents.py Agent.from_json() path used by server.agents.list(). Reproduce the issue with an agent whose SQL skill contains include_tables, and verify that listing agents handles the reported skill JSON without raising KeyError: 'tables'.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.