DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(llm): enable native tool calls for all registered cloud OpenAI-compatible providers
Bingxi Zhao (Frank)61f9c667188e
diff --git a/deeptutor/core/agentic/client.py b/deeptutor/core/agentic/client.pyindex 43b73ba07..9339056af 100644--- a/deeptutor/core/agentic/client.py+++ b/deeptutor/core/agentic/client.py@@ -328,10 +328,30 @@ def build_provider_extra_kwargs(def can_use_native_tool_calling(*, binding: str, model: str | None) -> bool:- """Whether the current provider supports OpenAI-style function calling."""- if not supports_tools(binding, model):- return False+ """Whether the current provider supports OpenAI-style function calling.++ Resolution order:++ 1. Anthropic-backed providers always support tool use (native Messages API).+ 2. Local OpenAI-compatible servers (Ollama, vLLM, LM Studio, llama.cpp,+ Lemonade, OVMS, …) and anything in ``_NATIVE_TOOL_BLOCKED_BINDINGS`` are+ opted out — tool support there depends on the loaded model and is+ unreliable, so the loop falls back to prose.+ 3. An explicit ``supports_tools`` capability (provider- or model-level) wins.+ 4. Otherwise a registered *cloud* OpenAI-compatible provider is assumed+ tool-capable — function calling is part of that API contract, matching+ the catch-all ``custom`` provider. This keeps newly added cloud+ providers working without a dedicated capability entry, instead of+ silently disabling native tools (the gap that affected e.g. SiliconFlow,+ Gemini, Zhipu, Qianfan, NVIDIA NIM and the Volc/BytePlus coding plans).+ To opt a cloud provider out, add its binding to+ ``_NATIVE_TOOL_BLOCKED_BINDINGS``.+ """spec = find_by_name(binding)if spec and spec.backend == "anthropic":return True- return binding not in _NATIVE_TOOL_BLOCKED_BINDINGS+ if binding in _NATIVE_TOOL_BLOCKED_BINDINGS or (spec and spec.is_local):+ return False+ if supports_tools(binding, model):+ return True+ return bool(spec and spec.backend == "openai_compat")diff --git a/tests/core/test_agentic_client_provider_kwargs.py b/tests/core/test_agentic_client_provider_kwargs.pyindex 185db3107..62a240860 100644--- a/tests/core/test_agentic_client_provider_kwargs.py+++ b/tests/core/test_agentic_client_provider_kwargs.py@@ -185,6 +185,46 @@ def test_siliconflow_deepseek_can_use_native_tool_calling() -> None:)+def test_registered_cloud_openai_compat_providers_enable_native_tools() -> None:+ # Registered cloud OpenAI-compatible providers are tool-capable by default,+ # even without a dedicated PROVIDER_CAPABILITIES entry — function calling is+ # part of the OpenAI-compatible API contract. Guards against silently+ # disabling native tools when a new cloud provider joins the registry (the+ # gap that affected SiliconFlow before #584).+ for binding in (+ "gemini",+ "zhipu",+ "qianfan",+ "stepfun",+ "xiaomi_mimo",+ "nvidia_nim",+ "aihubmix",+ "volcengine_coding_plan",+ "byteplus_coding_plan",+ ):+ assert can_use_native_tool_calling(binding=binding, model=None) is True, binding+++def test_local_and_oauth_backends_stay_opted_out_of_native_tools() -> None:+ # Local OpenAI-compatible servers (model-dependent, unreliable tool support)+ # and the OAuth CLI backends keep native tool schemas disabled.+ for binding in (+ "ollama",+ "vllm",+ "lm_studio",+ "llama_cpp",+ "lemonade",+ "ovms",+ "openai_codex",+ "github_copilot",+ ):+ assert can_use_native_tool_calling(binding=binding, model=None) is False, binding+++def test_unknown_binding_does_not_enable_native_tools() -> None:+ assert can_use_native_tool_calling(binding="totally-unknown", model=None) is False++@pytest.mark.asyncioasync def test_anthropic_adapter_streams_openai_style_chunks() -> None:captured = {}