Skip to content

Conversation

@LinPoly
Copy link
Collaborator

@LinPoly LinPoly commented Oct 9, 2025

Summary by CodeRabbit

  • New Features
    • Added a --tool_parser CLI option to select how tool calls are parsed.
    • Integrated tool-call parsing into chat responses, including streaming with stable per-call IDs.
    • Added support for Qwen 3 tool-call format.
  • Improvements
    • More reliable post-processing of tool calls with configurable parsers across server and API paths.
  • Chores
    • Added a dependency to improve partial JSON handling for incremental/streamed outputs.

Description

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@LinPoly LinPoly requested a review from JunyiXu-nv October 9, 2025 06:28
@LinPoly LinPoly self-assigned this Oct 9, 2025
@LinPoly LinPoly added the OpenAI API trtllm-serve's OpenAI-compatible API: endpoint behavior, req/resp formats, feature parity. label Oct 9, 2025
@LinPoly LinPoly requested a review from a team as a code owner October 9, 2025 06:28
@LinPoly LinPoly requested a review from pcastonguay October 9, 2025 06:28
@LinPoly LinPoly marked this pull request as draft October 9, 2025 06:30
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

📝 Walkthrough

Walkthrough

Adds a pluggable tool parsing capability. Introduces a tool parser framework, a Qwen3 parser, and utilities. Wires a new tool_parser option through CLI, LLM args, server, and post-processing to detect and stream tool calls. Adds helper for tool call IDs and a dependency for partial JSON parsing.

Changes

