← Back to Pull requests

feat(agent): add opt-in ToolCall argument validation gate before dispatch (T31) #149

Closed
unknown closed this pull request without merging on Oct 10, 2026 14:06 UTC
View on GitHub
unknown unknown commented on Oct 10, 2026 08:52 UTC
Author

Targets #134 (T31). First of the two PRs announced in the claim comment.

What

Opt-in (validateToolArguments, default false) validation of tool-call arguments
against the tool's declared input schema, in AgentToolNode's baseHandler — after
resolve() and before executeToolByType(), so the single insertion point covers
sync, async and wrapSyncToolsAsAsync dispatch.

Because the interceptor chain and the dynamic resolver both run outside/before the
baseHandler, the gate always validates the final arguments against the final
schema — the acceptance item "interceptor 改写后/换 Schema 后校验最终执行版本" holds
by construction, with no extra re-validation logic.

Design notes

  • Validator: hand-rolled closed-rule validator (JSON parse / required / type /

  • enum / numeric range / additionalProperties: false / null type handling) over the
    rule set defined in the issue — zero new runtime dependencies (Jackson databind
    is already on the classpath via argi-graph-core). $ref nodes are skipped rather
    than resolved, so remote references can never be fetched and recursion is bounded
    by the finite schema document. If reviewers prefer wiring
    com.networknt:json-schema-validator (already version-managed in the root pom)
    instead, the swap is local to ToolArgumentValidator.
  • Failure protocol: ToolCallResponse with status=error and metadata carrying

  • errorCode + safe fieldPath; argument values are never echoed (asserted in
    tests). Per the discussion in #134, no structured error protocol is introduced
    here — that stays with T38.
  • Sub-agents: options are not propagated by SubAgentInterceptor, matching how

  • wrapSyncToolsAsAsync behaves today.

    Scope vs. remaining (PR2)

    Covered here: parse + schema rules above, sync/async paths, opt-in plumbing
    (Builder → DefaultBuilder → AgentToolNode).
    Left for PR2 per the issue: byte/depth/collection resource limits, local $ref
    expansion, hardened sanitization tests.

    Tests

  • ToolArgumentValidatorTest (16): every rule incl. nested paths ($.user.age),

  • array indexes ($.tags[1]), value-free failure messages, malformed schema
    fail-closed, $ref skip.
  • ToolArgumentValidationGateTest (7): rejection before callback (invocation count

  • = 0) with metadata assertions, illegal JSON, valid pass-through, default-off
    legacy behavior, async path gating, and interceptor-rewrite validation (original
    args valid → rewritten args rejected, proving post-rewrite validation).
  • Full local regression: argi-graph-core 579 + argi-agent-framework 754 tests,

  • 0 failures (three pre-existing Windows-only env failures in
    FileSystemStoreTest/FilesystemInterceptorTest/FileSystemToolsTest are excluded and
    reproduce identically on a clean f3bcbef baseline — symlink privileges / drive
    relativize, unrelated to this change).
  • checkstyle 0 violations, spotless clean, license headers byte-identical to

  • existing files.

    Diff: 369 lines (+276 / -93) across 4 files Reviewer: yuluo-yx Review duration: 313m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 369 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #149"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%