in src/agents/function_schema.py [0:0]
def to_call_args(self, data: BaseModel) -> tuple[list[Any], dict[str, Any]]:
"""
Converts validated data from the Pydantic model into (args, kwargs), suitable for calling
the original function.
"""
positional_args: list[Any] = []
keyword_args: dict[str, Any] = {}
seen_var_positional = False
# Use enumerate() so we can skip the first parameter if it's context.
for idx, (name, param) in enumerate(self.signature.parameters.items()):
# If the function takes a RunContextWrapper and this is the first parameter, skip it.
if self.takes_context and idx == 0:
continue
value = getattr(data, name, None)
if param.kind == param.VAR_POSITIONAL:
# e.g. *args: extend positional args and mark that *args is now seen
positional_args.extend(value or [])
seen_var_positional = True
elif param.kind == param.VAR_KEYWORD:
# e.g. **kwargs handling
keyword_args.update(value or {})
elif param.kind in (param.POSITIONAL_ONLY, param.POSITIONAL_OR_KEYWORD):
# Before *args, add to positional args. After *args, add to keyword args.
if not seen_var_positional:
positional_args.append(value)
else:
keyword_args[name] = value
else:
# For KEYWORD_ONLY parameters, always use keyword args.
keyword_args[name] = value
return positional_args, keyword_args