Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/tool/src/utils/raw-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ export interface RawToolOptions<T = unknown> {
execute: (input: T, options: ToolExecuteOptions) => Promise<ToolExecuteResult> | ToolExecuteResult
name: string
parameters: JsonSchema
strict?: boolean
}

export const rawTool = <T = unknown>({ description, execute, name, parameters }: RawToolOptions<T>): Tool => ({
export const rawTool = <T = unknown>({ description, execute, name, parameters, strict }: RawToolOptions<T>): Tool => ({
execute: execute as Tool['execute'],
function: {
description,
name,
parameters: strictJsonSchema(parameters) as Record<string, unknown>,
strict: true,
parameters: (strict !== false
? strictJsonSchema(parameters)
: parameters) as Record<string, unknown>,
strict: strict ?? true,
},
type: 'function',
})
10 changes: 7 additions & 3 deletions packages/tool/src/utils/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ export interface ToolOptions<T extends Schema> {
execute: (input: InferIn<T>, options: ToolExecuteOptions) => Promise<ToolExecuteResult> | ToolExecuteResult
name: string
parameters: T
/** @default true */
strict?: boolean
}

export const tool = async <T extends Schema>({ description, execute, name, parameters }: ToolOptions<T>): Promise<Tool> => {
export const tool = async <T extends Schema>({ description, execute, name, parameters, strict }: ToolOptions<T>): Promise<Tool> => {
const schema = await toJsonSchema(parameters)

return {
execute,
function: {
description,
name,
parameters: strictJsonSchema(schema) as Record<string, unknown>,
strict: true,
parameters: (strict !== false
? strictJsonSchema(schema)
: schema) as Record<string, unknown>,
strict: strict ?? true,
},
type: 'function',
}
Expand Down
Loading