Skip to content

Python: reject positional arguments in Monty typed tool calls - #10227

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:monty-keyword-only-tool-calls
Nov 10, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:monty-keyword-only-tool-calls

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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, so ty accepted positional calls. The bridge then discarded the positional arguments and invoked the host tool with its defaults.

Description & Review Guide

  • What are the major changes?
    • generate_type_stubs declares every tool parameter keyword-only (leading *). ty now rejects positional calls before any code runs, so no host tool runs for that execution.
    • The stub declares only the parameters guest code can supply. *args/**kwargs, self and an injected FunctionInvocationContext parameter are left out (_run_code passes each tool's schema properties), so typed calls to such tools no longer need parameters the guest cannot provide.
    • InlineCodeBridge._schedule_direct_tool resumes the guest with a TypeError when positional arguments still arrive (for example when type checking is bypassed), instead of dropping them.
    • Updated the Monty README and 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, *args or **kwargs.
  • What is the impact of these changes?
    • Typed positional guest calls now fail with a clear error instead of silently running with defaults. Typed keyword calls to tools with an injected context, self, *args or **kwargs now type-check; before, ty required those parameters, so only call_tool(...) worked for them. Other keyword calls, call_tool(...) and tools without parameters are unchanged. Samples and instructions already use keyword arguments.
    • The full Monty test suite passes with pydantic-monty 1.0.0, 1.4.0 and 1.5.0.
  • What do you want reviewers to focus on?
    • Whether rejecting positional calls (previously accepted, then silently dropped) should carry the [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

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, tests, documentation, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 *) so ty rejects positional calls pre-execution.
  • Add a runtime guard in InlineCodeBridge to 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

Comment thread python/packages/monty/README.md Resolved
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Nov 10, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
Merged via the queue into microsoft:main with commit 2c4f008 Nov 10, 2026
52 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the monty-keyword-only-tool-calls branch November 10, 2026 16:47

This branch was previously deployed

1 inactive deployment
github-app-auth — cfcb68b9 Deployed Nov 10, 2026 by eavanvalkenburg via add_label #27479
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants