fix: place Qwen tools before system prompt#10579
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a helper method _format_system_content to correctly order and format system instructions and tool definitions, specifically ensuring that tools precede system content for the qwen3_5 tool format. A corresponding unit test was also added to verify this behavior. The review feedback suggests improving the robustness of this new method by handling cases where the system argument might be None to prevent potential runtime TypeError during string concatenation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def _format_system_content(self, system: str, tool_text: str) -> str: | ||
| if tool_text and self.format_tools.tool_format == "qwen3_5": | ||
| tool_text = tool_text.lstrip("\n") | ||
| return tool_text + ("\n\n" + system if system else "") | ||
|
|
||
| return system + tool_text |
There was a problem hiding this comment.
To ensure robust defensive programming, _format_system_content should handle cases where system might be None (e.g., if self.default_system is not set or is set to None in custom templates). Accepting Optional[str] and defaulting to an empty string prevents potential runtime TypeError during string concatenation.
| def _format_system_content(self, system: str, tool_text: str) -> str: | |
| if tool_text and self.format_tools.tool_format == "qwen3_5": | |
| tool_text = tool_text.lstrip("\n") | |
| return tool_text + ("\n\n" + system if system else "") | |
| return system + tool_text | |
| def _format_system_content(self, system: Optional[str], tool_text: str) -> str: | |
| system = system or "" | |
| if tool_text and self.format_tools.tool_format == "qwen3_5": | |
| tool_text = tool_text.lstrip("\n") | |
| return tool_text + ("\n\n" + system if system else "") | |
| return system + tool_text |
Summary
Fixes #10491.
To verify