Repository navigation
fix(v3): avoid forced done tool use for Sonnet 5.5 #3132
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
Open
shubh24
wants to merge
2
commits into
v3
Choose a base branch
from
shubh24/sonnet-55-auto-done-v3
base: v3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@browserbasehq/stagehand": patch | ||
| --- | ||
|
|
||
| Use automatic tool choice for the final agent `done` call with Claude Sonnet 5.5, Opus 5.5, and Fable 5.1. |
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
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
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import type { LanguageModelV2 } from "@ai-sdk/provider"; | ||
|
|
||
| import { handleDoneToolCall } from "../../lib/v3/agent/utils/handleDoneToolCall.js"; | ||
|
|
||
| const automaticToolChoiceModels = [ | ||
| "claude-sonnet-5-5", | ||
| "claude-opus-5-5", | ||
| "claude-fable-5-1", | ||
| ].flatMap((modelId) => [modelId, `anthropic/${modelId}`]); | ||
|
|
||
| function modelMock(modelId: string, response: "done" | "text") { | ||
| const toolChoices: unknown[] = []; | ||
| const model = { | ||
| specificationVersion: "v2", | ||
| provider: "anthropic", | ||
| modelId, | ||
| supportedUrls: {}, | ||
| async doGenerate(options: Parameters<LanguageModelV2["doGenerate"]>[0]) { | ||
| toolChoices.push(options.toolChoice); | ||
| if ( | ||
| options.toolChoice?.type === "tool" || | ||
| options.toolChoice?.type === "required" | ||
| ) { | ||
| throw new Error(`${modelId} rejects forced tool use`); | ||
| } | ||
| return { | ||
| finishReason: "stop" as const, | ||
| usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 }, | ||
| content: | ||
| response === "done" | ||
| ? [ | ||
| { | ||
| type: "tool-call" as const, | ||
| toolCallId: "done-1", | ||
| toolName: "done", | ||
| input: JSON.stringify({ | ||
| reasoning: "The task is complete.", | ||
| taskComplete: true, | ||
| }), | ||
| }, | ||
| ] | ||
| : [{ type: "text" as const, text: "The task needs review." }], | ||
| warnings: [] as [], | ||
| }; | ||
| }, | ||
| } as unknown as LanguageModelV2; | ||
| return { model, toolChoices }; | ||
| } | ||
|
|
||
| describe("v3 agent done tool choice", () => { | ||
| it.each(automaticToolChoiceModels)( | ||
| "lets %s call done without forcing tool use", | ||
| async (modelId) => { | ||
| const { model, toolChoices } = modelMock(modelId, "done"); | ||
| const result = await handleDoneToolCall({ | ||
| model, | ||
| inputMessages: [{ role: "user", content: "The task is complete." }], | ||
| instruction: "Complete the task", | ||
| logger: () => {}, | ||
| }); | ||
|
|
||
| expect(toolChoices).toEqual([{ type: "auto" }]); | ||
| expect(result.taskComplete).toBe(true); | ||
| expect(result.reasoning).toBe("The task is complete."); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(automaticToolChoiceModels)( | ||
| "keeps a text reply from %s as an incomplete result", | ||
| async (modelId) => { | ||
| const { model, toolChoices } = modelMock(modelId, "text"); | ||
| const result = await handleDoneToolCall({ | ||
| model, | ||
| inputMessages: [{ role: "user", content: "The task is incomplete." }], | ||
| instruction: "Complete the task", | ||
| logger: () => {}, | ||
| }); | ||
|
|
||
| expect(toolChoices).toEqual([{ type: "auto" }]); | ||
| expect(result.taskComplete).toBe(false); | ||
| expect(result.reasoning).toBe("The task needs review."); | ||
| }, | ||
| ); | ||
| }); | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3:
automaticToolChoiceModelsomitsclaude-fable-5, one of the four entries inMODELS_WITHOUT_FORCED_TOOL_USE(anthropicOptions.ts), so thehandleDoneToolCallauto-tool-choice path for the base Fable model is never exercised here. Add it (or export the implementation set) so the test and source lists cannot drift.Prompt for AI agents