Skip to content

feat(event): emit COMPACTION_START/END events from CompactionMiddleware#1962

Open
Buktal wants to merge 2 commits into
agentscope-ai:mainfrom
Buktal:feat/compaction-events
Open

feat(event): emit COMPACTION_START/END events from CompactionMiddleware#1962
Buktal wants to merge 2 commits into
agentscope-ai:mainfrom
Buktal:feat/compaction-events

Conversation

@Buktal

@Buktal Buktal commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

Fixes #1905.

Background: When CompactionMiddleware triggers context compaction (a summarization LLM call), the frontend receives no events during this period and appears frozen.

Changes:

  • Add COMPACTION_START and COMPACTION_END to AgentEventType
  • Add CompactionStartEvent (carries estimatedTokens, triggerThreshold) and CompactionEndEvent (carries originalMessageCount, compactedMessageCount, estimatedTokensSaved)
  • Register both events in AgentEvent @JsonSubTypes
  • CompactionMiddleware.onReasoning() wraps the reasoning stream with COMPACTION_START → stream → COMPACTION_END when compaction is actually triggered (events are not emitted when the token threshold is not reached)

Testing: Full build passes (mvn clean install). The events fire only when compaction triggers, consistent with the existing event model (e.g. MODEL_CALL_START/END).

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

When context compaction is triggered, CompactionMiddleware now emits
COMPACTION_START before the summarization LLM call and COMPACTION_END
after reasoning completes, allowing frontends to display progress
instead of appearing frozen. Events carry token statistics so callers
can show meaningful progress information.

Closes agentscope-ai#1905
@Buktal Buktal requested a review from a team June 29, 2026 11:46
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.50000% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...harness/agent/middleware/CompactionMiddleware.java 15.38% 11 Missing ⚠️

📢 Thoughts on this report? Let us know!

…ent and CompactionMiddleware

- CompactionEventRoundTrip in AgentEventStreamTest: JSON serialization/deserialization
  round-trip via Jackson polymorphism for both compaction event types; field values and
  type discriminator are verified
- CompactionMiddlewareTest: covers the four execution paths — no compaction (passthrough),
  compaction triggered (START/END wrap next flux), non-ReActAgent short-circuit, and
  compaction error fallback
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.

[Feature]: 希望支持compact事件、toolResultEviction等事件通过streamEvent透出

1 participant