Repository navigation
Python: reject positional arguments in Monty typed tool calls - #10227
Conversation
Declare the generated Monty tool stubs keyword-only so type checking rejects positional guest calls before any code runs. Fail closed in the bridge when positional arguments still reach a direct tool call, instead of dropping them and running the host tool with its defaults.
Mangesh Raut (mangeshraut712)
left a comment
There was a problem hiding this comment.
Making the stubs keyword-only and failing closed in _schedule_direct_tool both look right to me. One thing in the stub loop: now that the stub is effectively the call contract, it doesn't match the tool's actual input model.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
Aligns Monty’s typed tool-call behavior with the documented “keyword-only” contract by making positional arguments fail loudly (at type-check time when available, and at runtime otherwise), and adds regression tests/docs to prevent silent argument dropping.
Changes:
- Generate keyword-only type stubs for all tool parameters (inject
*) sotyrejects positional calls pre-execution. - Add a runtime guard in
InlineCodeBridgeto reject positional args that bypass type-checking. - Add/adjust tests and docs to cover stub shape + runtime behavior for positional vs keyword calls.
| File | Description |
|---|---|
| python/packages/monty/agent_framework_monty/_monty_bridge.py | Makes generated stubs keyword-only and rejects positional args at runtime. |
| python/packages/monty/tests/monty/test_monty_runtime.py | Adds runtime tests ensuring positional calls fail before any host tool runs. |
| python/packages/monty/tests/monty/test_monty_codeact.py | Adds regression tests for bridge behavior + updates stub-shape assertions. |
| python/packages/monty/tests/monty/conftest.py | Adds a parametrized fixture to test different host tool signature styles. |
| python/packages/monty/README.md | Documents keyword-only requirement and positional-arg rejection. |
| python/packages/monty/AGENTS.md | Updates internal docs to reflect keyword-only stubs + bridge enforcement. |
Review effort: Lite
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 9e69c2d7ad0c
Model: gpt-5.6-sol
Overview
The PR makes direct typed Monty tool calls keyword-only in generated stubs and adds a fail-closed runtime guard for executions that bypass type checking. Regression coverage verifies pre-execution rejection, zero host side effects, bypassed-check behavior, keyword/default handling, and the unchanged call_tool fallback. No new Critical, High, or Medium issue remained after source-level reconciliation and deduplication against the existing unresolved feedback.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Declare only the parameters guest code can supply in the generated Monty tool stubs. Never declare *args or **kwargs, and leave out parameters that FunctionTool does not accept as keywords, such as an injected context or self, so typed keyword calls to those tools type-check. Explain why the positional-argument error stays detailed and reword the README sentence.



Motivation & Context
Monty documents typed host-tool calls as keyword-only (
await tool_name(**kwargs)), with arguments checked before execution, and its instructions tell the model to always use keyword arguments. The generated type stubs did not declare the parameters keyword-only, sotyaccepted positional calls. The bridge then discarded the positional arguments and invoked the host tool with its defaults.Description & Review Guide
generate_type_stubsdeclares every tool parameter keyword-only (leading*).tynow rejects positional calls before any code runs, so no host tool runs for that execution.*args/**kwargs,selfand an injectedFunctionInvocationContextparameter are left out (_run_codepasses each tool's schema properties), so typed calls to such tools no longer need parameters the guest cannot provide.InlineCodeBridge._schedule_direct_toolresumes the guest with aTypeErrorwhen positional arguments still arrive (for example when type checking is bypassed), instead of dropping them.AGENTS.md. Updated the three stub-text assertions and added regression tests: stub shape, the bridge guard with a fake snapshot, and real-runtime tests for positional-or-keyword and keyword-only host tools (positional call rejected before any host call, rejected at runtime with type checking bypassed, keyword call still works with defaults) and for tools with an injected context,self,*argsor**kwargs.self,*argsor**kwargsnow type-check; before,tyrequired those parameters, so onlycall_tool(...)worked for them. Other keyword calls,call_tool(...)and tools without parameters are unchanged. Samples and instructions already use keyword arguments.[BREAKING]marker. I treated it as a bug fix because those calls never delivered their arguments.Related Issue
N/A - no linked issue. This makes the implementation match the documented contract; regression tests are included.
AI Assistance
AI assistance details: implementation, tests, documentation, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.