Skip to content

fix: return invalid tool arguments to the model for correction - #30

Open
cyyecao-lappland wants to merge 1 commit into
mozilla-ai:mainfrom
cyyecao-lappland:fix/recover-invalid-tool-arguments-20261002
Open

cyyecao-lappland wants to merge 1 commit into
mozilla-ai:mainfrom
cyyecao-lappland:fix/recover-invalid-tool-arguments-20261002

Conversation

@cyyecao-lappland

Copy link
Copy Markdown

Description

Malformed JSON currently aborts the agent before it can return a tool error, and non-object arguments to final_answer can terminate the run with an error string. Catch JSON decoding failures and require a JSON object before casting or execution. Append tool feedback using the original call ID and continue, including for invalid final_answer calls. Keep the existing empty-string behavior for zero-argument tools and document the recovery behavior.

Validation

  • Malformed-argument baseline: 12 failed, 2 passed.
  • Final regression suite: 16 passed, including correction in later turns and valid calls in the same response.
  • Full unit/snapshot suite: 202 passed, 2 unchanged gateway failures.
  • Full source/test Ruff lint and formatting pass; changed-file mypy passes.

The local environment uses Python 3.11 and mcp==1.30.0: current main cannot import with MCP 2.x (tracked in #22). Full unit/snapshot runs retain two pre-existing gateway cases failing with the installed any-llm-sdk 1.30.0 (tracked in #23). Full mypy retains three errors in the unchanged A2A executor on Python 3.11; these were reproduced on main. The repository pre-commit launcher was attempted but could not finish creating its notebook hook environment: it expected Python 3.13 and detected 3.13.15. No notebook is changed. Full source/test Ruff lint and formatting and mypy of the changed source/test pass.

PR Type

  • Bug Fix

Relevant issues

Fixes #29

Checklist

  • I understand the code I am submitting.
  • I have added unit tests that prove my fix/feature works.
  • I have run this code locally and verified it fixes the issue.
  • New and existing tests pass locally. See the unchanged baseline failures above.
  • Documentation was updated where necessary.
  • I have read and followed the contribution guidelines.
  • AI Usage:
    • No AI was used.
    • AI was used for drafting/refactoring.
    • This is fully AI-generated.

AI Usage Information

  • AI Model used: GPT-6

  • AI Developer Tool used: Codex desktop

  • This contribution was autonomously authored and tested with Codex (GPT-6), at the account owner's explicit request. Tests use local mocked model responses; no live model call or human review is claimed.

  • I am an AI Agent filling out this form.

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.

Invalid JSON tool arguments abort the run or prematurely return a final-answer error

1 participant