refactor(filter): use tool call for review filter output - #722
refactor(filter): use tool call for review filter output#722lizhengfeng101 wants to merge 1 commit into
Conversation
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
| toolCalls := resp.ToolCalls() | ||
| if len(toolCalls) == 0 { | ||
| fmt.Fprintf(stdout.Writer(), "[ocr] Review filter: no tool call in response\n") | ||
| return nil | ||
| } |
There was a problem hiding this comment.
[bug · medium]
When tools are provided but tool_choice is not set, OpenAI-compatible APIs default to "auto", meaning the model may or may not invoke the tool. If the model responds with plain text instead of a tool call (e.g., when it believes no comments are incorrect, or if the model has limited tool-calling support), the filter silently becomes a no-op and all comments pass through.
The old parseFilterResponse at least attempted to parse the text content as a fallback. Consider either:
- Setting
tool_choiceto force invocation (e.g.,{"type": "function", "function": {"name": "report_incorrect_comments"}}), or - Falling back to text-based parsing of
resp.Content()when no tool call is found.
Option 1 is preferable since the tool's description already instructs the model to return an empty array when no comments are incorrect.
There was a problem hiding this comment.
建议修一下,可以提高工具调用的稳定性,但是 AI 提供的方法不适用于 Responses 和 Anthropic 客户端,这三者的 SDK 应该都有专门的字段支持直接指定需要调用的工具名的字段
… output Replace the text-based JSON array output with a structured tool call (report_incorrect_comments) for the review filter task. This improves output reliability by leveraging the LLM's native tool-call mechanism which guarantees valid JSON schema, eliminating the need for StripMarkdownFences and fragile text parsing.
849fd17 to
4fedf35
Compare
Summary
report_incorrect_commentstool call for the review filter taskStripMarkdownFencesand fragile text parsingChanges
review_filter_task_user.md): Updated output instructions to call the tool instead of returning raw JSONagent.go): Injectreport_incorrect_commentstool definition intoChatRequest.Tools; replaceparseFilterResponsewithparseFilterToolCallthat extracts results from tool call argumentsTest plan
make checkpassesmake testpassesTestParseFilterToolCallcovers: valid tool call, out-of-range/negative/invalid IDs, no tool call, wrong tool name, invalid arguments, empty arrayTestExecuteReviewFilter_RemovesCommentsandTestExecuteReviewFilter_WithTimeoutupdated and passing