Cohort / File(s) Summary of changes
Dependencies
requirements.txt
Adds partial_json_parser dependency.
CLI and Serve Wiring
tensorrt_llm/commands/serve.py
Adds --tool_parser click option; imports ToolParserFactory; extends get_llm_args and serve to accept and pass tool_parser.
LLM Args Schema
tensorrt_llm/llmapi/llm_args.py
Adds tool_parser: Optional[str] to BaseLlmArgs.
OpenAI Server Propagation
tensorrt_llm/serve/openai_server.py
Sets postproc_args.tool_parser from self.llm.args.tool_parser.
Chat Utilities
tensorrt_llm/serve/chat_utils.py
Adds `make_tool_call_id(id_type="random"
Post-processing Integration
tensorrt_llm/serve/postprocess_handlers.py
Integrates tool parser into chat post-processing (streaming and non-streaming). Adds tool_parser, tool_parser_dict to ChatPostprocArgs. Introduces apply_tool_parser(...). Switches to DeltaToolCall/DeltaFunctionCall. Handles tool call ID assignment and conditional inclusion. Imports new tool parser types and helper.
Tool Parser Public API
tensorrt_llm/serve/tool_parser/__init__.py
Re-exports ToolParserFactory via __all__.
Tool Parser Core Types
tensorrt_llm/serve/tool_parser/core_types.py
Adds ToolCallItem, StreamingParseResult, StructureInfo, _GetInfoFunc.
Tool Parser Base
tensorrt_llm/serve/tool_parser/base_tool_parser.py
Adds BaseToolParser abstract class with streaming state, JSON parsing helpers, incremental parsing, and structure info hooks.
Qwen3 Tool Parser
tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py
Adds Qwen3ToolParser implementing detection, one-shot and streaming parsing for <tool_call>...</tool_call> blocks; provides structure info.
Tool Parser Factory
tensorrt_llm/serve/tool_parser/tool_parser_factory.py
Adds ToolParserFactory with parsers registry and create_tool_parser(...); registers qwen3.
Tool Parser Utilities
tensorrt_llm/serve/tool_parser/utils.py
Adds find_common_prefix, partial_json_loads (using partial_json_parser), and is_complete_json.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User (CLI)
  participant S as Serve CLI
  participant L as LLM Args
  participant O as OpenAI Server
  participant P as Postprocessor
  participant F as ToolParserFactory
  participant T as Tool Parser

  U->>S: serve ... --tool_parser qwen3
  S->>L: get_llm_args(..., tool_parser)
  L-->>S: llm_args{..., tool_parser}
  S->>O: start server with llm.args.tool_parser
  O->>P: build ChatPostprocArgs(tool_parser)
  P->>F: create_tool_parser(tool_parser)
  F-->>P: parser instance (e.g., Qwen3ToolParser)
  O->>P: post-process model output (stream/non-stream)
  P->>T: detect_and_parse / parse_streaming_increment
  T-->>P: StreamingParseResult(text, tool_calls[])
  P-->>O: messages with tool_calls (IDs via make_tool_call_id)
  O-->>U: OpenAI-compatible response/stream
Loading
sequenceDiagram
  autonumber
  participant M as Model Stream
  participant P as Postprocessor
  participant T as Tool Parser
  participant ID as make_tool_call_id

  loop token chunks
    M-->>P: new_text
    P->>T: parse_streaming_increment(new_text, tools)
    T-->>P: {normal_text, calls[]}
    alt first chunk for a call
      P->>ID: generate ID (type=random|kimi_k2)
      ID-->>P: tool_call_id
      P-->>M: Delta with tool name + id
    else subsequent arg chunks
      P-->>M: Delta with arguments (id omitted)
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.43% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description Check ⚠️ Warning The pull request description is empty aside from the template placeholders and lacks a filled title, Summary, Description, Test Coverage, and checklist details as required by the repository’s PR template. None of the template sections have been completed with actual information about the changes, tests, or reviewer guidance. This makes it impossible for reviewers to understand the purpose, scope, or testing of the PR. Please complete the PR template by providing a properly formatted title following the ticket and type conventions, a concise summary of the change in the Description section, the relevant test cases in Test Coverage, and update the PR Checklist to confirm guidelines are met.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title follows the repository’s template and concisely summarizes the primary change of adding support for the Qwen3 tool parser, including a valid JIRA ticket reference and type tag.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (5)
requirements.txt (1)

78-78: Pin partial_json_parser via constraints.

Please add partial_json_parser to constraints.txt (e.g., partial_json_parser==0.2.1.1.post6) so installs stay reproducible and immune to upstream releases drifting under us. Based on learnings.

tensorrt_llm/serve/tool_parser/tool_parser_factory.py (1)

8-10: Annotate mutable class attribute with ClassVar.

The parsers dictionary is a class-level attribute that should be annotated with typing.ClassVar to clearly indicate it's not an instance attribute.

Apply this diff:

+from typing import ClassVar, Type
-from typing import Type

 from .base_tool_parser import BaseToolParser
 from .qwen3_tool_parser import Qwen3ToolParser


 class ToolParserFactory:
-    parsers: dict[str, Type[BaseToolParser]] = {
+    parsers: ClassVar[dict[str, Type[BaseToolParser]]] = {
         "qwen3": Qwen3ToolParser,
     }
tensorrt_llm/serve/tool_parser/core_types.py (1)

29-34: Consider using a comment-style docstring for type aliases.

The triple-quoted string after the type alias is not a standard Python docstring location. For type aliases, documentation is typically provided as a comment above the definition.

Apply this diff:

-"""
-Helper alias of function
-Usually it is a function that takes a name string and returns a StructureInfo object,
-which can be used to construct a structural_tag object
-"""
-_GetInfoFunc = Callable[[str], StructureInfo]
+# Helper alias for a function that takes a name string and returns a StructureInfo object,
+# which can be used to construct a structural_tag object
+_GetInfoFunc = Callable[[str], StructureInfo]
tensorrt_llm/serve/postprocess_handlers.py (1)

218-246: Emit type="function" on first tool_call chunk

Add type only when id is present (first chunk) to align with OpenAI stream deltas.

-                    tool_calls.append(
-                        DeltaToolCall(
-                            id=tool_call_id,
-                            index=call_item.tool_index,
-                            function=DeltaFunctionCall(
-                                name=function_name,
-                                arguments=call_item.parameters,
-                            ),
-                        ))
+                    tool_calls.append(
+                        DeltaToolCall(
+                            id=tool_call_id,
+                            type="function" if tool_call_id else None,
+                            index=call_item.tool_index,
+                            function=DeltaFunctionCall(
+                                name=function_name,
+                                arguments=call_item.parameters,
+                            ),
+                        ))
tensorrt_llm/serve/tool_parser/base_tool_parser.py (1)

297-299: Avoid broad except Exception

Limit to known parse errors to prevent swallowing bugs; log and re-raise otherwise.

-        except Exception as e:
+        except (MalformedJSON, json.JSONDecodeError, TypeError, ValueError, KeyError) as e:
             logger.error(f"Error in parse_streaming_increment: {e}")
             return StreamingParseResult()
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27677a3 and 1dc11ee.

📒 Files selected for processing (12)
  • requirements.txt (1 hunks)
  • tensorrt_llm/commands/serve.py (6 hunks)
  • tensorrt_llm/llmapi/llm_args.py (1 hunks)
  • tensorrt_llm/serve/chat_utils.py (2 hunks)
  • tensorrt_llm/serve/openai_server.py (1 hunks)
  • tensorrt_llm/serve/postprocess_handlers.py (6 hunks)
  • tensorrt_llm/serve/tool_parser/__init__.py (1 hunks)
  • tensorrt_llm/serve/tool_parser/base_tool_parser.py (1 hunks)
  • tensorrt_llm/serve/tool_parser/core_types.py (1 hunks)
  • tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py (1 hunks)
  • tensorrt_llm/serve/tool_parser/tool_parser_factory.py (1 hunks)
  • tensorrt_llm/serve/tool_parser/utils.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Use only spaces, no tabs; indent with 4 spaces.

Files:

  • tensorrt_llm/serve/chat_utils.py
  • tensorrt_llm/serve/openai_server.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/serve/tool_parser/__init__.py
  • tensorrt_llm/serve/tool_parser/utils.py
  • tensorrt_llm/serve/tool_parser/tool_parser_factory.py
  • tensorrt_llm/serve/tool_parser/core_types.py
  • tensorrt_llm/serve/postprocess_handlers.py
  • tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/serve/tool_parser/base_tool_parser.py
**/*.py

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.

Files:

  • tensorrt_llm/serve/chat_utils.py
  • tensorrt_llm/serve/openai_server.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/serve/tool_parser/__init__.py
  • tensorrt_llm/serve/tool_parser/utils.py
  • tensorrt_llm/serve/tool_parser/tool_parser_factory.py
  • tensorrt_llm/serve/tool_parser/core_types.py
  • tensorrt_llm/serve/postprocess_handlers.py
  • tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/serve/tool_parser/base_tool_parser.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}

📄 CodeRabbit inference engine (CODING_GUIDELINES.md)

Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).

Files:

  • tensorrt_llm/serve/chat_utils.py
  • tensorrt_llm/serve/openai_server.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/serve/tool_parser/__init__.py
  • tensorrt_llm/serve/tool_parser/utils.py
  • tensorrt_llm/serve/tool_parser/tool_parser_factory.py
  • tensorrt_llm/serve/tool_parser/core_types.py
  • tensorrt_llm/serve/postprocess_handlers.py
  • tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py
  • tensorrt_llm/commands/serve.py
  • tensorrt_llm/serve/tool_parser/base_tool_parser.py
🧬 Code graph analysis (7)
tensorrt_llm/llmapi/llm_args.py (1)
tensorrt_llm/builder.py (1)
  • default (50-58)
tensorrt_llm/serve/tool_parser/__init__.py (1)
tensorrt_llm/serve/tool_parser/tool_parser_factory.py (1)
  • ToolParserFactory (7-21)
tensorrt_llm/serve/tool_parser/tool_parser_factory.py (2)
tensorrt_llm/serve/tool_parser/base_tool_parser.py (1)
  • BaseToolParser (16-351)
tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py (1)
  • Qwen3ToolParser (13-114)
tensorrt_llm/serve/postprocess_handlers.py (6)
tensorrt_llm/serve/chat_utils.py (1)
  • make_tool_call_id (209-214)
tensorrt_llm/serve/openai_protocol.py (9)
  • CompletionStreamResponse (169-175)
  • DeltaFunctionCall (341-343)
  • DeltaMessage (445-451)
  • DeltaToolCall (353-357)
  • FunctionCall (336-338)
  • ToolCall (346-350)
  • UsageInfo (71-74)
  • to_disaggregated_params (923-933)
  • ChatMessage (360-365)
tensorrt_llm/serve/tool_parser/base_tool_parser.py (3)
  • BaseToolParser (16-351)
  • detect_and_parse (89-96)
  • parse_streaming_increment (111-299)
tensorrt_llm/serve/tool_parser/core_types.py (1)
  • ToolCallItem (7-12)
tensorrt_llm/serve/tool_parser/tool_parser_factory.py (2)
  • ToolParserFactory (7-21)
  • create_tool_parser (13-21)
tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py (2)
  • detect_and_parse (43-70)
  • parse_streaming_increment (72-107)
tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py (2)
tensorrt_llm/serve/openai_protocol.py (1)
  • ChatCompletionToolsParam (478-480)
tensorrt_llm/serve/tool_parser/base_tool_parser.py (7)
  • BaseToolParser (16-351)
  • has_tool_call (302-306)
  • detect_and_parse (89-96)
  • parse_base_json (62-86)
  • parse_streaming_increment (111-299)
  • _ends_with_partial_token (98-109)
  • structure_info (313-324)
tensorrt_llm/commands/serve.py (1)
tensorrt_llm/serve/tool_parser/tool_parser_factory.py (1)
  • ToolParserFactory (7-21)
tensorrt_llm/serve/tool_parser/base_tool_parser.py (5)
tensorrt_llm/serve/openai_protocol.py (1)
  • ChatCompletionToolsParam (478-480)
tensorrt_llm/serve/tool_parser/core_types.py (2)
  • StreamingParseResult (15-19)
  • ToolCallItem (7-12)
tensorrt_llm/serve/tool_parser/utils.py (3)
  • find_common_prefix (10-18)
  • is_complete_json (50-55)
  • partial_json_loads (21-47)
tensorrt_llm/logger.py (2)
  • warning (132-133)
  • error (126-127)
tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py (4)
  • detect_and_parse (43-70)
  • parse_streaming_increment (72-107)
  • has_tool_call (39-41)
  • structure_info (109-114)
🪛 Ruff (0.13.3)
tensorrt_llm/serve/chat_utils.py

214-214: Use explicit conversion flag

Replace with conversion flag

(RUF010)

tensorrt_llm/serve/tool_parser/utils.py

53-53: Consider moving this statement to an else block

(TRY300)

tensorrt_llm/serve/tool_parser/tool_parser_factory.py

8-10: Mutable class attributes should be annotated with typing.ClassVar

(RUF012)


18-21: Avoid specifying long messages outside the exception class

(TRY003)

tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py

34-34: Possible hardcoded password assigned to: "bot_token"

(S105)


35-35: Possible hardcoded password assigned to: "eot_token"

(S105)


67-67: Use explicit conversion flag

Replace with conversion flag

(RUF010)

tensorrt_llm/serve/tool_parser/base_tool_parser.py

295-295: Consider moving this statement to an else block

(TRY300)


297-297: Do not catch blind exception: Exception

(BLE001)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
🔇 Additional comments (18)
tensorrt_llm/serve/tool_parser/__init__.py (1)

1-3: LGTM!

The public API re-export is clean and follows standard Python module patterns.

tensorrt_llm/llmapi/llm_args.py (1)

1475-1478: LGTM!

The new tool_parser field is properly defined with appropriate type hints, default value, and documentation. It follows the same pattern as the existing reasoning_parser field above it.

tensorrt_llm/serve/openai_server.py (1)

458-458: LGTM!

The assignment correctly propagates the tool_parser configuration to post-processing arguments, following the same pattern as the reasoning_parser on line 457.

tensorrt_llm/serve/tool_parser/tool_parser_factory.py (1)

13-21: LGTM!

The factory method correctly implements the factory pattern with proper error handling. The error message includes helpful information about supported parsers, which aids debugging.

tensorrt_llm/serve/tool_parser/utils.py (3)

10-18: LGTM!

The find_common_prefix function is straightforward and correct. The implementation is clear and handles edge cases properly.


21-47: LGTM!

The partial_json_loads function is well-documented and handles partial JSON parsing robustly. The error recovery logic for "Extra data" and "pop from empty list" messages adds resilience for streaming scenarios.


50-55: LGTM!

The is_complete_json function correctly validates JSON completeness. The try/except pattern is idiomatic Python despite the static analysis suggestion to use an else block.

tensorrt_llm/serve/tool_parser/core_types.py (2)

7-19: LGTM!

The ToolCallItem and StreamingParseResult Pydantic models are well-defined with proper type hints, default values, and docstrings. They follow Pydantic v2 patterns correctly.


22-26: LGTM!

The StructureInfo dataclass is clean and appropriate for a simple data container.

tensorrt_llm/serve/tool_parser/qwen3_tool_parser.py (4)

13-41: LGTM!

The class initialization and basic methods are well-implemented. The docstring clearly explains the format structure with references to the source model.


43-70: LGTM!

The detect_and_parse method correctly uses regex to extract tool call blocks and handles JSON parsing errors gracefully by logging warnings and continuing to process remaining calls.


72-107: LGTM!

The streaming parser correctly handles partial end tokens through buffering. The logic is well-commented and handles edge cases where the end token arrives character by character.


109-114: LGTM!

The structure_info method returns appropriate metadata for constrained generation with correct begin/end patterns and trigger token.

tensorrt_llm/serve/postprocess_handlers.py (2)

127-148: apply_tool_parser integration looks good

Parser lifecycle per-output with factory + streaming vs non-streaming split is clean.


310-319: Non-streaming tool_calls mapping LGTM

Converts parsed calls into ToolCall(FunctionCall) as expected; ignores tool_index appropriately.

tensorrt_llm/commands/serve.py (2)

328-333: CLI and arg propagation for tool_parser look correct

  • click.Choice over available parsers
  • Signature and get_llm_args propagation are consistent.

Also applies to: 359-386


32-32: No change needed for ToolParserFactory import: It’s re-exported in tensorrt_llm/serve/tool_parser/__init__.py, so the current import is valid.

Likely an incorrect or invalid review comment.

tensorrt_llm/serve/tool_parser/base_tool_parser.py (1)

152-170: Flag selection is sensible

Using Allow.ALL until name is sent, then disallow STR to stabilize name parse is reasonable.

@LinPoly LinPoly force-pushed the pengyunl/qwen3_tool_calling branch from 1dc11ee to 39c06e8 Compare October 10, 2025 07:51
@LinPoly LinPoly marked this pull request as ready for review October 11, 2025 12:46
@LinPoly LinPoly requested review from syuoni and removed request for pcastonguay October 13, 2025 04:01
Copy link
Collaborator

@JunyiXu-nv JunyiXu-nv left a comment

Choose a reason for hiding this comment

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

LGTM

@LinPoly LinPoly force-pushed the pengyunl/qwen3_tool_calling branch from 8001ac2 to 26d83cc Compare October 20, 2025 13:45
@LinPoly LinPoly requested a review from a team as a code owner October 20, 2025 13:45
@LinPoly LinPoly force-pushed the pengyunl/qwen3_tool_calling branch from 26d83cc to 98cda6a Compare October 21, 2025 08:22
@LinPoly
Copy link
Collaborator Author

LinPoly commented Oct 21, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22038 [ run ] triggered by Bot. Commit: 4436904

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22038 [ run ] completed with state FAILURE. Commit: 4436904
/LLM/main/L0_MergeRequest_PR pipeline #16616 completed with status: 'FAILURE'

@LinPoly
Copy link
Collaborator Author

LinPoly commented Oct 21, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22058 [ run ] triggered by Bot. Commit: 50797a9

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22058 [ run ] completed with state FAILURE. Commit: 50797a9
/LLM/main/L0_MergeRequest_PR pipeline #16632 completed with status: 'FAILURE'

@LinPoly
Copy link
Collaborator Author

LinPoly commented Oct 21, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22062 [ run ] triggered by Bot. Commit: 50797a9

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22062 [ run ] completed with state FAILURE. Commit: 50797a9
/LLM/main/L0_MergeRequest_PR pipeline #16635 completed with status: 'FAILURE'

@LinPoly
Copy link
Collaborator Author

LinPoly commented Oct 22, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22147 [ run ] triggered by Bot. Commit: 50797a9

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22147 [ run ] completed with state FAILURE. Commit: 50797a9
/LLM/main/L0_MergeRequest_PR pipeline #16700 completed with status: 'FAILURE'

@LinPoly LinPoly force-pushed the pengyunl/qwen3_tool_calling branch from 50797a9 to e198eb1 Compare October 22, 2025 08:07
@LinPoly
Copy link
Collaborator Author

LinPoly commented Oct 22, 2025

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22160 [ run ] triggered by Bot. Commit: e198eb1

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22160 [ run ] completed with state SUCCESS. Commit: e198eb1
/LLM/main/L0_MergeRequest_PR pipeline #16709 completed with status: 'FAILURE'

Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
.
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
@LinPoly LinPoly force-pushed the pengyunl/qwen3_tool_calling branch from e198eb1 to 64196e9 Compare October 28, 2025 08:37
@LinPoly
Copy link
Collaborator Author

LinPoly commented Oct 28, 2025

/bot run

@LinPoly LinPoly removed the request for review from a team October 28, 2025 08:42
@tensorrt-cicd
Copy link
Collaborator

PR_Github #22751 [ run ] triggered by Bot. Commit: 64196e9

@tensorrt-cicd
Copy link
Collaborator

PR_Github #22751 [ run ] completed with state SUCCESS. Commit: 64196e9
/LLM/main/L0_MergeRequest_PR pipeline #17155 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

Copy link
Collaborator

@juney-nvidia juney-nvidia left a comment

Choose a reason for hiding this comment

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

On behalf of the review about OSS compliance.

@LinPoly LinPoly merged commit 2aade46 into NVIDIA:main Oct 29, 2025
5 checks passed
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 1, 2025
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Nov 3, 2025
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
fredricz-20070104 pushed a commit to fredricz-20070104/TensorRT-LLM that referenced this pull request Nov 5, 2025
Signed-off-by: Pengyun Lin <81065165+LinPoly@users.noreply.github.com>
Signed-off-by: FredricZ-2007 <226039983+fredricz-20070104@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OpenAI API trtllm-serve's OpenAI-compatible API: endpoint behavior, req/resp formats, feature parity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants