Skip to content

BaseRetrievalTool does not auto-add question parameter when other parameters exist #12

@MicaPerdomo

Description

@MicaPerdomo

Description

The migration runner adds a default question parameter to retrieval tools only when the parameters list is empty:

params = list(_get("parameters") or [])
if not params:
    params.append({"name": "question", ...})

When a retrieval tool defines filter parameters (e.g. genre, language, decade), the question parameter is not added. The Cognitive API then has no way to receive the search query, causing a 500 Internal Server Error at runtime when the model calls the tool.

Steps to reproduce

  1. Define a BaseRetrievalTool with filter parameters but no explicit question parameter:
class MovieSearch(BaseRetrievalTool):
    description = "Search movies."
    retrieval = MovieRetrieval
    parameters = [
        {"name": "genre", "description": "Filter by genre", "type": "string", "required": False},
    ]
  1. Run manage.py migrate agents
  2. Chat with the agent and trigger the retrieval tool → 500 error

Current workaround

Explicitly include a question parameter in the parameters list:

parameters = [
    {"name": "question", "description": "Search query", "type": "string", "required": True},
    {"name": "genre", "description": "Filter by genre", "type": "string", "required": False},
]

Proposed fix

Always ensure a question parameter exists, not just when the list is empty:

params = list(_get("parameters") or [])
if not any(p.get("name") == "question" for p in params):
    params.insert(0, {"name": "question", "description": "Search query", "type": "string", "required": True})

This is backward-compatible — existing tools that already include question are unaffected.

File

cogsol/management/commands/migrate.py, _retrieval_tool_payload (around line 750)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions