refactor(filter): use tool call for review filter output - #722
Open
lizhengfeng101 wants to merge 1 commit into
Open
refactor(filter): use tool call for review filter output#722lizhengfeng101 wants to merge 1 commit into
lizhengfeng101 wants to merge 1 commit into
Conversation
… 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.
Contributor
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
Comment on lines
+1333
to
+1337
| toolCalls := resp.ToolCalls() | ||
| if len(toolCalls) == 0 { | ||
| fmt.Fprintf(stdout.Writer(), "[ocr] Review filter: no tool call in response\n") | ||
| return nil | ||
| } |
Contributor
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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