Skip to content

refactor(filter): use tool call for review filter output - #722

Open
lizhengfeng101 wants to merge 1 commit into
mainfrom
refactor/review-filter-tool-call
Open

refactor(filter): use tool call for review filter output#722
lizhengfeng101 wants to merge 1 commit into
mainfrom
refactor/review-filter-tool-call

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Collaborator

Summary

  • Replace the text-based JSON array output with a structured report_incorrect_comments tool call for the review filter task
  • The LLM's native tool-call mechanism guarantees valid JSON schema, eliminating the need for StripMarkdownFences and fragile text parsing
  • If no tool call is returned, it's treated as an error (consistent with how the main agent loop handles tool calls)

Changes

  • Prompt (review_filter_task_user.md): Updated output instructions to call the tool instead of returning raw JSON
  • Agent (agent.go): Inject report_incorrect_comments tool definition into ChatRequest.Tools; replace parseFilterResponse with parseFilterToolCall that extracts results from tool call arguments
  • Tests: Updated mock responses to use tool call format

Test plan

  • make check passes
  • make test passes
  • TestParseFilterToolCall covers: valid tool call, out-of-range/negative/invalid IDs, no tool call, wrong tool name, invalid arguments, empty array
  • TestExecuteReviewFilter_RemovesComments and TestExecuteReviewFilter_WithTimeout updated and passing

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

Comment thread internal/agent/agent.go
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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:

  1. Setting tool_choice to force invocation (e.g., {"type": "function", "function": {"name": "report_incorrect_comments"}}), or
  2. 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议修一下,可以提高工具调用的稳定性,但是 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.
@lizhengfeng101
lizhengfeng101 force-pushed the refactor/review-filter-tool-call branch from 849fd17 to 4fedf35 Compare August 14, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants