Skip to content

Commit e2d9d29

Browse files
committed
sdk: modify custom tool slightly to match with ai-sdk
1 parent cf59fe8 commit e2d9d29

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

sdk/src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { MAX_AGENT_STEPS_DEFAULT } from '../../common/src/constants/agents'
1818
import { API_KEY_ENV_VAR } from '../../common/src/old-constants'
1919
import { toolNames } from '../../common/src/tools/constants'
20-
import type { PublishedClientToolName } from '../../common/src/tools/list'
20+
2121
import {
2222
clientToolCallSchema,
2323
type ClientToolCall,
@@ -31,6 +31,7 @@ import type {
3131
PublishedToolName,
3232
ToolName,
3333
} from '../../common/src/tools/constants'
34+
import type { PublishedClientToolName } from '../../common/src/tools/list'
3435
import type {
3536
ToolResultOutput,
3637
ToolResultPart,
@@ -218,7 +219,7 @@ export class CodebuffClient {
218219
)
219220
}
220221
const toolDef = toolDefs[toolDefs.length - 1]
221-
const handler = toolDef.handler
222+
const handler = toolDef.execute
222223
try {
223224
return {
224225
output: toolDef.outputSchema.parse(

sdk/src/custom-tool.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { JSONSchema } from 'zod/v4/core'
55

66
export type CustomToolDefinition<
77
N extends string = string,
8-
Args = any,
9-
Input = any,
8+
Args = unknown,
9+
Input = unknown,
1010
Output extends ToolResultOutput[] = ToolResultOutput[],
1111
> = {
1212
toolName: N
@@ -16,9 +16,21 @@ export type CustomToolDefinition<
1616
description: string
1717
endsAgentStep: boolean
1818
exampleInputs: Input[]
19-
handler: (params: Args) => Promise<Output>
19+
execute: (params: Args) => Promise<Output>
2020
}
2121

22+
/**
23+
* Creates a CustomToolDefinition object
24+
*
25+
* @param toolName the name of the tool
26+
* @param inputSchema a Zod4 schema describing the input of the tool.
27+
* @param outputSchema a Zod4 schema describing the output of the tool.
28+
* @param description a description of the tool to be passed to the LLM. This should describe what the tool does and when to use it.
29+
* @param endsAgentStep whether the tool ends the agent step. If `true`, this will be used as a "stop sequence" for the LLM. i.e. it will not be able to call any other tools after this one in a single step and must wait for the tool results. Used for tools that give more information to the LLM.
30+
* @param exampleInputs an array of example inputs for the tool.
31+
* @param execute what to do when the tool is called.
32+
* @returns The CustomToolDefinition object
33+
*/
2234
export function getCustomToolDefinition<
2335
ToolName extends string,
2436
Args,
@@ -31,15 +43,15 @@ export function getCustomToolDefinition<
3143
description,
3244
endsAgentStep = true,
3345
exampleInputs = [],
34-
handler,
46+
execute,
3547
}: {
3648
toolName: ToolName
3749
inputSchema: z.ZodType<Args, Input>
3850
outputSchema: z.ZodType<ToolResultOutput[], Output>
3951
description: string
4052
endsAgentStep?: boolean
4153
exampleInputs?: Input[]
42-
handler: (params: Args) => Promise<Output>
54+
execute: (params: Args) => Promise<Output>
4355
}): CustomToolDefinition<ToolName, Args, Input, Output> {
4456
return {
4557
toolName,
@@ -49,6 +61,6 @@ export function getCustomToolDefinition<
4961
description,
5062
endsAgentStep,
5163
exampleInputs,
52-
handler,
64+
execute,
5365
}
5466
}

0 commit comments

Comments
 (0)