@@ -10,7 +10,7 @@ import delay from "delay"
1010import pWaitFor from "p-wait-for"
1111import { serializeError } from "serialize-error"
1212import { Package } from "../../shared/package"
13- import { getCurrentToolProtocol , formatToolInvocation } from "../tools/helpers/toolResultFormatting"
13+ import { formatToolInvocation } from "../tools/helpers/toolResultFormatting"
1414
1515import {
1616 type TaskLike ,
@@ -46,7 +46,6 @@ import {
4646} from "@roo-code/types"
4747import { TelemetryService } from "@roo-code/telemetry"
4848import { CloudService , BridgeOrchestrator } from "@roo-code/cloud"
49- import { getToolProtocolFromSettings } from "../../utils/toolProtocol"
5049import { resolveToolProtocol } from "../../utils/resolveToolProtocol"
5150
5251// api
@@ -321,6 +320,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
321320 task,
322321 images,
323322 historyItem,
323+ experiments : experimentsConfig ,
324324 startTask = true ,
325325 rootTask,
326326 parentTask,
@@ -410,10 +410,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
410410
411411 // Initialize the assistant message parser only for XML protocol.
412412 // For native protocol, tool calls come as tool_call chunks, not XML.
413+ // experiments is always provided via TaskOptions (defaults to experimentDefault in provider)
413414 const toolProtocol = resolveToolProtocol (
414415 this . apiConfiguration ,
415416 this . api . getModel ( ) . info ,
416417 this . apiConfiguration . apiProvider ,
418+ experimentsConfig ,
417419 )
418420 this . assistantMessageParser = toolProtocol === "xml" ? new AssistantMessageParser ( ) : undefined
419421
@@ -1268,7 +1270,13 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
12681270 } without value for required parameter '${ paramName } '. Retrying...`,
12691271 )
12701272 const modelInfo = this . api . getModel ( ) . info
1271- const toolProtocol = resolveToolProtocol ( this . apiConfiguration , modelInfo , this . apiConfiguration . apiProvider )
1273+ const state = await this . providerRef . deref ( ) ?. getState ( )
1274+ const toolProtocol = resolveToolProtocol (
1275+ this . apiConfiguration ,
1276+ modelInfo ,
1277+ this . apiConfiguration . apiProvider ,
1278+ state ?. experiments ,
1279+ )
12721280 return formatResponse . toolError ( formatResponse . missingToolParameterError ( paramName , toolProtocol ) )
12731281 }
12741282
@@ -1409,10 +1417,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
14091417
14101418 // v2.0 xml tags refactor caveat: since we don't use tools anymore, we need to replace all tool use blocks with a text block since the API disallows conversations with tool uses and no tool schema
14111419 // Now also protocol-aware: format according to current protocol setting
1420+ const state = await this . providerRef . deref ( ) ?. getState ( )
14121421 const protocol = resolveToolProtocol (
14131422 this . apiConfiguration ,
14141423 this . api . getModel ( ) . info ,
14151424 this . apiConfiguration . apiProvider ,
1425+ state ?. experiments ,
14161426 )
14171427 const useNative = isNativeProtocol ( protocol )
14181428
@@ -1786,10 +1796,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
17861796 break
17871797 } else {
17881798 const modelInfo = this . api . getModel ( ) . info
1799+ const state = await this . providerRef . deref ( ) ?. getState ( )
17891800 const toolProtocol = resolveToolProtocol (
17901801 this . apiConfiguration ,
17911802 modelInfo ,
17921803 this . apiConfiguration . apiProvider ,
1804+ state ?. experiments ,
17931805 )
17941806 nextUserContent = [ { type : "text" , text : formatResponse . noToolsUsed ( toolProtocol ) } ]
17951807 this . consecutiveMistakeCount ++
@@ -2436,11 +2448,13 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
24362448 const parsedBlocks = this . assistantMessageParser . getContentBlocks ( )
24372449
24382450 // Check if we're using native protocol
2451+ const state = await this . providerRef . deref ( ) ?. getState ( )
24392452 const isNative = isNativeProtocol (
24402453 resolveToolProtocol (
24412454 this . apiConfiguration ,
24422455 this . api . getModel ( ) . info ,
24432456 this . apiConfiguration . apiProvider ,
2457+ state ?. experiments ,
24442458 ) ,
24452459 )
24462460
@@ -2581,10 +2595,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25812595
25822596 if ( ! didToolUse ) {
25832597 const modelInfo = this . api . getModel ( ) . info
2598+ const state = await this . providerRef . deref ( ) ?. getState ( )
25842599 const toolProtocol = resolveToolProtocol (
25852600 this . apiConfiguration ,
25862601 modelInfo ,
25872602 this . apiConfiguration . apiProvider ,
2603+ state ?. experiments ,
25882604 )
25892605 this . userMessageContent . push ( { type : "text" , text : formatResponse . noToolsUsed ( toolProtocol ) } )
25902606 this . consecutiveMistakeCount ++
@@ -2610,12 +2626,14 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
26102626 // apiConversationHistory at line 1876. Since the assistant failed to respond,
26112627 // we need to remove that message before retrying to avoid having two consecutive
26122628 // user messages (which would cause tool_result validation errors).
2629+ let state = await this . providerRef . deref ( ) ?. getState ( )
26132630 if (
26142631 isNativeProtocol (
26152632 resolveToolProtocol (
26162633 this . apiConfiguration ,
26172634 this . api . getModel ( ) . info ,
26182635 this . apiConfiguration . apiProvider ,
2636+ state ?. experiments ,
26192637 ) ,
26202638 ) &&
26212639 this . apiConversationHistory . length > 0
@@ -2628,7 +2646,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
26282646 }
26292647
26302648 // Check if we should auto-retry or prompt the user
2631- const state = await this . providerRef . deref ( ) ?. getState ( )
2649+ // Reuse the state variable from above
26322650 if ( state ?. autoApprovalEnabled && state ?. alwaysApproveResubmit ) {
26332651 // Auto-retry with backoff - don't persist failure message when retrying
26342652 const errorMsg =
@@ -2681,12 +2699,14 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
26812699 } else {
26822700 // User declined to retry
26832701 // For native protocol, re-add the user message we removed
2702+ // Reuse the state variable from above
26842703 if (
26852704 isNativeProtocol (
26862705 resolveToolProtocol (
26872706 this . apiConfiguration ,
26882707 this . api . getModel ( ) . info ,
26892708 this . apiConfiguration . apiProvider ,
2709+ state ?. experiments ,
26902710 ) ,
26912711 )
26922712 ) {
@@ -2791,6 +2811,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
27912811 apiConfiguration ?? this . apiConfiguration ,
27922812 modelInfo ,
27932813 ( apiConfiguration ?? this . apiConfiguration ) ?. apiProvider ,
2814+ experiments ,
27942815 )
27952816
27962817 return SYSTEM_PROMPT (
@@ -3030,7 +3051,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
30303051 // 1. Tool protocol is set to NATIVE
30313052 // 2. Model supports native tools
30323053 const modelInfo = this . api . getModel ( ) . info
3033- const toolProtocol = resolveToolProtocol ( this . apiConfiguration , modelInfo , this . apiConfiguration . apiProvider )
3054+ const toolProtocol = resolveToolProtocol (
3055+ this . apiConfiguration ,
3056+ modelInfo ,
3057+ this . apiConfiguration . apiProvider ,
3058+ state ?. experiments ,
3059+ )
30343060 const shouldIncludeTools = toolProtocol === TOOL_PROTOCOL . NATIVE && ( modelInfo . supportsNativeTools ?? false )
30353061
30363062 // Build complete tools array: native tools + dynamic MCP tools, filtered by mode restrictions
0 commit comments