Skip to content

Reject kwargs keys that collide with named tool parameters - #4709

Closed
mikemikimike wants to merge 1 commit into
openai:mainfrom
mikemikimike:fix-kwargs-collision-4669
Closed

mikemikimike wants to merge 1 commit into
openai:mainfrom
mikemikimike:fix-kwargs-collision-4669

Conversation

@mikemikimike

Copy link
Copy Markdown

Summary

FuncSchema.to_call_args could silently overwrite a validated named argument, or produce an invalid Python call, when a **kwargs key collided with a named function parameter.

This change rejects those collisions with ModelBehaviorError before invocation. Non-conflicting **kwargs continue to be passed through unchanged.

Testing

  • uv run --frozen pytest tests/test_function_schema.py -q (41 passed)
  • uv run --frozen ruff check src/agents/function_schema.py tests/test_function_schema.py
  • git diff --check

Mypy was attempted but did not complete on the local Windows environment.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d2480b4539

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

for idx, (name, param) in enumerate(self.signature.parameters.items())
if not (self.takes_context and idx == 0)
and param.kind
in (param.POSITIONAL_ONLY, param.POSITIONAL_OR_KEYWORD, param.KEYWORD_ONLY)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude positional-only names from collision checks

For a supported callable such as def func(value: int, /, **kwargs: int), the input {"value": 1, "kwargs": {"value": 9}} is valid: Python binds the first value positionally and places the second in kwargs. Including POSITIONAL_ONLY here instead raises ModelBehaviorError, preventing a valid function-tool invocation; restrict collision detection to parameters that can actually bind by keyword.

AGENTS.md reference: AGENTS.md:L194-L194

Useful? React with 👍 / 👎.

@seratch

seratch commented Aug 27, 2026

Copy link
Copy Markdown
Member

Thanks for the fix. #4674 addresses the same #4669 bug and already preserves the valid positional-only case.

This implementation includes positional-only parameter names in the collision set, so it rejects valid Python calls such as def f(value, /, **kwargs) with kwargs={"value": ...}. Rather than maintain competing implementations, I am closing this in favor of #4674.

@seratch seratch closed this Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants