Skip to content

Support Qwen/Hermes inline <tool_call> format when native function calling is unavailable#30

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-create-test-qwen-agent
Draft

Support Qwen/Hermes inline <tool_call> format when native function calling is unavailable#30
Copilot wants to merge 2 commits intomainfrom
copilot/fix-create-test-qwen-agent

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

Qwen models served via vLLM without native OpenAI function-calling support emit tool invocations as <tool_call> XML blocks inside the message content with finish_reason: stop, bypassing the structured tool_calls field entirely. The agent treated these responses as plain text and returned without executing any tools.

Changes

  • src/openai_compat.py — Add extract_tool_calls_from_content(content): parses <tool_call>…</tool_call> blocks out of content, returning extracted ToolCall objects and cleaned content. Handles both "arguments" and "parameters" key variants. OpenAICompatClient.complete() now falls back to this when tool_calls is absent from the response.

  • src/agent_runtime.py — Streaming path (_get_assistant_turn) applies the same fallback after accumulation, and patches the session message with cleaned content + properly-serialized tool calls so conversation history remains consistent on subsequent turns.

# Model response content (instead of structured tool_calls field):
<tool_call>
{"name": "write_file", "arguments": {"path": "./test_cases/TEST_QWEN_AGENT.md", "content": "test ok"}}
</tool_call>

# Now parsed and executed; file is created; content field is cleaned before storing in session history.
  • tests/test_agent_runtime.py — Two new tests: unit test for client.complete() parsing the inline format, and an end-to-end test verifying the file is actually written when the model uses <tool_call> content blocks.

Copilot AI linked an issue Apr 22, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix issue with creating TEST_QWEN_AGENT.md file Support Qwen/Hermes inline <tool_call> format when native function calling is unavailable Apr 22, 2026
Copilot AI requested a review from abdoelsayed2016 April 22, 2026 15:02
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.

nothing created

2 participants