Repository navigation
Description
Describe the bug
After per-call model selection (#2097), the synthetic structured-output retry in ReActAgent still checks the build-time model.supportsToolChoiceSpecific(), although the request is served by getModel(rc). When their capabilities differ, the selected model either receives an unsupported named-tool constraint or never receives the constraint it supports.
Verified against current main 9e98dfa7648afa67530bb8735cdef14ef6e2560a (2.1.0-SNAPSHOT), without a fallback model, session recording, network service, or model credentials.
To Reproduce
- Build a
ReActAgentwith a default model whosesupportsToolChoiceSpecific()isfalse. - Register a second model under
test:structured-tool-choice. It supports named tool choice, does not support native JSON schema, emits free text on its first request, and callsgenerate_responsewhen a retry specifies that tool. This models a provider needing the existing structured-output forcing path. - Run the public structured call:
ModelRegistry.register("test:structured-tool-choice", selectedModel);
try {
RuntimeContext context = RuntimeContext.builder()
.modelId("test:structured-tool-choice")
.build();
Msg result = agent.call("Return a structured answer", Output.class, context).block();
assertTrue(result.hasStructuredData());
} finally {
ModelRegistry.unregister("test:structured-tool-choice");
}The selected model never receives ToolChoice.Specific("generate_response"), even on retries; the call gives up without structured data. Reverse the capabilities (default true, selected false) and the second request instead sends a named-tool constraint to the model that does not support it. The offline model rejects that request with IllegalArgumentException: named tool choice is unsupported.
A four-case regression using the real public call(String, Class, RuntimeContext) API produces:
| Default supports named choice | Selected supports named choice | Original main |
|---|---|---|
| false | false | passes: prompt-reminder retry |
| false | true | fails: retry never forces the tool; no structured result |
| true | false | fails: unsupported named-tool constraint sent |
| true | true | passes: forced-tool retry |
The complete parameterized offline regression will be included with the linked fix PR. It checks the structured result, the selected model's outgoing retry options and request count, and that the default model was never invoked.
Expected behavior
The forced retry should use the capability of the per-call selected model, consistently with native structured-output routing and the model actually serving the request. Calls without modelId should retain existing behavior.
Error messages
Final regression on unchanged production code: 4 tests, 2 failures, 0 errors. The mismatching cases fail with:
the selected model must complete the retry ==> expected: <true> but was: <false>Unexpected exception thrown: java.lang.IllegalArgumentException: named tool choice is unsupported
Command from the repository root (with JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8):
mvn -B -T1C -pl :agentscope-core -am -Dtest=ReActAgentPerCallStructuredToolChoiceTest -Dsurefire.failIfNoSpecifiedTests=false test
Environment
- AgentScope Java: 2.1.0-SNAPSHOT, main
9e98dfa7648afa67530bb8735cdef14ef6e2560a - Java: Temurin 17.0.15; Maven: 3.9.12
- OS: Windows; reproduction is portable and uses local model fakes only
Additional context
The remaining build-time probe is in ReActAgent.CallExecution.reasoning, in the condition guarding ToolChoice.Specific after soForceToolChoiceCount > 0. Native structured-output routing and actual model execution already resolve the per-call model.
I checked the current source and matching open/closed issues/PRs. #3881 forwards capability methods through recording/failover wrappers; its patch does not touch this build-time probe, and this reproduction uses neither wrapper. This report is about the per-call selection mismatch, not that existing wrapper work.
I am implementing and will submit the minimal fix with the matrix regression and relevant checks. Please assign this issue to @pengmoubuaixuexi if appropriate; I am taking responsibility for the fix rather than requesting someone else implement it. AI assistance is being used for investigation, implementation and diff review; executed checks and their limits will be disclosed in the PR.
Activity