Interface: ToolUseStrategy
@providerprotocol/ai / @providerprotocol/ai / ToolUseStrategy
Interface: ToolUseStrategy
Section titled “Interface: ToolUseStrategy”Defined in: src/types/tool.ts:257
Strategy for controlling tool execution behavior.
Provides hooks for monitoring, controlling, and transforming the tool execution loop during LLM inference.
Example
Section titled “Example”const strategy: ToolUseStrategy = { maxIterations: 5, onToolCall: (tool, params) => { console.log(`Calling ${tool.name} with`, params); }, // Transform input parameters onBeforeCall: (tool, params) => { if (tool.name === 'search') { return { proceed: true, params: { ...params, limit: 10 } }; } return true; }, // Transform output results onAfterCall: (tool, params, result) => { if (tool.name === 'fetch_data') { return { result: sanitize(result) }; } }, onMaxIterations: (iterations) => { console.warn(`Reached max iterations: ${iterations}`); }};Properties
Section titled “Properties”maxIterations?
Section titled “maxIterations?”
optionalmaxIterations:number
Defined in: src/types/tool.ts:259
Maximum number of tool execution rounds (default: 10)
Methods
Section titled “Methods”onAfterCall()?
Section titled “onAfterCall()?”
optionalonAfterCall(tool,params,result):void|AfterCallResult|Promise<void|AfterCallResult>
Defined in: src/types/tool.ts:289
Called after tool execution completes. Can transform the result.
Parameters
Section titled “Parameters”The tool that was executed
params
Section titled “params”unknown
The parameters that were used
result
Section titled “result”unknown
The result from the tool
Returns
Section titled “Returns”void | AfterCallResult | Promise<void | AfterCallResult>
Void to use original result, or AfterCallResult to transform it
onBeforeCall()?
Section titled “onBeforeCall()?”
optionalonBeforeCall(tool,params):boolean|BeforeCallResult|Promise<boolean|BeforeCallResult>
Defined in: src/types/tool.ts:279
Called before tool execution. Can skip execution or transform parameters.
Parameters
Section titled “Parameters”The tool about to be executed
params
Section titled “params”unknown
The parameters for the call
Returns
Section titled “Returns”boolean | BeforeCallResult | Promise<boolean | BeforeCallResult>
One of:
falseto skip executiontrueto proceed with original paramsBeforeCallResultobject to control execution and optionally transform params
onError()?
Section titled “onError()?”
optionalonError(tool,params,error):void|Promise<void>
Defined in: src/types/tool.ts:298
Called when a tool execution throws an error.
Parameters
Section titled “Parameters”The tool that failed
params
Section titled “params”unknown
The parameters that were used
Error
The error that was thrown
Returns
Section titled “Returns”void | Promise<void>
onMaxIterations()?
Section titled “onMaxIterations()?”
optionalonMaxIterations(iterations):void|Promise<void>
Defined in: src/types/tool.ts:305
Called when the maximum iteration limit is reached.
Parameters
Section titled “Parameters”iterations
Section titled “iterations”number
The number of iterations that were performed
Returns
Section titled “Returns”void | Promise<void>
onToolCall()?
Section titled “onToolCall()?”
optionalonToolCall(tool,params):void|Promise<void>
Defined in: src/types/tool.ts:267
Called when the model requests a tool call.
Parameters
Section titled “Parameters”The tool being called
params
Section titled “params”unknown
The parameters for the call
Returns
Section titled “Returns”void | Promise<void>