Skip to content

docs(agui): stop trimming resent transcripts and document incremental input - #4523

Merged
xzxiaoshan merged 2 commits into
agentscope-ai:mainfrom
xzxiaoshan:refactor/agui-incremental-input
Dec 1, 2026
Merged

xzxiaoshan merged 2 commits into
agentscope-ai:mainfrom
xzxiaoshan:refactor/agui-incremental-input

Conversation

@xzxiaoshan

Copy link
Copy Markdown
Collaborator

Summary

AG-UI front ends such as CopilotKit resend the whole conversation on every run. AguiRequestProcessor currently deals with this by asking AgentResolver.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.messages as 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: true and 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

  • AguiRequestProcessor passes RunAgentInput.messages to the agent unchanged and no longer calls hasMemory(). The public extractLatestUserMessage(RunAgentInput) is removed, and AgentResolver.hasMemory stays as an existence probe.
  • The AG-UI guide (EN and ZH, dev) gets a "Conversation History" section with the two options: upgrade CopilotKit to 1.73.1 or later and use its messageFilter, or write a MiddlewareBase that trims the input in onAgentStateReady, 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.

… 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.
@mintlify

mintlify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 7fffa49.

Approve preview

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.
@xzxiaoshan
xzxiaoshan merged commit 0a57744 into agentscope-ai:main Dec 1, 2026
6 of 7 checks passed
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants