Skip to content

function tool arg default value cannot be None #2186

Closed

Description

@longcw

Issue 1: the default value of the arg of function tool cannot be None

    @function_tool()
    async def update_caller_status(
        context: RunContext_T,
        caller_name: Optional[str] = None,
    ) -> str:
        logger.info(f"Updating caller status to {caller_name}")
        return "ok"

for example this one raises

livekit.agents._exceptions.APIStatusError: Error code: 400 - {'error': {'message': "Invalid schema for function 'update_caller_status': In context=('properties', 'caller_name'), 'default' is not permitted.", 'type': 'invalid_request_error', 'param': 'tools[0].function.parameters', 'code': 'invalid_function_parameters'}} (status_code=400, request_id=req_69d97bdefaaaa6f45cf652fbe439f4b1, body={'message': "Invalid schema for function 'update_caller_status': In context=('properties', 'caller_name'), 'default' is not permitted.", 'type': 'invalid_request_error', 'param': 'tools[0].function.parameters', 'code': 'invalid_function_parameters'})

the schema generated by build_strict_openai_schema is

{'function': {'description': '',
              'name': 'update_caller_status',
              'parameters': {'additionalProperties': False,
                             'properties': {'caller_name': {'default': None,
                                                            'type': ['string',
                                                                     'null']}},
                             'required': ['caller_name'],
                             'type': 'object'},
              'strict': True},
 'type': 'function'}

A str default works for this case.

### Issue 2: function_tool without context: RunContext_T has a wrong args scehma
(it's bc the class method missing the self)

from slack https://livekit-users.slack.com/archives/C07FY8WHGPM/p1745885751149599

Activity

  1. added
    bug
    on May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions