Skip to content

fix(state): bound persisted session context#2178

Open
guslegend0510 wants to merge 2 commits into
agentscope-ai:mainfrom
guslegend0510:fix/2173-session-state-retention
Open

fix(state): bound persisted session context#2178
guslegend0510 wants to merge 2 commits into
agentscope-ai:mainfrom
guslegend0510:fix/2173-session-state-retention

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

Summary

  • Add maxPersistedContextMessages to limit the number of recent conversation messages stored in persisted agent_state snapshots.
  • Keep the live runtime context unchanged while trimming only the persistence snapshot.
  • Add deleteSessionState(...) APIs so applications can explicitly remove persisted session data and local state caches.
  • Expose the new configuration and cleanup APIs through HarnessAgent.
  • Add English and Chinese documentation for standalone AgentStateStore and DistributedStore usage.

The default remains unlimited for backward compatibility. Setting maxPersistedContextMessages to 0 persists non-conversation agent state without storing conversation messages.

Testing

  • mvn -pl agentscope-core -Dtest=ReActAgentPerSessionStateTest test
  • mvn -pl agentscope-harness -am -Dtest=HarnessAgentTest -Dsurefire.failIfNoSpecifiedTests=false test
  • mvn -pl agentscope-core test

Full core test result: 2,213 tests passed, 0 failures, 0 errors, 9 skipped.

Fixes #2173

@guslegend0510 guslegend0510 requested a review from a team July 13, 2026 13:09
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.91667% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...e/src/main/java/io/agentscope/core/ReActAgent.java 78.04% 7 Missing and 2 partials ⚠️
...java/io/agentscope/harness/agent/HarnessAgent.java 42.85% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/core/memory Memory, session, state area/harness agentscope-harness (test/runtime support) area/docs Documentation labels Jul 14, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR adds two features to ReActAgent:

  1. maxPersistedContextMessages — limits the number of recent conversation messages stored in persisted agent_state snapshots, preventing unbounded storage growth for long sessions. Trimming only affects the persistence snapshot, not the live runtime context.
  2. deleteSessionState(...) — public API allowing applications to explicitly delete persisted session data and clean local caches.

Changes are well-scoped, code style consistent with project conventions, tests cover core paths and edge cases (negative limit rejection, auto-persistence trimming, post-delete cache eviction), and documentation is provided in both English and Chinese. The PR directly addresses issue #2173.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR adds two features to ReActAgent:

  1. maxPersistedContextMessages — limits the number of recent conversation messages stored in persisted agent_state snapshots, preventing unbounded storage growth for long sessions. Trimming only affects the persistence snapshot, not the live runtime context.
  2. deleteSessionState(...) — public API allowing applications to explicitly delete persisted session data and clean local caches.

Changes are well-scoped, code style consistent with project conventions, tests cover core paths and edge cases (negative limit rejection, auto-persistence trimming, post-delete cache eviction), and documentation is provided in both English and Chinese. The PR directly addresses issue #2173.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/memory Memory, session, state area/docs Documentation area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:使用DistributedStore的方式,数据库中的agentscope_sessions中的state_data字段会一直叠加

2 participants