Skip to content

Commit 46e5a8c

Browse files
committed
Fix nudge injection to insert before tool_use blocks
1 parent 05d5d8d commit 46e5a8c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/fetch-wrapper/formats/anthropic.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export const anthropicFormat: FormatDescriptor = {
4242
if (msg.role === 'assistant') {
4343
// Append to existing content array
4444
if (Array.isArray(msg.content)) {
45-
msg.content.push({ type: 'text', text: injection })
45+
const firstToolUseIndex = msg.content.findIndex((block: any) => block.type === 'tool_use')
46+
if (firstToolUseIndex !== -1) {
47+
msg.content.splice(firstToolUseIndex, 0, { type: 'text', text: injection })
48+
} else {
49+
msg.content.push({ type: 'text', text: injection })
50+
}
4651
} else if (typeof msg.content === 'string') {
4752
// Convert string content to array format
4853
msg.content = [

0 commit comments

Comments
 (0)