[Rust Frontend] Add Python bridge for Rust tool parsers#44624
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
This comment has been minimized.
This comment has been minimized.
55b6c5e to
4e10bc6
Compare
This comment has been minimized.
This comment has been minimized.
|
Please compile with python limited API just like other native extensions. You can try adding something like: I'm not sure whether this works well with vllm's complex packaging scripts. |
|
Hi @BugenZhao, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, |
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
…er macos Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
372045c to
872fd7d
Compare
| except Exception as error: | ||
| self._error = error | ||
| logger.exception( | ||
| "Error parsing %s streaming tool call output.", | ||
| self.rust_parser_name, | ||
| ) | ||
|
|
||
| delta_message = self._delta_message_from_parser_output(parser_output) |
There was a problem hiding this comment.
⚪ Severity: LOW
After the Rust parse_into raises an exception (line 310-316), execution falls through to process the potentially partially-mutated parser_output. Unlike _parse_complete (which correctly returns None inside its except block), here the partial/corrupt parser output is forwarded as a valid tool call delta. This can cause incomplete tool calls (e.g., truncated arguments) to be streamed to downstream tool executors.
Helpful? Add 👍 / 👎
💡 Fix Suggestion
Suggestion: Add return None at the end of the except block (after the logger.exception call) to prevent fall-through to processing the potentially partially-mutated parser_output. This matches the pattern used in _parse_complete (line 226) which correctly returns None inside its except block.
⚠️ Experimental Feature: This code suggestion is automatically generated. Please review carefully.
| except Exception as error: | |
| self._error = error | |
| logger.exception( | |
| "Error parsing %s streaming tool call output.", | |
| self.rust_parser_name, | |
| ) | |
| delta_message = self._delta_message_from_parser_output(parser_output) | |
| except Exception as error: | |
| self._error = error | |
| logger.exception( | |
| "Error parsing %s streaming tool call output.", | |
| self.rust_parser_name, | |
| ) | |
| return None | |
| delta_message = self._delta_message_from_parser_output(parser_output) |
…#44624) Signed-off-by: Bugen Zhao <i@bugenzhao.com>
…#44624) Signed-off-by: Bugen Zhao <i@bugenzhao.com>
…#44624) Signed-off-by: Bugen Zhao <i@bugenzhao.com>
…#44624) Signed-off-by: Bugen Zhao <i@bugenzhao.com> Signed-off-by: divineearthly <divineearthly@gmail.com>
…#44624) Signed-off-by: Bugen Zhao <i@bugenzhao.com>
…#44624) Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Purpose
This PR adds a generic PyO3 bridge that exposes Rust tool parsers to Python through
vllm._rust_tool_parser, along with a PythonRustToolParseradapter for the existing vLLMToolParserinterface.This is not yet wired into any production parser path. The intent is to provide a future extension point where Python adapters can delegate parser state and grammar to Rust while keeping protocol adaptation in Python.
This updates the existing PR for this Rust tool parser bridge work rather than opening a duplicate PR. AI assistance was used.
Tests
Verified locally:
VLLM_RS_TARGET_PATH=/tmp/vllm-rust-artifacts/vllm-rs VLLM_RUST_EXTENSION_TARGET_DIR=/tmp/vllm-rust-artifacts bash build_rust.sh- passed; producedvllm-rsand_rust_tool_parser.abi3.so.vllm._rust_tool_parserusing the built_rust_tool_parser.abi3.so- passed.cargo test --manifest-path rust/Cargo.toml -p vllm-tool-parser-py- passed..venv/bin/pytest -q tests/tool_parsers/test_rust_tool_parser.py- passed.git diff --check- passed.Verified in Buildkite build 70210 before the DCO-only commit-message rewrite:
docker-build-image- passed; log confirmed_rust_tool_parser.abi3.sowas added to the wheel.docker-smoking-non-root-smoke-tests- passed.async-engine-inputs-utils-worker-config-cpureachedtests/tool_parsers/test_rust_tool_parser.py; all four Rust tool parser Python tests passed beforetokenizers_started.