Repository navigation
feat(core): add InputMessageDeduplicationMiddleware to deduplicate full-history resent input and keep only the incremental delta - #3467
Closed
xzxiaoshan wants to merge 15 commits into
Conversation
…ll-history resent input and keep only the incremental delta
# Conflicts: # agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui/src/main/java/io/agentscope/core/agui/adapter/AguiAgentAdapter.java
…ware from ext-agui to core
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…ing ids Upstream agentscope-ai#3239 rewrote every outbound AG-UI message id to agui::<sourceId>-<UUID>, which silently broke the id round-trip contract that InputMessageDeduplicationMiddleware anchoring relies on (R2): resent history could never match the persisted context by id, so the converter round-trip test failed after merging main. Restore id fidelity while keeping agentscope-ai#3239's goal of distinct ids for expanded messages: - one-to-one conversions keep the source id unchanged - an expansion keeps the source id on exactly one sibling: the standard message of a reasoning split, or the last result of a multi-result tool message (the anchor matches the last resent sibling, so earlier siblings strip together with it) - every other sibling gets a deterministic derived id <sourceId>::<qualifier> ("reasoning", or the tool call id), making repeated conversions idempotent instead of regenerating UUIDs
Resolve conflicts with main: - AguiRequestProcessorTest.java: keep assertNull import (used by main's new first-class userId tests), drop assertSame (its extractLatestUserMessage test was removed by this branch's InputMessageDeduplicationMiddleware rework). - HarnessInputMessageDeduplicationTest: exclude main's new per-turn synthetic state projections (METADATA_SYNTHETIC: subagent catalog, session-state context items) from conversationTexts assertions; the dedup regression asserts caller history appears exactly once and the request-only projections are orthogonal.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Conflict resolution in AguiMessageConverter: adopt main's list-based structure with media/document InputContents while keeping this branch's stable message-ID scheme (source ID on exactly one sibling, deterministic sourceId::qualifier derived IDs for the others; random generatedMessageId removed). InputMessageDeduplicationMiddlewareConverterTest fixture moved to a user media message: main now maps assistant media to structured blocks, which toMsg rejects by design (user/tool only, pinned upstream).
…-merge-middleware # Conflicts: # docs/v2/en/integration/protocol/agui.md # docs/v2/zh/integration/protocol/agui.md
# Conflicts: # agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui/src/main/java/io/agentscope/core/agui/converter/AguiMessageConverter.java # docs/v2/en/integration/protocol/agui.md # docs/v2/zh/integration/protocol/agui.md
…on test HarnessInputMessageDeduplicationTest counted the model calls seen by the agent's Model after dropping only the memory-extraction ones. The harness also runs a fire-and-forget memory consolidation after each agent call, whose prompt that filter does not match. Whether the call happens depends on which background task wins the race between the flush writing the daily ledger and the maintenance reading it, so it lands in the capture at a timing-dependent position: - fullTranscriptDedup_survivesSessionDefaultsDerivation: expected <2> but was <3> (ubuntu CI, d4bdf6a) - dedupedInput_sparesTheCallerImmutableList_throughDerivation: expected <[first, done, second]> but was <[Current MEMORY.md: ... (ubuntu CI, 642d8bc) Disable the memory hooks on both agents so only reasoning calls reach the model, and assert on every captured call instead of a filtered view.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Replace the bundled InputMessageDeduplicationMiddleware with a declaration: the developer states whether the front end sends the whole conversation or only new messages, and the adapter passes the request messages to the agent unchanged in both modes. - Add the core enum InputMessageMode (FULL, INCREMENTAL), carried on the RuntimeContext as a typed attribute. AguiAdapterConfig.messageMode and the starter property agentscope.agui.message-mode declare it, and the adapter publishes it for agent-side code. - Clear the attribute for subagent calls in SubAgentTool and DefaultAgentManager: a child's input is its task prompt. - Remove the middleware, its three tests and the registrations in the documentation examples. - Document the modes, the CopilotKit messageFilter alternative and a custom-middleware outline for full-history resends in the AG-UI guide (EN/ZH, v2 and dev).
… 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.
Collaborator
Author
|
Superseded by #4523 and #4535. #4523 (merged) removes the The outbound id preservation in |
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 clients (e.g. CopilotKit) resend the full message history on every turn. When the server
persists conversation context through an
AgentStatestore, the resent prefix gets replayedinto the agent and duplicates the persisted context.
InputMessageDeduplicationMiddlewarestrips this overlapping prefix at the call boundary — thelast persisted context message acts as the anchor — so only the incremental messages reach the
agent.
This is not AG-UI specific. Any application layer that passes in the full message history while
the server persists context (protocol adapters, chat frontends, replayed event sources) hits the
same duplication; the middleware is protocol-neutral and lives in
agentscope-corealongsidethe other standard middlewares. It is opt-in: developers register it on agents whose input
source resends history, e.g.
Agents whose frontend message list is the single source of truth (no server-side history)
should not register it.
Changes
InputMessageDeduplicationMiddlewareinagentscope-core(io.agentscope.core.middleware),with id-first / role+content fallback anchor matching, pending-tool resume, and regenerate
semantics
AguiRequestProcessor: input messages now pass through in full; dedupresponsibility moves to the middleware, replacing the old
hasMemory-based last-messageextraction
agui extension, harness path in
HarnessInputMessageDeduplicationTestFixes #2023