Repository navigation
fix(core): forward model capability probes through the session-recording and failover wrappers - #3881
Open
birdie7761 wants to merge 1 commit into
Open
birdie7761 wants to merge 1 commit into
birdie7761 wants to merge 1 commit into
Conversation
…ing and failover wrappers SessionModels.Recorded (assembled whenever session recording is active) and the failover wrapper (assembled whenever fallbackModel is configured) forward only a hand-picked subset of Model's capability probes, so the rest silently leak the interface defaults. Three omissions accumulated across feature PRs: getToolSearchMode (agentscope-ai#3680, both wrappers), supportsToolChoiceSpecific (agentscope-ai#2697, both wrappers), and supportsNativeStructuredOutputWithTools (failover wrapper only - the interface default derived it from the forwarded plain flag, which is wrong for models whose two flags diverge). For getToolSearchMode the effect was user-visible: DEFERRED/CLIENT models silently degraded to FUNCTION behind either wrapper, so ToolSearchMiddleware hid the catalog instead of exposing it with deferred loading, and the native protocol implementations of AnthropicChatModel/OpenAIResponsesChatModel were dead paths. The other two probes are exposed to ON_MODEL_CALL middlewares via ModelCallInput.model(), which is the wrapper. Forward all three probes and document the remaining heterogeneous-failover limitation (a DEFERRED-shaped surface cannot be served by a CLIENT fallback) in ToolSearchMiddleware's Javadoc and docs/v2 EN/ZH. Four regression tests, red-verified pre-fix.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This was referenced Nov 4, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentScope-Java Version
2.1.0-SNAPSHOT (based on
main@0714868cc)Description
#3680 added on-demand tool search. Models opt into a native loading protocol by overriding
Model.getToolSearchMode()—AnthropicChatModelreturnsDEFERRED,OpenAIResponsesChatModelreturns
CLIENT; ordinary function calling remains the interface default (FUNCTION).ToolSearchMiddleware.onModelCallselects the protocol frominput.model().getToolSearchMode().Two agent-internal model wrappers forward only a hand-picked subset of
Model's capabilityprobes, so the rest silently fall back to the interface defaults. Three omissions accumulated
across three feature PRs:
getToolSearchMode(#3680, both wrappers),supportsToolChoiceSpecific(#2697, both wrappers), and
supportsNativeStructuredOutputWithTools(failover wrapper only —the interface default derived it from the forwarded plain flag, which is wrong for models whose
two flags diverge). This PR forwards all three, making both wrappers complete over
Model'scurrent capability surface:
SessionModels.Recorded— assembled byReActAgent.modelForCallwhenever session recordingis active (
sessionLogStoreconfigured with a non-LEGACYsessionHistoryMode);Modelreturned bymodelForCallwheneverfallbackModelis configured.For
getToolSearchModethe effect was user-visible: everyDEFERRED/CLIENTmodel behindeither wrapper was silently degraded to
FUNCTION, soToolSearchMiddleware.onModelCallhidcatalog tools from the request entirely (visible-only surface) instead of exposing them with
deferLoading=true(DEFERRED) ortoolSearch=true(CLIENT). Both wrappers areunconditional in those setups — nothing warns or logs, the native protocol implementations of
the two models become dead paths while the agent keeps working in fallback semantics.
For the other two probes the exposure is the middleware SPI:
ModelCallInput.model()is thewrapper, so any third-party
ON_MODEL_CALLmiddleware reading them gets the derived/defaultvalue even for models that declare otherwise (in-repo consumers read the unwrapped field and
are unaffected). The delegation mirrors the neighboring capability probes
(
delegate.getToolSearchMode()inRecorded,activeModel.get().supportsToolChoiceSpecific()in the failover wrapper).
Compatibility
getToolSearchMode()has exactly two readers in the codebase, both inToolSearchMiddleware.onModelCall(:107,:121);supportsToolChoiceSpecific()has nowrapper-path readers in-repo (its consumers read the unwrapped field). No other component
observes either value, so the behavior change is confined to tool-search requests and the
middleware SPI behind these wrappers.
FUNCTION/falseare unaffected (forwarding a defaultyields the default).
FUNCTIONsemantics switch to the model'sdeclared native protocol — restoring the documented behavior of feat(tool): add on-demand tool search with native provider loading #3680, not changing it.
Modelwrappers inagentscope-core/agentscope-harnessmain sources(verified by sweep); extension models are leaf implementations declaring their own mode.
Known interaction (heterogeneous failover pairs)
The middleware reads the mode once per request from the wrapper (
activeModelat call start —the primary). If the primary fails over, the already-shaped surface is passed to the fallback
unchanged. For a
DEFERREDprimary (Anthropic) failing over to aCLIENTfallback(
OpenAIResponsesChatModel) without a hostedtool_searchserver tool configured,ResponsesRequestMapperrejectsdeferLoadingtools, so the fallback call errors — and sincethe docs forbid combining the middleware with a hosted
tool_searchserver tool, that escapehatch does not exist. This pairing requires the tool-search middleware with native loading and
two different native-protocol models in one failover pair; the pre-fix code reached it only in
degraded
FUNCTIONsemantics (no flags) — i.e. the pre-fix "working" failover was itself thebug: the primary never used its declared protocol. Same-family (
FUNCTIONdefault) fallbacksignore the flag and degrade softly;
DEFERREDfallbacks consume it natively. The limitation isnow documented in
ToolSearchMiddleware's Javadoc anddocs/v2/{en,zh}/docs/building-blocks/tool.md(failover across mixed native protocols:use a function-calling fallback or
nativeLoading=false). Reshaping the surface per servingmodel is an architectural change in the failover path and is deliberately out of scope here.
Tests
Five new cases in
ToolSearchTest. The mode cases and the false-direction capability caseswere red-verified against pre-fix code — verbatim failure output:
(The surface printed is the single
tool_searchschema — the catalog entry was absent, i.e. theDEFERREDmodel had been degraded to visible-onlyFUNCTIONsemantics.)sessionRecordingWrapperPreservesNativeToolSearchModeDEFERREDmodel +sessionLogStore(EVENT_LOG) +ToolSearchMiddlewarereceives the catalog tool in the request withdeferLoading=true(not hidden)failoverWrapperPreservesNativeToolSearchModefallbackModel(failover wrapper active, primary succeeds) still exposes the deferred-loading catalog entrymodelWrappersForwardSupportsToolChoiceSpecificON_MODEL_CALLmiddleware readinginput.model().supportsToolChoiceSpecific()sees the declared value through both wrappers, true and false directions (a fallback-only run exercises the failover wrapper, a no-fallback run theRecordedwrapper); red-verified pre-fix (expected: <[true]> but was: <[false]>)failoverWrapperForwardsStructuredOutputWithToolstrue, with-tools=false) readsfalsethrough the failover wrapper'sWithTools(not the value derived from the forwarded plain flag); the true direction (plain=false, with-tools=true), theRecordedwrapper, and the plain flag are pinned as regressions; red-verified pre-fix (expected: <[false]> but was: <[true]>)modelWrappersOverrideEveryModelDefaultProbeModel'sdefaultmethods and asserts both wrappers (captured live viaModelCallInput.model()) override every one, so a future probe added toModelwithout wrapper forwarding fails here instead of silently leaking the default; red-verified by removing an override (ReActAgent$2 must override Model.supportsToolChoiceSpecific())Regression: full
agentscope-coresuite — 2947 tests, 0 failures, 8 pre-existing skips;spotless:checkclean.