@@ -255,11 +255,21 @@ def _build_schema(self, param_def):
255255 type = types .Type (param_type ),
256256 description = param_def .get ("description" , None ),
257257 )
258+ if "const" in param_def .keys ():
259+ schema .default = param_def .get ("const" , None )
260+
261+ if "enum" in param_def .keys ():
262+ schema .enum = param_def .get ("enum" , [])
263+
264+ if "anyOf" in param_def .keys ():
265+ schema .any_of = [
266+ self ._build_schema (item ) for item in param_def .get ("anyOf" , [])
267+ ]
258268 if param_type == "OBJECT" :
259269 schema .properties = {}
260- if "properties" in param_def :
270+ if "properties" in param_def . keys () :
261271 for key in param_def .get ("properties" , {}):
262- prop = param_def .get ("properties" ).get (" key" , {})
272+ prop = param_def .get ("properties" ).get (key , {})
263273 schema .properties [key ] = self ._build_schema (prop )
264274 elif param_type == "ARRAY" :
265275 itemsSchema = self ._build_schema (param_def .get ("items" ))
@@ -293,10 +303,12 @@ def register_tool(self, tool_definition, handler_function):
293303 tool_definition ["function" ].get ("parameters" , {}).get ("required" , [])
294304 )
295305 description = tool_definition ["function" ].get ("description" , "" )
306+ defs = tool_definition ["function" ].get ("parameters" , {}).get ("$defs" , {})
296307 else :
297308 parameters = tool_definition .get ("parameters" , {}).get ("properties" , {})
298309 required = tool_definition .get ("parameters" , {}).get ("required" , [])
299310 description = tool_definition .get ("description" , "" )
311+ defs = tool_definition .get ("parameters" , {}).get ("$defs" , {})
300312
301313 # Create a function declaration for Google GenAI
302314 function_declaration = types .FunctionDeclaration (
@@ -315,6 +327,14 @@ def register_tool(self, tool_definition, handler_function):
315327 function_declaration .parameters is not None
316328 and function_declaration .parameters .properties is not None
317329 ):
330+ if param_def .get ("$ref" , "" ):
331+ ref_key = param_def ["$ref" ].lstrip ("#/$defs/" )
332+ if ref_key in defs .keys ():
333+ function_declaration .parameters .properties [param_name ] = (
334+ self ._build_schema (defs [ref_key ])
335+ )
336+ continue
337+
318338 function_declaration .parameters .properties [param_name ] = (
319339 self ._build_schema (param_def )
320340 )
0 commit comments