Skip to content

Commit 6f32e18

Browse files
committed
feat(tool): preserve root schema keywords in toJsonSchema pass-through
1 parent 213589b commit 6f32e18

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/tool.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,17 @@ export class BaseTool {
183183
* This is framework-agnostic and can be used with any LLM that accepts JSON Schema
184184
*/
185185
toJsonSchema(): ObjectJSONSchema {
186-
return {
186+
const schema: Record<string, unknown> = {
187+
...this.parameters,
187188
type: 'object',
188189
properties: this.parameters.properties,
189-
required: this.parameters.required,
190190
};
191+
if (this.parameters.required && this.parameters.required.length > 0) {
192+
schema.required = this.parameters.required;
193+
} else {
194+
delete schema.required;
195+
}
196+
return schema as unknown as ObjectJSONSchema;
191197
}
192198

193199
/**

‎src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export interface ToolExecution {
159159
/**
160160
* Schema definition for tool parameters
161161
*/
162-
export interface ToolParameters {
162+
export interface ToolParameters extends Record<string, unknown> {
163163
type: string;
164164
properties: JsonSchemaProperties; // these are the params we will expose to the user/agent in the tool. These might be higher level params.
165165
required?: string[]; // list of required parameter names

0 commit comments

Comments
 (0)