File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -430,7 +430,7 @@ export class DynamicStructuredTool<
430
430
this . func = fields . func ;
431
431
this . returnDirect = fields . returnDirect ?? this . returnDirect ;
432
432
this . schema = (
433
- isZodSchema ( fields . schema ) ? fields . schema : z . object ( { } )
433
+ isZodSchema ( fields . schema ) ? fields . schema : z . object ( { } ) . passthrough ( )
434
434
) as T extends ZodObjectAny ? T : ZodObjectAny ;
435
435
}
436
436
@@ -557,7 +557,11 @@ export function tool<
557
557
| DynamicStructuredTool < T extends ZodObjectAny ? T : ZodObjectAny >
558
558
| DynamicTool {
559
559
// If the schema is not provided, or it's a string schema, create a DynamicTool
560
- if ( ! fields . schema || ! ( "shape" in fields . schema ) || ! fields . schema . shape ) {
560
+ if (
561
+ ! fields . schema ||
562
+ ( isZodSchema ( fields . schema ) &&
563
+ ( ! ( "shape" in fields . schema ) || ! fields . schema . shape ) )
564
+ ) {
561
565
return new DynamicTool ( {
562
566
...fields ,
563
567
description :
Original file line number Diff line number Diff line change @@ -128,23 +128,33 @@ test("Tool declared with JSON schema", async () => {
128
128
required : [ "location" ] ,
129
129
} ;
130
130
const weatherTool = tool (
131
- ( _ ) => {
131
+ ( input ) => {
132
+ // even without validation expect input to be passed
133
+ expect ( input ) . toEqual ( {
134
+ somethingSilly : true ,
135
+ } ) ;
132
136
return "Sunny" ;
133
137
} ,
134
138
{
135
139
name : "weather" ,
136
140
schema : weatherSchema ,
137
141
}
138
142
) ;
143
+ expect ( weatherTool ) . toBeInstanceOf ( DynamicStructuredTool ) ;
139
144
140
145
const weatherTool2 = new DynamicStructuredTool ( {
141
146
name : "weather" ,
142
147
description : "get the weather" ,
143
- func : async ( _ ) => {
148
+ func : async ( input ) => {
149
+ // even without validation expect input to be passed
150
+ expect ( input ) . toEqual ( {
151
+ somethingSilly : true ,
152
+ } ) ;
144
153
return "Sunny" ;
145
154
} ,
146
155
schema : weatherSchema ,
147
156
} ) ;
157
+
148
158
// No validation on JSON schema tools
149
159
await weatherTool . invoke ( {
150
160
somethingSilly : true ,
You can’t perform that action at this time.
0 commit comments