Repository navigation
Description
Describe the bug
JevToolSelectionMiddleware puts the entire input.messages() list — full system
prompt, memory, and complete conversation history — into SystemOneRequest.state
and posts it to POST /v1/systemone on every reasoning step. When the tool set
exceeds the choice limit (254) and is chunked, the same full state is sent twice
per step (initial selection + rerank).
Root cause: onReasoning passes
JevSelectionSupport.messagesState(input.messages()), i.e.
Map.of("messages", List.copyOf(messages)), as the request state. The middleware
already extracts latestUserText from the messages, but uses it only as a
blank-input guard — it is never sent.
In a realistic agent setup (non-trivial system prompt + persistent memory + a few
turns of history) the serialized state is ~32K characters per request. A user turn
with S reasoning steps therefore uploads the full conversation S times (2S when
chunked), even though the decision being made is only "which of these tools fits
the current request".
To Reproduce
- Wrap the Jev call with a size logger and attach the middleware to a ReActAgent
with more optional tools thanmaxTools:
JevToolSelectionMiddleware middleware =
JevToolSelectionMiddleware.builder(request -> {
System.out.println("state bytes: "
+ JevClient.MAPPER.writeValueAsString(request.state()).length());
return client.systemOne(request);
})
.maxTools(3)
.build();
ReActAgent agent =
ReActAgent.builder()
.name("assistant")
.model(model)
.toolkit(toolkit) // > 3 optional tools
.middleware(middleware)
.build();- Run any user turn with a realistic system prompt and accumulated memory/history.
- Observe: every reasoning step logs a state payload equal to the complete
serialized conversation (~32K chars in our setup), and chunked tool sets log it
twice per step.state.messagescontains everything, including the system
prompt and memory.
Expected behavior
The middleware sends only the context the tool-selection decision needs — e.g. the
latest user request and/or a bounded recent message window — not the complete
serialized conversation on every reasoning step.
Error messages
None — this is not a crash. The middleware works as coded; the defect is the
excessive and unnecessary request payload (cost, latency, and data exposure).
Environment (please complete the following information):
- AgentScope-Java Version: 2.0.4-SNAPSHOT
- Java Version: 21
- OS: Windows 11
Additional context
- Impact: (1) payload size and latency on a 5-second-timeout pre-check that sits in
the hot path of every reasoning step; (2) Jev API cost, which scales with input
size; (3) unnecessary exposure of the full system prompt, memory, and history to
a third-party endpoint on every step. - Prior art in the same package:
JevModelRouterMiddlewarealready uses the lean
patternstate = Map.of("userRequest", userText)and makes one decision per
agent invocation. - The existing test
reselectsToolsForEachReasoningStepUsingFullMessages
explicitly asserts the full-messages behavior, and both the EN and ZH docs state
"sends the fullinput.messages()state to Jev" — the behavior is documented but
the design is disproportionate to the decision being made. - Suggested fix: make the request context configurable on the builder, e.g. a
ContextStrategywith a bounded recent window (default, capped by
maxContextMessages/maxContextChars), a latest-user-message mode aligned
withJevModelRouterMiddleware, and the current full-conversation mode kept for
backward compatibility. I am willing to submit a PR along these lines. - Out of scope:
JevAutoModeMiddlewarealso sends the full history, but risk
assessment arguably needs broader context; that can be discussed separately. - Related: Wanted: Tell us your JEV ideas. #3251
Activity
oss-maintainer commentedon Sep 30, 2026
Issue Evaluation
Category:
bug| Status: Confirmed (verified againstmain@01da9e6fb,2.0.4-SNAPSHOT)Every code, test and doc claim in this report checks out. Paths below are relative to repo root;
JEV=agentscope-extensions/agentscope-extensions-judge/agentscope-extensions-jev.Confirmed
input.messages()becomes the request stateJevToolSelectionMiddleware.java:115→JevSelectionSupport.messagesState(input.messages()), which is exactlyMap.of("messages", List.copyOf(messages))(JevSelectionSupport.java:52-57); packed atJevToolSelectionMiddleware.java:151-152/v1/systemoneper reasoning stepJevClient.java:51(endpoint),:111-116(state serialized verbatim),:118-126(POST body)JevToolSelectionMiddleware.java:174+:190-195— the rerank request reuses the samestatevariableJevSelectionSupport.java:33-34—MAX_CHOICE_OPTIONS = 255(API cap enforced atJevClient.java:291-294),MAX_CANDIDATES_PER_CHOICE = 254(254 tools +__none__fills the budget); partitioning at:138-140latestUserTextextracted but never sentJevToolSelectionMiddleware.java:110-113—userTextis only the blank-input guard and is never referenced againJevToolSelectionMiddlewareTest.java:151(reselectsToolsForEachReasoningStepUsingFullMessages), assertingstate.messagessize 2 at:200-206docs/v2/en/jev/index.md:152,docs/v2/zh/jev/index.md:151JevModelRouterMiddlewarelean prior artJevModelRouterMiddleware.java:147—.state(Map.of("userRequest", userText)), one decision per invocation viaonAgent(:86-110) +RuntimeContext(:107)JevAutoModeMiddlewarealso sends full historyJevAutoModeMiddleware.java:132,:212-214Two additions that strengthen the case
ReActAgent.java:2476-2485rebuilds and applies theonReasoningchain inside everyreasoning()iteration, so the upload really is per step, not per turn. But it is skipped when the optional tool count is ≤maxTools(:106) or the latest user text is blank (:111) — so the worst case is one full-conversation upload per step of every ReAct loop that actually has tools to select.ReasoningInput.messagesis built atReActAgent.java:2449-2451viaMessageUtils.prependSystemMessage(...)(MessageUtils.java:214-224), so the system prompt is element 0 followed by the full in-memory context (state.contextMutable(),:2433-2434) — every role and content block, tool results included.SystemOneRequest.stateis an untypedObjectvalidated only for non-null (JevClient.validateRequest,:263-266); the 2..255 limit constrains the tools dimension only.JevClient.java:48defaults to a remote endpoint, so this is third-party transmission of the complete agent context, not an internal call.Assessment: the behavior is documented and test-pinned, so this is a design defect rather than an implementation mistake — the decision being made is "which of these tools fits the current request", and the payload sent to answer it is the entire conversation. Cost, latency on a hot path, and data exposure all scale with history length instead of tool count.
On your proposed fix: a configurable context strategy on the builder (
JevToolSelectionMiddleware.java:232-270currently exposes onlyalwaysIncludeTools,maxTools,confidenceThreshold,failOpen) is the right shape, and keeping the full-conversation mode for backward compatibility is correct sinceJevToolSelectionMiddlewareTest.java:151and both docs pin today's behavior. Two things to settle in the PR: what the default becomes (a bounded window changes what Jev sees, which is an observable behavior change), and whetherJevAutoModeMiddleware(:212-214) stays as-is — we agree with you that risk assessment arguably needs the broader context, so leaving it out of scope is reasonable.Since you offered to submit the PR along these lines, we will not generate a competing fix proposal — please open it and we will review the diff. If you would rather have an automated proposal here first, reply
/approveand we will produce one.Automated evaluation by github-manager-bot
fix(jev): bound the conversation state sent by JevToolSelectionMiddle…
fix(jev): bound the conversation state sent by JevToolSelectionMiddle…
oss-maintainer commentedon Oct 3, 2026
Proposal window closed — no automated PR will be generated, this proposal window here is closed
The 72 h feedback window opened by the evaluation above (
2026-09-30T10:10:10Z, comment5909097492) reached its bound at2026-10-03T10:10:10Zwith no reply on this thread — 0 comments and 0 reactions after that evaluation as of this read — so the offer to produce an automated proposal has lapsed: we are not opening a PR for #3372 and no automated PR will be generated from this thread.The implementation path is already owned by the community. PR #3375 (
fix(jev): bound the conversation state sent by JevToolSelectionMiddleware, authored by @amyaxy, opened2026-09-30T14:18:09Zand declaringFixes #3372) targets exactly the seam the evaluation describes — replacing the fullinput.messages()state thatJevToolSelectionMiddleware.java:115builds and packs per reasoning step with a bounded context, which is the shape the evaluation endorsed. As of this read #3375 is OPEN, not a draft, unmerged, headcc683848269f6f99c91e6b0237c3d7002d283a72,mergeablereported MERGEABLE / clean, last updated2026-09-30T14:58:52Z. Filing a second PR against the same issue is the competing-proposal outcome this window was written to avoid, which is why the proposal is stood down rather than escalated.Nothing here retracts the evaluation. The defect it confirms — every reasoning step serialising the whole conversation, system prompt and tool results included, to the remote endpoint at
JevClient.java:48— was verified againstmainat01da9e6fband stands. The open work is review of #3375, and in particular the two decisions the evaluation named: what the new default context strategy becomes (a bounded window changes what Jev sees, which is an observable behavior change againstJevToolSelectionMiddlewareTest.java:151and both the EN and ZH docs), and whetherJevAutoModeMiddleware.java:212-214stays out of scope.If #3375 is closed without merging and an automated proposal is still wanted here, reply on this issue and the fix will be re-evaluated against whatever
mainlooks like at that point. No action is needed from anyone else.Automated feedback-window maintenance by github-manager-bot
fix(jev): bound the conversation state sent by JevToolSelectionMiddle…