Repository navigation
feat(core): Enhance reliability of structured output degradation path - #2697
Conversation
c8bbd73 to
6e5800b
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR enhances the reliability of the structured-output fallback path in ReActAgent. When the model does not support native structured output (response_format), a synthetic generate_response tool is injected; however, the model could previously ignore it and emit free text, leaving the caller without structured data. The fix introduces three mechanisms: (1) persistent enter/exit system-reminder banners that prime the model about the active mode, (2) a force-retry strategy — ToolChoice.Specific for OpenAI, prompt-reminder for GLM/MiniMax — capped at 3 retries, and (3) context compression that strips SO-related messages after completion. The implementation is well-structured, thoroughly tested (11 new test cases), and solves the problem described in issue #2696. A few design concerns around persistent reminder accumulation and an optimistic capability default warrant attention.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
76c7724 to
3d49478
Compare
This comment was marked as outdated.
This comment was marked as outdated.
合并 PR agentscope-ai#2697,增强结构化输出降级路径、强制 generate_response 调用,并兼容主线消息上下文持久化逻辑。
|
跟进一下这个 PR 的进度。 现状核对:6 commits / 9 files,目前只有机器人 COMMENTED,没有人工 approve;分支落后 main 20 个提交;关联的 issue #2696 仍为 open。 这个改动针对的是结构化输出降级路径的可靠性(模型不支持原生 response_format 时,强制调用 generate_response 并注入模式提示,避免模型自由发挥或陷入反复重试)。从下游使用看这类问题确实存在——我们 fork 里长期带着这份实现跑。 想请维护者/作者确认是否有已知阻塞,例如:
如果方向已经不被接受,也建议在 issue #2696 里明确说明,免得下游继续依赖这份实现。如果需要我这边补充下游的实际使用数据(什么模型、什么触发条件下会走到降级路径),我可以补到这条 PR 里。 |
…lback calls The fallback structured-output path injects a persistent <system-reminder> when entering tool mode. When the model produced no result (empty response or stream failure), that reminder and the flipped so_tool_active flag were still persisted, leaving durable state that claimed the mode was active despite no output. Roll the injected reminder back on these no-result exits so the durable context matches the other empty-response paths and persists only the user input.
…ing, strip on give-up Strategy-B prompt reminders (providers without ToolChoice.Specific, e.g. GLM/MiniMax) were appended on every forced retry and only cleaned on the success path, so they stacked up to three per call and accumulated without bound across calls that gave up. - Inject by remove-then-add so at most one reminder is in context at a time; this also cleans leftovers persisted by a previous give-up call. - Strip reminder-marked messages when the loop gives up after three forced retries. The persistent enter banner and so_tool_active flag are kept: the turn's interaction is retained in durable state, and the exit banner on the next normal call closes the mode. - Add regression tests: reminder counts across retries ([0, 1, 1]) and durable-context assertions after give-up (0 reminders, 1 enter, 1 exit banner).
… option - OpenAIModelProviderSupport.applyAdvancedOptions now reads the supportsToolChoiceSpecific boolean option, mirroring nativeStructuredOutput, so users targeting OpenAI-compatible providers that only support tool_choice="auto" can configure the flag without subclassing. - Extend OpenAIModelProviderTest.createUsesModelCreationContext to cover the new option. - Cover AgentState.so_tool_active in AgentStateTest (default, builder, setter, JSON round-trip, omitted-field fallback). - Restore supportsToolChoiceSpecific=true in MockModel.reset().
16a0e41 to
a0bf93d
Compare
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Delta re-review of the new author commit a0bf93d2 since my last review on a0c49d70. The commit is polish, not behaviour change: it documents why the persistent enter banner is deliberately kept while the transient force reminders are stripped on give-up, adds a JSON round-trip test for the reminder metadata types, and documents the supportsToolChoiceSpecific opt-out for OpenAI-compatible gateways in both the EN and ZH model docs. This closes the loop on the state-leak concerns raised in the previous round — nothing here blocks the PR.
Findings
- [Info]
agentscope-core/src/test/java/io/agentscope/core/state/AgentStateTest.java:185— good test: it pins the exact assumption the give-up cleanup depends on (Boolean.TRUE.equalson a metadata value that may have come back from a durable store) rather than just asserting the round-trip is lossless. One gap:STRUCTURED_OUTPUT_REMINDER_TYPEis asserted to survive as theString"PROMPT"; if the writer side ever persists an enum name of a different shape, this assertion tracks the implementation instead of the contract. Consider asserting on the enum's name constant rather than a literal, or dropping that line since the comment already says the marker is informational and never read for cleanup. - [Info]
agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:1418— the comment now explains the enter/exit banner asymmetry well. Since this is precisely the kind of invariant a later "simplify the cleanup" change would break, it would be worth naming the test that protects it (the give-up/strip test) in the comment, so the two stay in sync. - [Info]
docs/v2/en/docs/building-blocks/model.md:421(and the mirrored ZH section) — the new "Providers without specifictool_choicesupport" section is the right documentation to add, and the failure mode is stated concretely (retry a constraint the gateway never applies, loop, lose structured data). Minor: the ZH and EN blocks are not literal mirrors — EN says the option "is also available as a provider-config advanced option", ZH phrases it as an additional sentence; worth keeping the wording aligned so neither drifts.
Verdict
No blocking findings. The remaining item on my side from earlier rounds was the give-up-path state cleanup, and the added round-trip test plus this comment make the intent explicit. Rebase onto main when convenient so CI can re-run against the current tree.
Automated review by github-manager-bot
# Conflicts: # agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai/src/main/java/io/agentscope/extensions/model/openai/OpenAIChatModel.java # agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai/src/main/java/io/agentscope/extensions/model/openai/OpenAIModelProviderSupport.java # agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai/src/test/java/io/agentscope/extensions/model/openai/OpenAIModelProviderTest.java
|
Assign to @wahllllll (Review) |
|
Second pass over First, the Kimi fix in Three merge leftovers, fix attachedI opened xzxiaoshan#1 (
Four things worth deciding before merge1. The
The consequence is worth a sentence somewhere though: anyone pointing an OpenAI-compatible model at a self-hosted or gateway URL — vLLM, an internal gateway, direct Moonshot — silently moves off the hard 2. The reminder text is regenerated identically each round, and the hard constraint is gated on
The three-round budget is real, but the pressure on the model does not increase — rounds 2 and 3 only re-append the model's own rejected answer. Your 3. Rejected answers are persisted; the reminder isn't.
4. Not a defect — you updated the class javadoc in step, so it's deliberate, and Verification
|
|
Verified
Counts agree: I've closed xzxiaoshan#1 as superseded — no point leaving a conflicting PR sitting in your fork. Re-anchoring the four open items on the new head, since my earlier comment was written against
None of these block the merge on my side. 1 and 4 are release-notes material; 2 and 3 are design calls that are yours to make. |
Brings in agentscope-ai#2697 (structured-output fallback determinism) and agentscope-ai#3129. Conflict resolution: ReActAgentStructuredOutputTest.java — both sides appended test suites at the end of the class (ours: prose/guard/ unknown-domain/retry-prompt; agentscope-ai#2697's: tool_choice forcing and request-local reminder tests) plus overlapping imports. Kept both suites and both import sets; closed the MathAnswer helper before the incoming tests. Semantic integration check (auto-merged ReActAgent.java): the two retry mechanisms are disjoint by guard conditions — native path runs this PR's validation retry (nativeResponseFormat != null, soTool == null), fallback path runs agentscope-ai#2697's forced-retry loop (soTool != null); isNonDegradableFailure and the extraction seam are intact. Verified by the focused structured-output suite: 48 tests green including both sides' cases.
Brings main (incl. agentscope-ai#2697, agentscope-ai#3324, agentscope-ai#2751, agentscope-ai#3129) into the branch. Only conflict: ReActAgentStructuredOutputTest.java — this branch's added test (testToolBasedExtractionPreservesMessageIdentity) sat exactly where agentscope-ai#2697 later appended its new tests; kept both sides (our test plus the incoming suite) and both import sets. ReActAgent.java auto-merged. Verified: ReActAgentStructuredOutputTest 16 tests green including both this branch's identity test and the merged-in tests.
Summary
Structured-output fallback could finish without structured data when the model skipped the synthetic
generate_responsetool. This PR makes that path deterministic while keeping the request and durable context clean.Fixes #2696
Fixes #3393
Fixes #641
Fixes #1103
Fixes #1699
What changed
<system-reminder>that tells the model it must callgenerate_response:state.contextMutable(), hooks, middleware, session persistence, or later calls.generate_response, reasoning is retried up to 3 times:supportsToolChoiceSpecific() = truereceiveToolChoice.Specific("generate_response")on retry.generate_responsetool remains per-call and is not registered in the shared toolkit, so concurrent structured-output calls do not interfere.Model.supportsToolChoiceSpecific()defaults tofalse; custom or unknown models never receive namedtool_choiceunless they explicitly opt in.false.Compatibility
AgentStatefield was added for structured-output mode.supportsToolChoiceSpecificis additive.