Repository navigation
Closed
Labels
bugSomething isn't working
Description
Create an ticket to track this issue:
I was not able to create a tool with default argument like
@function_tool
async def get_weather(self, location: str = "") -> str:
"""
Called when the user asks about the weather.
Args:
location: The location to get the weather for
"""OAI raises error Invalid schema for function 'get_weather': In context=('properties', 'location'), 'default' is not permitted.
2025-04-11 15:01:20,350 - WARNING livekit.agents - failed to generate LLM completion, retrying in 2.0s
Traceback (most recent call last):
File "/home/longc/data/code/agents/livekit-agents/livekit/agents/llm/llm.py", line 137, in _main_task
return await self._run()
^^^^^^^^^^^^^^^^^
File "/home/longc/data/code/agents/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/llm.py", line 599, in _run
raise APIStatusError(
livekit.agents._exceptions.APIStatusError: Error code: 400 - {'error': {'message': "Invalid schema for function 'get_weather': In context=('properties', 'location'), 'default' is not permitted.", 'type': 'invalid_request_error', 'param': 'tools[0].function.parameters', 'code': 'invalid_function_parameters'}} (status_code=400, request_id=req_6da84b4da8310ea5c55054fa50e9113e, body={'message': "Invalid schema for function 'get_weather': In context=('properties', 'location'), 'default' is not permitted.", 'type': 'invalid_request_error', 'param': 'tools[0].function.parameters', 'code': 'invalid_function_parameters'})But something like this works, seems it has to be an enum to have the default value?
@function_tool
async def toggle_light(
self,
switch_to: Literal["on", "off"] = "on",
) -> str:
...their schemas are
# failed
{'properties': {'location': {'default': 'New York', 'description': 'The location to get the weather for', 'title': 'Location', 'type': 'string'}}, 'title': 'GetWeatherArgs', 'type': 'object', 'additionalProperties': False, 'required': ['location']}
# succ
{'properties': {'switch_to': {'default': 'on', 'description': 'The state to turn the light to', 'enum': ['on', 'off'], 'title': 'Switch To', 'type': 'string'}}, 'title': 'ToggleLightArgs', 'type': 'object', 'additionalProperties': False, 'required': ['switch_to']}
also, can we remove the arg from required if it has a default value?
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
[-]default value for function tool argument mark require to False[/-][+]default value for function tool argument doesn't work for some types[/+]nickderobertis commentedon Apr 21, 2025
We are running into this as well and it's preventing us from upgrading to 1.0. We noticed that it can be reproduced with the weather example by adding an additional arg. Note that it seems to only affect
LLMand notRealtimeModel, if you use this same script withRealtimeModelit works fine.blakemjones commentedon May 1, 2025
I've upgraded to
livekit-agents==1.0.18and validated that the code trying to fix this is installed locally, but I'm still getting the following error message:This is my tool definition:
After running the debugger, I found that the
patient_preferred_namewas still set with adefaultkey atlivekit/agents/llm/utils.py:209in thebuild_strict_openai_schemamethod and that the line in_strict.py:111in_ensure_strict_json_schemanever gets hit.This is because your check for the "default" key is dependent on the value, I've left a comment on your PR.
One more note: the description for this optional parameter isn't getting populated. I'm not sure why yet, looking into it.
Thank you!
theomonnom commentedon May 3, 2025
Thanks for the report @blakemjones, done here #2187 !