AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend/copilot): address PR review round 2
Zamil Majdy5a3739e54d8f
diff --git a/autogpt_platform/backend/backend/copilot/tools/ask_question.py b/autogpt_platform/backend/backend/copilot/tools/ask_question.pyindex 5171fd84a1..60855ec437 100644--- a/autogpt_platform/backend/backend/copilot/tools/ask_question.py+++ b/autogpt_platform/backend/backend/copilot/tools/ask_question.py@@ -5,11 +5,11 @@ from typing import Anyfrom backend.copilot.model import ChatSession-logger = logging.getLogger(__name__)-from .base import BaseToolfrom .models import ClarificationNeededResponse, ClarifyingQuestion, ToolResponseBase+logger = logging.getLogger(__name__)+class AskQuestionTool(BaseTool):"""Ask the user one or more clarifying questions and wait for answers.@@ -91,11 +91,11 @@ class AskQuestionTool(BaseTool):},"description": ("Ask multiple questions at once. Each item has "- "'question' (required), 'options', and 'keyword'."+ "'question' (required), 'options', and 'keyword'. "+ "Takes precedence over the single 'question' param."),},},- "required": ["question"],}@property@@ -131,7 +131,7 @@ class AskQuestionTool(BaseTool):async def _execute(self,user_id: str | None,- session: ChatSession,+ session: ChatSession | None,**kwargs: Any,) -> ToolResponseBase:del user_id # unused; required by BaseTool contract@@ -157,12 +157,11 @@ class AskQuestionTool(BaseTool):raw_options = kwargs.get("options", [])if not isinstance(raw_options, list):raw_options = []- options: list[str] = [str(o) for o in raw_options if o is not None]raw_keyword = kwargs.get("keyword", "")keyword: str = str(raw_keyword) if raw_keyword else ""- clarifying_question = self._build_question(question, options, keyword)+ clarifying_question = self._build_question(question, raw_options, keyword)return ClarificationNeededResponse(message=question,session_id=session_id,diff --git a/autogpt_platform/backend/backend/copilot/tools/ask_question_test.py b/autogpt_platform/backend/backend/copilot/tools/ask_question_test.pyindex 6467f1cc1b..62134bb881 100644--- a/autogpt_platform/backend/backend/copilot/tools/ask_question_test.py+++ b/autogpt_platform/backend/backend/copilot/tools/ask_question_test.py@@ -292,3 +292,20 @@ async def test_execute_options_with_falsy_values()assert result.questions[0].example == "0, 1, 2"+++async def test_execute_questions_as_non_list_falls_back(+ tool: AskQuestionTool, session: ChatSession+):+ """If 'questions' is a truthy non-list (e.g. a dict), fall back to single path."""+ result = await tool._execute(+ user_id=None,+ session=session,+ question="Fallback?",+ questions={"question": "Not a list"}, # type: ignore[arg-type]+ )++ assert isinstance(result, ClarificationNeededResponse)+ assert len(result.questions) == 1+ assert result.questions[0].question == "Fallback?"