-
-
Notifications
You must be signed in to change notification settings - Fork 930
feat: 增强工具调用参数处理机制 #3036
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
Merged
Merged
feat: 增强工具调用参数处理机制 #3036
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -209,17 +209,35 @@ async def _handle_function_tools( | |||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# 参数过滤:只传递函数实际需要的参数 | ||||||||||||||||||||||||||
import inspect | ||||||||||||||||||||||||||
valid_params = {} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
# 获取实际的 handler 函数 | ||||||||||||||||||||||||||
handler_func = func_tool.handler | ||||||||||||||||||||||||||
if handler_func: | ||||||||||||||||||||||||||
|
# 获取实际的 handler 函数 | |
handler_func = func_tool.handler | |
if handler_func: | |
if handler_func := func_tool.handler: |
解释
此函数的质量分数低于 25% 的质量阈值。
此分数是方法长度、认知复杂度和工作内存的组合。
如何解决这个问题?
重构此函数以使其更短、更易读可能是有益的。
- 通过将部分功能提取到自己的函数中来减少函数长度。这是您可以做的最重要的事情 - 理想情况下,一个函数应该少于 10 行。
- 减少嵌套,也许通过引入守卫子句来提前返回。
- 确保变量的作用域紧密,以便使用相关概念的代码在函数中坐在一起,而不是分散。
Original comment in English
suggestion (code-quality): We've found these issues:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Low code quality found in ToolLoopAgentRunner._handle_function_tools - 10% (
low-code-quality
)
Suggested change
# 获取实际的 handler 函数 | |
handler_func = func_tool.handler | |
if handler_func: | |
if handler_func := func_tool.handler: |
Explanation
The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.
How can you solve this?
It might be worth refactoring this function to make it shorter and more readable.
- Reduce the function length by extracting pieces of functionality out into
their own functions. This is the most important thing you can do - ideally a
function should be less than 10 lines. - Reduce nesting, perhaps by introducing guard clauses to return early.
- Ensure that variables are tightly scoped, so that code using related concepts
sits together within the function rather than being scattered.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.