Skip to content

tool calling alignment with openai's spec#4585

Open
lvhan028 wants to merge 10 commits into
InternLM:mainfrom
lvhan028:feat/openai-tool-calling-alignment
Open

tool calling alignment with openai's spec#4585
lvhan028 wants to merge 10 commits into
InternLM:mainfrom
lvhan028:feat/openai-tool-calling-alignment

Conversation

@lvhan028
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings May 13, 2026 10:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates LMDeploy’s OpenAI-compatible tool-calling support to better align with OpenAI’s spec, including request/response schema additions and stricter handling of tool-call parsing and rendering.

Changes:

  • Extend OpenAI protocol models with Function.strict, AllowedToolChoice, parallel_tool_calls, and make DeltaToolCall.id optional.
  • Update response/tool parsing to (a) omit id on argument-only tool-call deltas, (b) optionally truncate/skip parallel tool calls, and (c) surface invalid tool-call payloads as an error message in parse_complete.
  • Update BaseChatTemplate.messages2prompt() to render tool_calls and tool_call_id in prompts; add targeted unit tests for the new behaviors.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_lmdeploy/serve/parsers/test_gpt_oss_parser.py Updates expected dumped tool schema to include strict.
tests/test_lmdeploy/serve/openai/test_protocol_strict.py Adds coverage for Function.strict passthrough and dumping.
tests/test_lmdeploy/serve/openai/test_parallel_tool_calls.py Adds coverage for parallel_tool_calls default and truncation behavior.
tests/test_lmdeploy/serve/openai/test_messages2prompt_tool_calls.py Adds coverage for rendering tool_calls / tool_call_id into prompts.
tests/test_lmdeploy/serve/openai/test_delta_tool_call_id.py Adds coverage that streaming tool-call id only appears on the first chunk.
tests/test_lmdeploy/serve/openai/test_arguments_validation.py Adds coverage for tool-call argument JSON validation/normalization and error surfacing.
tests/test_lmdeploy/serve/openai/test_allowed_tool_choice.py Adds coverage for AllowedToolChoice and tool filtering in dump_tools().
lmdeploy/serve/parsers/tool_parser/tool_parser.py Adjusts JSON incremental tool-call delta emission so arg deltas omit id.
lmdeploy/serve/parsers/tool_parser/qwen3coder_tool_parser.py Tightens argument JSON parsing (raise on invalid JSON) and skips normalization on errors.
lmdeploy/serve/parsers/response_parser.py Adds allowed-tool filtering in dump_tools(), truncation helper, streaming skipping for non-parallel tool calls, and error return on tool parse failure.
lmdeploy/serve/openai/protocol.py Adds protocol fields/models (strict, AllowedToolChoice, parallel_tool_calls) and makes DeltaToolCall.id optional.
lmdeploy/model.py Renders assistant tool_calls and tool tool_call_id in messages2prompt().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lmdeploy/serve/parsers/response_parser.py Outdated
Comment thread lmdeploy/serve/parsers/response_parser.py Outdated
Comment thread lmdeploy/model.py Outdated
lvhan028 and others added 10 commits May 15, 2026 07:43
…bility

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Per the OpenAI streaming spec, the tool call id should appear only on
the name-delta chunk and be None on subsequent argument-delta chunks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…dumps

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…2prompt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lvhan028 lvhan028 force-pushed the feat/openai-tool-calling-alignment branch from 69c476f to 66477eb Compare May 15, 2026 07:44
@lvhan028 lvhan028 requested a review from Copilot May 15, 2026 07:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants