-
Notifications
You must be signed in to change notification settings - Fork 922
Add SeedAgentTemplate #6128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SeedAgentTemplate #6128
Conversation
Summary of ChangesHello @hpsun1109, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this 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 SeedAgentTemplate for a specific model. The implementation is generally well-structured, but there are several areas for improvement regarding code style, consistency, and maintainability. My review includes suggestions to maintain alphabetical ordering for imports and dictionary keys, remove redundant and unused code, address language inconsistencies in the generated prompts, and refactor duplicated logic for better code clarity.
| from .mistral import MistralAgentTemplate | ||
| from .qwen import QwenEnAgentTemplate, QwenEnParallelAgentTemplate, QwenZhAgentTemplate, QwenZhParallelAgentTemplate | ||
| from .qwen3_coder import Qwen3CoderAgentTemplate | ||
| from .seed_oss import SeedAgentTemplate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 'llama4': Llama4AgentTemplate, | ||
| # ref: https://huggingface.co/deepseek-ai/DeepSeek-V3.1 | ||
| 'deepseek_v3_1': DeepSeekV31AgentTemplate, | ||
| 'seed_oss': SeedAgentTemplate, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return SeedAgentTemplate._PY_TYPE_MAPPING.get(t, 'Any') | ||
|
|
||
| def get_toolcall(self, response: str) -> List['Function']: | ||
| from swift.llm.infer import Function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| return f"Function:\ndef {func_name}({param_str}):\n{docstring}" | ||
|
|
||
| def _format_tools(self, tools: List[Union[str, dict]], system: Optional[str] = None, user_message=None) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter user_message is defined but not used within the _format_tools method. It should be removed to clean up the code and avoid confusion.
| def _format_tools(self, tools: List[Union[str, dict]], system: Optional[str] = None, user_message=None) -> str: | |
| def _format_tools(self, tools: List[Union[str, dict]], system: Optional[str] = None) -> str: |
| def _format_tools(self, tools: List[Union[str, dict]], system: Optional[str] = None, user_message=None) -> str: | ||
| if not tools: | ||
| return system or '' | ||
|
|
||
| if system: | ||
| system_prompt = system | ||
| else: | ||
| system_prompt = "You are Doubao, a helpful AI assistant. You may call one or more functions to assist with the user query." | ||
|
|
||
| tool_defs = [ | ||
| self._build_tool_def_string(self.wrap_tool(tool)) | ||
| for tool in tools if self.wrap_tool(tool).get('type') == 'function' | ||
| ] | ||
| tool_defs_joined = '\n\n'.join(tool_defs) | ||
|
|
||
| tool_call_format_instruction = ( | ||
| "工具调用请遵循如下格式:\n" | ||
| f"{self.TOOL_CALL_START}\n" | ||
| f"<{self.FUNCTION_TAG}=example_function_name>\n" | ||
| f"<{self.PARAMETER_TAG}=example_parameter_1>value_1</{self.PARAMETER_TAG}>\n" | ||
| f"<{self.PARAMETER_TAG}=example_parameter_2>This is the value for the second parameter\n" | ||
| "that can span\n" | ||
| f"multiple lines</{self.PARAMETER_TAG}>\n" | ||
| f"</{self.FUNCTION_TAG}>\n" | ||
| f"{self.TOOL_CALL_END}" | ||
| ) | ||
|
|
||
| split_token = "<seed:eos><seed:bos>system" | ||
| if split_token in system_prompt: | ||
| parts = system_prompt.split(split_token, 1) | ||
| return f"{parts[0]}\n\n{tool_defs_joined}\n{tool_call_format_instruction}\n{split_token}{parts[1]}" | ||
| else: | ||
| return f"{system_prompt}\n\n{tool_defs_joined}\n{tool_call_format_instruction}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an inconsistency in the language used for constructing the system prompt. The default system prompt (line 107) is in English, while the tool call instructions (line 116) and req_tag in _build_tool_def_string (line 82) are in Chinese. This could lead to confusing prompts for the model and for developers using this template. Please ensure consistency by using a single language.
| if properties: | ||
| docstring_parts.append('\n Args:') | ||
| required_params = parameters.get('required', []) | ||
| for name, spec in properties.items(): | ||
| req_tag = '[必填]' if name in required_params else '[选填]' | ||
| desc = spec.get("description", "") | ||
| type_str = self._py_type(spec.get("type", "any")) | ||
| docstring_parts.append(f' - {name} ({type_str}) {req_tag}: {desc}') | ||
|
|
||
| returns_props = func.get('returns', {}).get('properties', {}) | ||
| if returns_props: | ||
| docstring_parts.append('\n Returns:') | ||
| for name, spec in returns_props.items(): | ||
| desc = spec.get("description", "") | ||
| type_str = self._py_type(spec.get("type", "any")) | ||
| docstring_parts.append(f' - {name} ({type_str}): {desc}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is duplicated logic for processing properties in the if properties: block (lines 78-85) and the if returns_props: block (lines 87-93). The code for extracting description and type, and formatting the output line is very similar. Consider refactoring this into a helper function to reduce code duplication and improve maintainability. A helper function could take a dictionary of properties and format them into a list of strings.
|
hello 😊 please run following command and please write a test case, referring to here. https://github.com/modelscope/ms-swift/blob/main/tests/test_align/test_template/test_agent.py |
|
|
Hello! Could you use pre-commit to format the code to pass the lint tests? You need to go into the (use py310/py311) pip install pre-commit
pre-commit run --all-files |
|
|
I made some revisions and resubmitted. |

PR type
PR information
Write the detail information belongs to this PR.
Experiment results
Paste your experiment result here(if needed).