Repository navigation
docs(agui): stop trimming resent transcripts and document incremental input - #4523
Merged
xzxiaoshan merged 2 commits intoDec 1, 2026
Merged
Conversation
… input AguiRequestProcessor asked AgentResolver.hasMemory() before each call and, when it said yes, cut the request down to the messages after the last assistant turn. The probe runs outside the call and only says that some context exists, and the cut is a fixed position that does not hold for every client. Remove both; request messages now reach the agent unchanged. The AG-UI guide documents the two ways to deal with a front end that resends the whole conversation: upgrade CopilotKit to 1.73.1 or later and use messageFilter, or write a middleware that trims the input in onAgentStateReady.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
With the transcript no longer trimmed, a front end that resends its whole history also resends tool results from earlier rounds. While the agent waits for a front-end tool result, ReActAgent rejects such a result with "Invalid tool result IDs" and writes nothing, so every later request that carries it fails the same way. State that in the AG-UI guide next to the migration note.
jujn
approved these changes
Dec 1, 2026
xzxiaoshan
added a commit
to xzxiaoshan/agentscope-java
that referenced
this pull request
Dec 1, 2026
… middleware" This reverts commit 5a3a92f. PR agentscope-ai#3467 returns to the original middleware approach and is kept as a backup. The documentation-only direction was carried by PR agentscope-ai#4523.
This was referenced Dec 1, 2026
juruoO-o
pushed a commit
that referenced
this pull request
Dec 2, 2026
…ripts (#4535) ## Summary AG-UI front ends such as CopilotKit resend the whole conversation on every run. Against an agent that keeps its conversation across calls, each call then appends the history again. #4523 removed the old trimming and left a deduplicating `MiddlewareBase` to applications, because matching resent messages against the agent's state is easy to get wrong and the assistant message ids a client receives are not the persisted ones. This PR ships that middleware, `InputMessageDeduplicationMiddleware`, so applications register it instead of writing their own. Assistant messages are matched by content, because the ids the stream gives them are not the persisted message ids. ## Changes - `InputMessageDeduplicationMiddleware` (AG-UI extension) runs in `onAgentStateReady` and replaces the input with the messages the agent does not hold yet. It looks for the newest message of the agent's conversation that the input repeats and hands the agent only the input after its counterpart. A conversation message is recognized in the input by the tool call or tool result ids it carries, by its text, or by its id when it has no text. An incremental input is left unchanged. While the agent waits for tool results, results it is not waiting for are dropped. When the resent input carries nothing new, the last user message is handed over again under a new id, so the agent answers it again. - The AG-UI guide (EN and ZH) replaces the hand-written middleware outline with the registration: ```java import io.agentscope.core.agui.middleware.InputMessageDeduplicationMiddleware; HarnessAgent.Builder agentBuilder = HarnessAgent.builder() .name("assistant") // ... .middleware(new InputMessageDeduplicationMiddleware()); ``` Register it only on an agent that keeps its conversation across requests. Refs #2023.
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.
Summary
AG-UI front ends such as CopilotKit resend the whole conversation on every run.
AguiRequestProcessorcurrently deals with this by askingAgentResolver.hasMemory()before the call and, when the answer is yes, cutting the request down to the messages after the last assistant turn. The check runs outside the call and only tells us that some context exists, and the cut is a fixed position that does not hold for every client: a front-end tool result is not a user message, and a regenerate sends no new message at all. Issue #2023 reports the duplication when the check says no, and #3043 reports a session left waiting after the cut (I have not reproduced that one).This PR removes that handling and documents the two ways to deal with a front end that resends everything. AgentScope treats
RunAgentInput.messagesas incremental input: each call appends what it receives, and nothing checks whether the agent already holds some of it. No middleware is shipped for this. An earlier draft shipped one and we agreed to leave it out: matching resent messages against the agent's state is easy to get wrong, and on the streaming path the assistant message ids a client receives are not the persisted ones, so an id match is unreliable.One behavior change to be aware of: with
server-side-memory: trueand a front end that resends the whole history, the agent now receives the full transcript on every run. Those deployments need one of the two options described in the guide.Changes
AguiRequestProcessorpassesRunAgentInput.messagesto the agent unchanged and no longer callshasMemory(). The publicextractLatestUserMessage(RunAgentInput)is removed, andAgentResolver.hasMemorystays as an existence probe.messageFilter, or write aMiddlewareBasethat trims the input inonAgentStateReady, with an outline of the approach.Refs #2023. This PR removes the faulty handling and shows users how to cope; it does not deduplicate by itself.