Skip to content

Conversation

@ajpqs
Copy link

@ajpqs ajpqs commented Dec 2, 2025

Purpose

This PR adds a tool parser for parsing the function calls made by the Gigachat 3 models.
Models can generate only one function call without any text using format:

function call{json} 

Test Plan

This PR also includes tests. Existing tests have not been modified or will be impacted.

Test Result

pytest tests/entrypoints/openai/tool_parsers/test_gigachat3_tool_parser.py 

Output:

========================================================================= test session starts ========================================================================= platform linux -- Python 3.12.3, pytest-9.0.1, pluggy-1.6.0 configfile: pyproject.toml plugins: anyio-4.11.0 collected 9 items tests/entrypoints/openai/tool_parsers/test_gigachat3_tool_parser.py ......... [100%] ========================================================================== 9 passed in 8.28s ========================================================================== 

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.
Signed-off-by: Viacheslav Barinov <viacheslav.teh@gmail.com>
@github-actions
Copy link

github-actions bot commented Dec 2, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

@mergify
Copy link

mergify bot commented Dec 2, 2025

@mergify mergify bot added documentation Improvements or additions to documentation frontend tool-calling labels Dec 2, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new tool parser for Gigachat 3 models, along with corresponding documentation and tests. The implementation for non-streaming tool calls is solid. However, the streaming implementation contains a critical bug in its JSON parsing logic that can lead to state corruption and cause streaming to fail for tool calls with complex arguments. I've provided a detailed comment on this issue. The rest of the changes, including the tests and documentation, look good.

Comment on lines +144 to +150
if cur_args.endswith("}"): # last '}' end of json
try:
candidate = cur_args[:-1].strip()
json.loads(candidate)
cur_args = candidate
except json.JSONDecodeError:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The current logic for parsing streaming tool call arguments is brittle and has a state corruption bug that can cause streaming to fail.

  1. Fragile JSON Detection: The logic attempts to detect a complete JSON object by checking if the string ends with } and then trying to parse the string without this last character. This is not robust and can fail if a string value within the JSON contains a } near the end (e.g., {"key": "value}"}). The except pass then silently ignores parsing failures.
  2. State Corruption: More critically, when the parse is successful, cur_args is reassigned to the truncated candidate string. This modified cur_args is then used to update the streaming state. This corrupts the state because prev_args in the next iteration will not be a prefix of the raw cumulative stream content, causing the cur_args.startswith(prev_args) check to fail and prematurely stop argument streaming.

I'm suggesting removing this block to prevent state corruption. This will ensure streaming does not break, but it may result in the final concatenated argument string having an extra trailing }. This should be addressed, ideally with a more robust streaming JSON parsing approach (e.g., brace-counting).

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +124 to +128
clean_buffer = self.content_buffer.lstrip()
is_prefix = self.trigger_start.startswith(clean_buffer)
starts_with_trigger = clean_buffer.startswith(self.trigger_start)
if is_prefix or starts_with_trigger:
return None

Choose a reason for hiding this comment

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

P1 Badge Streaming leaks tool preamble when role separator is present

The streaming parser only treats a prefix matching trigger_start (function call{) as the start of a tool call, and otherwise flushes buffered text as normal content (lines 124-128). When the model emits the documented function call<|role_sep|>\n{…} prefix (which the non-streaming regex explicitly supports), these deltas do not match trigger_start, so the parser streams function call<|role_sep|> to the client as plain text before the tool call is detected. That produces stray text and breaks tool-call semantics for the common role_sep variant of GigaChat3 outputs during streaming.

Useful? React with 👍 / 👎.

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

Labels

documentation Improvements or additions to documentation frontend tool-calling

1 participant