← Back to Pull requests

fix(anthropic): omit incompatible tool schemas #2338

Open
unknown opened this pull request with 258 lines diff across 3 files
View on GitHub
unknown unknown commented on Jul 29, 2026 03:40 UTC
Author

Resolves #2328.

Problem

The official Anthropic API rejects a request when an MCP tool has oneOf, anyOf, or allOf at the root of its input schema. One such tool can block an otherwise unrelated prompt.

Change

  • Filter incompatible tools only for requests to the official Anthropic endpoint, in both regular and streaming paths. Equivalent official URLs, including explicit port :443, are handled; custom endpoints keep their original tools.

  • Preserve the prompt-cache marker on the last surviving tool and clear a forced tool choice only if its selected tool was omitted.

  • Report omitted tool names through llm.notice to native and requester callers, forward them through the production v2 adapter, and publish an agent warning.

  • Add focused tests for filtering, endpoint handling, cache markers, tool choice, streaming, and notices.
  • The rebase onto current main drops the legacy packages/kosong portion because upstream removed that package in #4599. The active agent-core-v2 implementation remains in this PR.

    Verification

  • On head e66d9c38d, affected Anthropic, model adapter, and agent requester tests: 91/91 passed. The two new adapter/warning tests failed before the follow-up and passed after it.

  • @moonshot-ai/agent-core-v2 typecheck and staged oxlint: passed.

  • The earlier full package run on head 74c40e48b passed 7,789 tests and failed 12 in four AgentSwarm/FullCompaction files. Three of those files passed in a serial replay; one compaction timeout remained. Representative failures, including that compaction case, passed in isolation on both the exact upstream base and the PR checkout. No green full-suite claim is made for the new head.

  • lint:imports still reports the existing violation in unchanged src/human/agent/origin.ts. GitHub Actions workflows for this fork require maintainer approval before remote checks run.
  • AI assistance disclosure

    This patch and PR text were AI-assisted using OpenAI Codex. The contributor remains responsible for reviewing and understanding the submitted changes.

    Diff: 258 lines (+193 / -65) across 3 files Reviewer: ousamabenyounes Review duration: 179748m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.51) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.51 · 258 lines diff across 3 files
    0.51
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.332
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #2338"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% 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: 51.2% (MEDIUM) · Higher = larger blast radius
    51.2%
    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: 40.9% · Lower = rushed or shallow review
    40.9%
    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: 30.2% · Safe to merge
    30.2%