-
-
Notifications
You must be signed in to change notification settings - Fork 188
fix(ai, ai-anthropic): thinking blocks missing on turn 2+ in tool loops #391
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
ea96c3d
c042c55
2019809
c31d45d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,7 @@ function isToolCallIncluded(part: ToolCallPart): boolean { | |
| function buildAssistantMessages(uiMessage: UIMessage): Array<ModelMessage> { | ||
| const messageList: Array<ModelMessage> = [] | ||
| let current = createSegment() | ||
| let pendingThinking: Array<{ content: string; signature?: string }> = [] | ||
|
|
||
|
Comment on lines
+168
to
169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still loses thinking/tool-call order within a single turn.
Also applies to: 233-239 🤖 Prompt for AI Agents |
||
| // Track emitted tool result IDs to avoid duplicates. | ||
| // A tool call can have BOTH an explicit tool-result part AND an output | ||
|
|
@@ -181,7 +182,9 @@ function buildAssistantMessages(uiMessage: UIMessage): Array<ModelMessage> { | |
| role: 'assistant', | ||
| content, | ||
| ...(hasToolCalls && { toolCalls: current.toolCalls }), | ||
| ...(pendingThinking.length > 0 && { thinking: pendingThinking }), | ||
| }) | ||
| pendingThinking = [] | ||
| } | ||
| current = createSegment() | ||
| } | ||
|
|
@@ -227,7 +230,15 @@ function buildAssistantMessages(uiMessage: UIMessage): Array<ModelMessage> { | |
| } | ||
| break | ||
|
|
||
| // thinking parts are skipped - they're UI-only | ||
| case 'thinking': | ||
| if (part.content) { | ||
| pendingThinking.push({ | ||
| content: part.content, | ||
| ...(part.signature && { signature: part.signature }), | ||
| }) | ||
| } | ||
| break | ||
|
|
||
| default: | ||
| break | ||
| } | ||
|
|
||
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.
Replay signed thinking for non-tool assistant messages too.
Line 407 only preserves thinking inside the
assistant && toolCallsbranch. Assistant responses that contain signed thinking but no tool calls fall through to lines 468-478, so theirmessage.thinkingis dropped from future Anthropic context.🐛 Proposed fix
Also applies to: 468-478
🤖 Prompt for AI Agents