Skip to content

fix(chat): enable native tool calling for reasoning models via OpenAI-compatible endpoints#528

Merged
pancacake merged 6 commits into
HKUDS:devfrom
wedone:fix/qwen-tool-call
May 27, 2026
Merged

fix(chat): enable native tool calling for reasoning models via OpenAI-compatible endpoints#528
pancacake merged 6 commits into
HKUDS:devfrom
wedone:fix/qwen-tool-call

Conversation

@wedone

@wedone wedone commented May 27, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes tool calling failures with reasoning models (Qwen 3.6 Plus, DeepSeek, etc.) when accessed through OpenAI-compatible endpoints. Resolves UnboundLocalError and enables proper native tool_calls support.

Related Issues

Module(s) Affected

  • agents
  • services

Changes Summary

File Change
deeptutor/agents/chat/agentic_pipeline.py Fix _is_reasoner variable order; add enable_thinking injection for reasoning models; add reasoner protocol note; adjust implicit_think_label logic
deeptutor/services/llm/capabilities.py Add custom binding with supports_tools: True; add dashscope binding with full capabilities

Key Fixes

  1. Variable order fix: Move _is_reasoner = has_thinking_tags(...) before first use
  2. Custom binding capabilities: Enable supports_tools and per-model has_thinking_tags via MODEL_OVERRIDES
  3. DashScope binding: Add official capability declaration
  4. Reasoning model handling: Inject enable_thinking=True for reasoning models when binding lacks thinking_style
  5. Protocol adjustment: Use LABEL_FINISH for reasoning models with native tool calling

Tested

  • Qwen 3.6 Plus via custom OpenAI-compatible binding
  • RAG retrieval (tool calling) works correctly
  • Non-reasoning models (GPT-4o) unaffected via MODEL_OVERRIDES

Checklist

  • I have read and followed the contribution guidelines
  • My code follows the project's coding standards
  • My changes do not introduce any new security vulnerabilities

Commits

  • 6f9af58 fix(chat): disable thinking mode for native tool calling and strip TOOL label when unavailable
  • b6a8183 fix(chat): only disable thinking for reasoning models when native tool calling is active
  • 35ea0b1 fix: enable native tool_calls for reasoning models via custom OpenAI binding
  • 4862185 fix: escape quotes in reasoner protocol note strings
  • 2a0310a fix(chat): fix Qwen 3.6 Plus tool call failures
  • 551b98b fix(capabilities): change custom binding has_thinking_tags to False

wedone added 6 commits May 27, 2026 11:39
…l calling is active

Previous fix unconditionally set enable_thinking=False for all models
when use_native_tools=True. Now gate on has_thinking_tags() so only
reasoning models (e.g. Qwen3.6-Plus matched via "qwen" prefix) get
thinking disabled. Non-reasoning models are unaffected.
…binding

Reasoning models (e.g. Qwen3.6-Plus) accessed through a generic OpenAI-compatible binding lacked the enable_thinking parameter that DashScope sets automatically. Without it the Bailian API defaults to thinking mode but the label protocol confuses the model into writing tool-call JSON inside content instead of using native tool_calls, causing tool_without_calls violations and infinite retries. Changes: Inject enable_thinking True for reasoning models whose binding lacks a thinking_style; Append a system-prompt note telling reasoning models to ignore the label protocol; Use implicit_think_label LABEL_FINISH for reasoning models with native tool calling.
- Move _is_reasoner assignment before first use to fix UnboundLocalError
- Add custom binding capabilities for OpenAI-compatible endpoints
- Enable supports_tools and has_thinking_tags for custom providers

Fixes tool call failures with reasoning models via OpenAI-compatible APIs
Rely on MODEL_OVERRIDES for per-model detection (qwen/deepseek/qwq
prefixes) instead of hardcoding True for all custom endpoints.
Prevents enable_thinking injection and reasoner protocol notes from
being incorrectly applied to non-reasoning models like GPT-4o.
@pancacake pancacake merged commit b2f2002 into HKUDS:dev May 27, 2026
4 of 9 checks passed
@pancacake

Copy link
Copy Markdown
Collaborator

Thanks for your contribution!

pancacake added a commit that referenced this pull request May 27, 2026
Security: lock down the TutorBot tool sandbox (shell exec is opt-in, all
filesystem/shell access confined to the bot workspace) and isolate per-user
resources, closing #518, #517, #516, #515, #514 and #506 (first hardened in
#507).

Bug fixes: chat input disabled after the first turn (#520), KB embedding
failure on long documents (#521 / #509), profile creation under Docker
(#512 / #513), Qwen reasoning models failing native tool calling (#527 / #528),
the GPT-5 init-wizard token parameter (#508), and oversized session-event
truncation (#524).

Features: HTTP/SSE API for multi-turn chat with a specific TutorBot (#511),
multimodal image fallback for vision-capable providers without a capability
entry, safe ZIP knowledge upload, and a /settings/network page with model
fetching (community PRs #522 and #523 reimplemented locally).

Also bumps __version__ to 1.4.1, adds the v1.4.1 release notes, updates the
README Releases section, and ships the Astro + Starlight docs site under site/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@wedone wedone deleted the fix/qwen-tool-call branch June 9, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants