DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(llm): keep an explicit strict setting when converting tools for the Responses API
mayuriphadb41968ef972d
diff --git a/deeptutor/services/llm/provider_core/openai_responses/converters.py b/deeptutor/services/llm/provider_core/openai_responses/converters.pyindex e663127ed..418184973 100644--- a/deeptutor/services/llm/provider_core/openai_responses/converters.py+++ b/deeptutor/services/llm/provider_core/openai_responses/converters.py@@ -123,14 +123,18 @@ def convert_tools(converted.append({"type": "web_search"})continueparams = fn.get("parameters") or {}- converted.append(- {- "type": "function",- "name": name,- "description": fn.get("description") or "",- "parameters": params if isinstance(params, dict) else {},- }- )+ item: dict[str, Any] = {+ "type": "function",+ "name": name,+ "description": fn.get("description") or "",+ "parameters": params if isinstance(params, dict) else {},+ }+ # Keep an explicit strict choice; leave it out when unset so the+ # provider default applies, as before.+ strict = fn.get("strict")+ if isinstance(strict, bool):+ item["strict"] = strict+ converted.append(item)return converteddiff --git a/tests/services/llm/test_responses_tool_strict.py b/tests/services/llm/test_responses_tool_strict.pynew file mode 100644index 000000000..3dfe6a9a5--- /dev/null+++ b/tests/services/llm/test_responses_tool_strict.py@@ -0,0 +1,50 @@+"""``convert_tools`` keeps an explicit ``strict`` setting on function tools (#1975)."""++from __future__ import annotations++import copy++import pytest++from deeptutor.services.llm.provider_core.openai_responses import convert_tools+++def _tool(**function_fields):+ return {+ "type": "function",+ "function": {+ "name": "demo_search",+ "description": "Search a synthetic demo.",+ "parameters": {+ "type": "object",+ "properties": {"query": {"type": "string"}},+ "required": ["query"],+ "additionalProperties": False,+ },+ **function_fields,+ },+ }++[email protected]("strict", [False, True])+def test_explicit_strict_is_preserved(strict: bool) -> None:+ tool = _tool(strict=strict)+ original = copy.deepcopy(tool)++ converted = convert_tools([tool])[0]++ assert converted["strict"] is strict+ assert converted["parameters"] == original["function"]["parameters"]+ assert tool == original++[email protected]("fields", [{}, {"strict": None}])+def test_unset_strict_is_omitted(fields) -> None:+ assert "strict" not in convert_tools([_tool(**fields)])[0]+++def test_native_web_search_ignores_strict() -> None:+ tool = _tool(strict=True)+ tool["function"]["name"] = "web_search"++ assert convert_tools([tool], native_web_search=True) == [{"type": "web_search"}]