You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
**kwargs tools nest under kwargs; flat model args silently invoke with empty kwargs #5170
@function_tool on a **kwargs function (with strict_mode=False) builds a schema with a nested kwargs object property. Models typically emit flat argument objects ({\"a\": 1, \"b\": \"x\"}). Those are accepted by the Pydantic wrapper but the tool is invoked with empty kwargs (got=[]), silently dropping the payload.
Non-strict **kwargs tools should expose open object parameters the way models emit them (root additionalProperties, flat keys), or reject flat payloads instead of calling with {}.
function_schema turns **kwargs into a nested object property named after the parameter. With strict_mode=False the model is a normal Pydantic model, so extra keys are ignored. to_call_args then reads that empty nested dict and calls the function with no keyword arguments. The tool returns success and the payload is gone.
With the default strict schema, decoration raises UserError: "additionalProperties should not be set for object types..." That comes from ensure_strict_json_schema seeing the open object inside the nested property. The message points at an old Pydantic version. The cause is **kwargs.
Fix, in src/agents/function_schema.py:
Non-strict. In the VAR_KEYWORD branch, do not add a field named kwargs. Build the args model with extra="allow" so named parameters stay properties and any other key is kept. Put additionalProperties on the root schema, not under a kwargs property. A function def f(a: int, **kwargs) should accept {"a": 1, "b": "x"} and bind b into kwargs.
Call path. In to_call_args, for VAR_KEYWORD, read those extra keys (model_extra / __pydantic_extra__) instead of instance_values["kwargs"]. Run the existing _raise_on_var_keyword_collisions check on that dict, then splat it. If the payload is only the old nested object, {"kwargs": {"a": 1, "b": "x"}}, unwrap that dict so current callers keep working. If flat keys and the nested object are both present, reject the call.
Strict. Before ensure_strict_json_schema, if the function has **kwargs and strict_json_schema is true, raise UserError that says a strict schema cannot take undeclared keys, and that strict_mode=False is the way through. Do not let it fall through to the additionalProperties error.
A test should cover the flat call, the old nested call, a named parameter plus extra keys, and the strict error.
Thanks @goran-revops — your 0.22.3 repro and the flat-vs-nested breakdown match what I saw. The three-part fix (non-strict extra="allow" + read extras in to_call_args with nested unwrap + explicit strict UserError for **kwargs) looks right to me. I’ll wait on maintainer direction before opening a PR so we don’t collide.
Activity
goran-revops commentedon Sep 25, 2026
Reproduced on openai-agents 0.22.3.
function_schematurns**kwargsinto a nested object property named after the parameter. Withstrict_mode=Falsethe model is a normal Pydantic model, so extra keys are ignored.to_call_argsthen reads that empty nested dict and calls the function with no keyword arguments. The tool returns success and the payload is gone.{"a": 1, "b": "x"}->got=[]{"kwargs": {"a": 1, "b": "x"}}->got=[('a', 1), ('b', 'x')]With the default strict schema, decoration raises
UserError: "additionalProperties should not be set for object types..." That comes fromensure_strict_json_schemaseeing the open object inside the nested property. The message points at an old Pydantic version. The cause is**kwargs.Fix, in
src/agents/function_schema.py:Non-strict. In the
VAR_KEYWORDbranch, do not add a field namedkwargs. Build the args model withextra="allow"so named parameters stay properties and any other key is kept. PutadditionalPropertieson the root schema, not under akwargsproperty. A functiondef f(a: int, **kwargs)should accept{"a": 1, "b": "x"}and bindbintokwargs.Call path. In
to_call_args, forVAR_KEYWORD, read those extra keys (model_extra/__pydantic_extra__) instead ofinstance_values["kwargs"]. Run the existing_raise_on_var_keyword_collisionscheck on that dict, then splat it. If the payload is only the old nested object,{"kwargs": {"a": 1, "b": "x"}}, unwrap that dict so current callers keep working. If flat keys and the nested object are both present, reject the call.Strict. Before
ensure_strict_json_schema, if the function has**kwargsandstrict_json_schemais true, raiseUserErrorthat says a strict schema cannot take undeclared keys, and thatstrict_mode=Falseis the way through. Do not let it fall through to theadditionalPropertieserror.A test should cover the flat call, the old nested call, a named parameter plus extra keys, and the strict error.
michaelkillgta commentedon Sep 25, 2026
Thanks @goran-revops — your 0.22.3 repro and the flat-vs-nested breakdown match what I saw. The three-part fix (non-strict
extra="allow"+ read extras into_call_argswith nested unwrap + explicit strictUserErrorfor**kwargs) looks right to me. I’ll wait on maintainer direction before opening a PR so we don’t collide.michaelkillgta commentedon Sep 25, 2026
Thanks @jbeckwith-oai — appreciate the fix in #5174.