Skip to content

fix(tools): report undeclared params instead of silently dropping them - #330

Open
raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/param-report
Open

raymondginger2018-sudo wants to merge 1 commit into
HKUDS:mainfrom
raymondginger2018-sudo:pr/param-report

Conversation

@raymondginger2018-sudo

Copy link
Copy Markdown
Contributor

Summary

prepare_call already rejected a tool call whose parameters failed validation, before execute. It did not reject — or even mention — undeclared keys: _cast_object dropped them, so a caller that invented a field got a normal-looking success and repeated the same malformed call.

That is a correctness problem, not a crash: the caller's input was silently altered. This change reports the unknown keys and gives every rejection one message shape.

Changes

  • core/agent_runtime/tools/base.py
    • format_invalid_input(tool_name, errors) — one message: Error: INVALID_INPUT, the violated contract, one line per offending field (carrying the accepted values where the schema declares them), then Nothing was run. Fix the field(s) above and call <tool> again.
    • Tool.unknown_param_names(params) — keys the schema never declared, honouring the same escape hatches _cast_object honours (no properties, or additionalProperties: true).
  • core/agent_runtime/tools/registry.py
    • prepare_call lists unknown keys first, then validation errors, and routes both through format_invalid_input.
  • tests/test_tool_schema_precheck.py (new, 10 cases) — strict and pass-through tools; unknown keys are reported and never reach execute; invalid enum values carry the accepted set; free-form schemas stay unchanged.

Compatibility

  • Valid calls are unchanged; no new dependency or configuration.
  • Unknown keys are still not passed to execute (they never were) — they are now named in the rejection instead of being dropped silently.
  • Schema-less / additionalProperties: true tools accept the same inputs as before.

Note on measured effect

The message shape is ported from the Rotifer Protocol CLI. An A/B against deepseek-flash did not show a correction-rate gain (19/20 old vs 20/20 new, Wilson intervals overlapping), so this stands on correctness — not altering the caller's input silently — rather than on a measured model-behaviour win.

Tests

10 passed on a clean worktree of main at c0395516; pre-commit run --files … (ruff 0.15.21 + ruff-format) clean.

Unrelated: tests/test_agent_runner_kernel.py::test_environment_context_is_resolved_and_xml_safe fails on this Windows checkout on the base commit too (XML escaping of a temp path containing &); it is not touched by this PR.

`_cast_object` discarded any argument the tool's schema did not declare, so a
caller that invented a field got a normal-looking success and repeated the
mistake. Report the key instead, and give every rejection one shape: an error
code, which contract was violated, one line per offending field (carrying the
accepted values where the schema declares them), and an explicit "nothing was
run".

The pre-check itself already existed — `prepare_call` returned before
`execute`. What is new is that unknown keys now reach that check at all.

Message shape ported from the Rotifer Protocol CLI (measured 2026-11-27).
An A/B against deepseek-flash did NOT show a correction-rate gain (OLD 19/20
vs NEW 20/20, Wilson intervals overlapping), so this stands on correctness —
silently altering the caller's input — not on measured model behaviour.

Tests: tests/test_tool_schema_precheck.py (10 cases).

This branch has not been deployed

No deployments
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.

1 participant