fix: detect tool calls as agent-initiated in Copilot plugin#22062
Closed
yepashkov wants to merge 2 commits intoanomalyco:devfrom
Closed
fix: detect tool calls as agent-initiated in Copilot plugin#22062yepashkov wants to merge 2 commits intoanomalyco:devfrom
yepashkov wants to merge 2 commits intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…overcharge The current isAgent detection only checks the last message role, which fails when tool results are returned. Tool call responses often have role: 'user' or contain tool_result parts, causing GitHub to incorrectly charge premium requests for agent-initiated actions. This fix checks the entire message context for tool calls (tool_result parts or role: 'tool') and marks the request as agent-initiated when tools are present, preventing incorrect premium request charges. Fixes anomalyco#8030 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
b617ad5 to
6b3687e
Compare
Collaborator
|
This checks if the message history contains any tool calls at all and if so makes it agent initiated, that means as soon as the agent calls a single tool, any subsequent prompts u send are "free" This will ofc get u BANNED this is not good. |
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.
Issue for this PR
Closes #8030
Type of change
What does this PR do?
Copilot was charging premium requests for tool calls because
isAgentonly checked the last message role. Tool results often haverole: "user", so they got flagged as user-initiated.Fixed by checking the full message context for
tool_resultparts orrole: "tool". If any exist, the request is marked as agent-initiated.Changed 3 API paths in
packages/opencode/src/plugin/github-copilot/copilot.ts: Completions, Responses, and Messages.How did you verify your code works?
Ran
bun turbo typecheck— all 13 packages passed. The logic follows the existing compaction detection pattern already in the same file'schat.headershook.Screenshots / recordings
N/A — no UI changes.
Checklist