Skip to content

Commit 6619d46

Browse files
authored
feat(anthropic): enable native tools by default and add telemetry tracking (#10021)
1 parent 69307ba commit 6619d46

File tree

4 files changed

+153
-81
lines changed

4 files changed

+153
-81
lines changed

packages/types/src/providers/anthropic.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const anthropicModels = {
1212
supportsImages: true,
1313
supportsPromptCache: true,
1414
supportsNativeTools: true,
15+
defaultToolProtocol: "native",
1516
inputPrice: 3.0, // $3 per million input tokens (≤200K context)
1617
outputPrice: 15.0, // $15 per million output tokens (≤200K context)
1718
cacheWritesPrice: 3.75, // $3.75 per million tokens
@@ -34,6 +35,7 @@ export const anthropicModels = {
3435
supportsImages: true,
3536
supportsPromptCache: true,
3637
supportsNativeTools: true,
38+
defaultToolProtocol: "native",
3739
inputPrice: 3.0, // $3 per million input tokens (≤200K context)
3840
outputPrice: 15.0, // $15 per million output tokens (≤200K context)
3941
cacheWritesPrice: 3.75, // $3.75 per million tokens
@@ -56,6 +58,7 @@ export const anthropicModels = {
5658
supportsImages: true,
5759
supportsPromptCache: true,
5860
supportsNativeTools: true,
61+
defaultToolProtocol: "native",
5962
inputPrice: 5.0, // $5 per million input tokens
6063
outputPrice: 25.0, // $25 per million output tokens
6164
cacheWritesPrice: 6.25, // $6.25 per million tokens
@@ -68,6 +71,7 @@ export const anthropicModels = {
6871
supportsImages: true,
6972
supportsPromptCache: true,
7073
supportsNativeTools: true,
74+
defaultToolProtocol: "native",
7175
inputPrice: 15.0, // $15 per million input tokens
7276
outputPrice: 75.0, // $75 per million output tokens
7377
cacheWritesPrice: 18.75, // $18.75 per million tokens
@@ -80,6 +84,7 @@ export const anthropicModels = {
8084
supportsImages: true,
8185
supportsPromptCache: true,
8286
supportsNativeTools: true,
87+
defaultToolProtocol: "native",
8388
inputPrice: 15.0, // $15 per million input tokens
8489
outputPrice: 75.0, // $75 per million output tokens
8590
cacheWritesPrice: 18.75, // $18.75 per million tokens
@@ -92,6 +97,7 @@ export const anthropicModels = {
9297
supportsImages: true,
9398
supportsPromptCache: true,
9499
supportsNativeTools: true,
100+
defaultToolProtocol: "native",
95101
inputPrice: 3.0, // $3 per million input tokens
96102
outputPrice: 15.0, // $15 per million output tokens
97103
cacheWritesPrice: 3.75, // $3.75 per million tokens
@@ -105,6 +111,7 @@ export const anthropicModels = {
105111
supportsImages: true,
106112
supportsPromptCache: true,
107113
supportsNativeTools: true,
114+
defaultToolProtocol: "native",
108115
inputPrice: 3.0, // $3 per million input tokens
109116
outputPrice: 15.0, // $15 per million output tokens
110117
cacheWritesPrice: 3.75, // $3.75 per million tokens
@@ -116,6 +123,7 @@ export const anthropicModels = {
116123
supportsImages: true,
117124
supportsPromptCache: true,
118125
supportsNativeTools: true,
126+
defaultToolProtocol: "native",
119127
inputPrice: 3.0, // $3 per million input tokens
120128
outputPrice: 15.0, // $15 per million output tokens
121129
cacheWritesPrice: 3.75, // $3.75 per million tokens
@@ -127,6 +135,7 @@ export const anthropicModels = {
127135
supportsImages: false,
128136
supportsPromptCache: true,
129137
supportsNativeTools: true,
138+
defaultToolProtocol: "native",
130139
inputPrice: 1.0,
131140
outputPrice: 5.0,
132141
cacheWritesPrice: 1.25,
@@ -138,6 +147,7 @@ export const anthropicModels = {
138147
supportsImages: true,
139148
supportsPromptCache: true,
140149
supportsNativeTools: true,
150+
defaultToolProtocol: "native",
141151
inputPrice: 15.0,
142152
outputPrice: 75.0,
143153
cacheWritesPrice: 18.75,
@@ -149,6 +159,7 @@ export const anthropicModels = {
149159
supportsImages: true,
150160
supportsPromptCache: true,
151161
supportsNativeTools: true,
162+
defaultToolProtocol: "native",
152163
inputPrice: 0.25,
153164
outputPrice: 1.25,
154165
cacheWritesPrice: 0.3,
@@ -160,6 +171,7 @@ export const anthropicModels = {
160171
supportsImages: true,
161172
supportsPromptCache: true,
162173
supportsNativeTools: true,
174+
defaultToolProtocol: "native",
163175
inputPrice: 1.0,
164176
outputPrice: 5.0,
165177
cacheWritesPrice: 1.25,

src/api/providers/__tests__/anthropic.spec.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
import { AnthropicHandler } from "../anthropic"
44
import { ApiHandlerOptions } from "../../../shared/api"
55

6+
// Mock TelemetryService
7+
vitest.mock("@roo-code/telemetry", () => ({
8+
TelemetryService: {
9+
instance: {
10+
captureException: vitest.fn(),
11+
},
12+
},
13+
}))
14+
615
const mockCreate = vitest.fn()
716

817
vitest.mock("@anthropic-ai/sdk", () => {
@@ -411,11 +420,11 @@ describe("AnthropicHandler", () => {
411420
},
412421
]
413422

414-
it("should include tools in request when toolProtocol is native", async () => {
423+
it("should include tools in request by default (native is default)", async () => {
424+
// Handler uses native protocol by default via model's defaultToolProtocol
415425
const stream = handler.createMessage(systemPrompt, messages, {
416426
taskId: "test-task",
417427
tools: mockTools,
418-
toolProtocol: "native",
419428
})
420429

421430
// Consume the stream to trigger the API call
@@ -443,10 +452,15 @@ describe("AnthropicHandler", () => {
443452
})
444453

445454
it("should not include tools when toolProtocol is xml", async () => {
446-
const stream = handler.createMessage(systemPrompt, messages, {
455+
// Create handler with xml tool protocol in options
456+
const xmlHandler = new AnthropicHandler({
457+
...mockOptions,
458+
toolProtocol: "xml",
459+
})
460+
461+
const stream = xmlHandler.createMessage(systemPrompt, messages, {
447462
taskId: "test-task",
448463
tools: mockTools,
449-
toolProtocol: "xml",
450464
})
451465

452466
// Consume the stream to trigger the API call
@@ -463,9 +477,9 @@ describe("AnthropicHandler", () => {
463477
})
464478

465479
it("should not include tools when no tools are provided", async () => {
480+
// Handler uses native protocol by default
466481
const stream = handler.createMessage(systemPrompt, messages, {
467482
taskId: "test-task",
468-
toolProtocol: "native",
469483
})
470484

471485
// Consume the stream to trigger the API call
@@ -482,10 +496,10 @@ describe("AnthropicHandler", () => {
482496
})
483497

484498
it("should convert tool_choice 'auto' to Anthropic format", async () => {
499+
// Handler uses native protocol by default
485500
const stream = handler.createMessage(systemPrompt, messages, {
486501
taskId: "test-task",
487502
tools: mockTools,
488-
toolProtocol: "native",
489503
tool_choice: "auto",
490504
})
491505

@@ -503,10 +517,10 @@ describe("AnthropicHandler", () => {
503517
})
504518

505519
it("should convert tool_choice 'required' to Anthropic 'any' format", async () => {
520+
// Handler uses native protocol by default
506521
const stream = handler.createMessage(systemPrompt, messages, {
507522
taskId: "test-task",
508523
tools: mockTools,
509-
toolProtocol: "native",
510524
tool_choice: "required",
511525
})
512526

@@ -524,10 +538,10 @@ describe("AnthropicHandler", () => {
524538
})
525539

526540
it("should omit both tools and tool_choice when tool_choice is 'none'", async () => {
541+
// Handler uses native protocol by default
527542
const stream = handler.createMessage(systemPrompt, messages, {
528543
taskId: "test-task",
529544
tools: mockTools,
530-
toolProtocol: "native",
531545
tool_choice: "none",
532546
})
533547

@@ -552,10 +566,10 @@ describe("AnthropicHandler", () => {
552566
})
553567

554568
it("should convert specific tool_choice to Anthropic 'tool' format", async () => {
569+
// Handler uses native protocol by default
555570
const stream = handler.createMessage(systemPrompt, messages, {
556571
taskId: "test-task",
557572
tools: mockTools,
558-
toolProtocol: "native",
559573
tool_choice: { type: "function" as const, function: { name: "get_weather" } },
560574
})
561575

@@ -573,10 +587,10 @@ describe("AnthropicHandler", () => {
573587
})
574588

575589
it("should enable parallel tool calls when parallelToolCalls is true", async () => {
590+
// Handler uses native protocol by default
576591
const stream = handler.createMessage(systemPrompt, messages, {
577592
taskId: "test-task",
578593
tools: mockTools,
579-
toolProtocol: "native",
580594
tool_choice: "auto",
581595
parallelToolCalls: true,
582596
})
@@ -618,10 +632,10 @@ describe("AnthropicHandler", () => {
618632
},
619633
}))
620634

635+
// Handler uses native protocol by default
621636
const stream = handler.createMessage(systemPrompt, messages, {
622637
taskId: "test-task",
623638
tools: mockTools,
624-
toolProtocol: "native",
625639
})
626640

627641
const chunks: any[] = []
@@ -685,10 +699,10 @@ describe("AnthropicHandler", () => {
685699
},
686700
}))
687701

702+
// Handler uses native protocol by default
688703
const stream = handler.createMessage(systemPrompt, messages, {
689704
taskId: "test-task",
690705
tools: mockTools,
691-
toolProtocol: "native",
692706
})
693707

694708
const chunks: any[] = []

0 commit comments

Comments
 (0)