Skip to content

feat: offload base64 image payloads from agent state - #2867

Closed
guslegend0510 wants to merge 5 commits into
agentscope-ai:mainfrom
guslegend0510:codex/issue-2852-offload-base64
Closed

guslegend0510 wants to merge 5 commits into
agentscope-ai:mainfrom
guslegend0510:codex/issue-2852-offload-base64

Conversation

@guslegend0510

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT

Description

Closes #2852

Large inline base64 image payloads were stored directly in agent state, so ordinary session and history retrieval had to load and deserialize the full image data even when the caller did not need it.

This PR introduces opt-in image payload offloading for agent state:

  • Extract inline base64 image data into content-addressed payload records and persist lightweight versioned references in messages.
  • Add LEAN and FULL agent-state load modes so ordinary state reads can skip image payload hydration.
  • Hydrate detached model input only when assembling model history, with per-call payload caching to avoid duplicate reads.
  • Support image payloads in ImageBlock, image DataBlock, and nested ToolResultBlock content while preserving custom Msg subtypes.
  • Route state and payload persistence through bounded-elastic execution for ReAct agents, sub-agents, harness agents, admin operations, and shutdown saves.
  • Add an explicit imagePayloadOffloadingEnabled(true) opt-in to keep mixed-version deployments safe; the default remains disabled.
  • Update examples and add migration, compatibility, missing-payload, deduplication, concurrency, and sub-agent coverage.

Compatibility

Existing inline base64 states remain readable. When offloading is enabled, a subsequent save migrates inline payloads to referenced payload records. Keeping the feature disabled by default prevents older nodes in rolling deployments from receiving states that contain references they cannot hydrate.

Validation

  • mvn spotless:apply
  • Full agentscope-core test suite: 2,329 tests, 0 failures, 0 errors, 9 skipped
  • Focused image payload persistence, transformer, state-store, ReActAgent, and SubAgentTool tests
  • Cross-backend verification for Redis, MySQL, PostgreSQL, COS, OSS, and Admin modules
  • Package verification for affected modules and documentation examples
  • git diff --check

Checklist

Please check the following items before code is ready to be reviewed.

  • 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

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR has conflicts with the main branch and cannot be merged. Please rebase or merge main into your branch and resolve the conflicts:

git fetch origin
git checkout codex/issue-2852-offload-base64
git rebase origin/main
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved.


Automated notification by github-manager-bot

wahllllll added a commit to wahllllll/agentscope-java that referenced this pull request Oct 10, 2026
Jackson's default StreamReadConstraints reject any single string value above
20,000,000 characters on read, while serialization imposes no cap at all. Every
AgentStateStore -- JSON file, JDBC, Redis, MongoDB, OSS, COS, the Service JPA
store -- persists through JsonUtils.getJsonCodec(), i.e. this codec's default
ObjectMapper, and an AgentState carrying inline Base64 media (a 25 MB video is
33.5 million characters) saved successfully and then failed to load on the very
next turn. Because the load happens before the model is called, every later
turn of that session failed too, text-only ones included: a session bricked by
its own persisted state.

Configure the default ObjectMapper's JsonFactory with maxStringLength set to
Integer.MAX_VALUE so the reader accepts whatever the writer emitted. Nesting
depth, number length and name length keep their Jackson defaults; a caller-
supplied ObjectMapper is left untouched. Strings this large only ever reach the
codec from the framework's own persisted state -- model output and tool
arguments are bounded far below the old limit -- so no untrusted boundary
loses protection.

Offloading media out of AgentState (agentscope-ai#2867) remains the right long-term answer;
this restores the round-trip invariant the stores already rely on.

Fixes agentscope-ai#3465
wahllllll added a commit to wahllllll/agentscope-java that referenced this pull request Oct 10, 2026
Jackson's default StreamReadConstraints reject any single string value above
20,000,000 characters on read, while serialization imposes no cap at all. Every
AgentStateStore -- JSON file, JDBC, Redis, MongoDB, OSS, COS, the Service JPA
store -- persists through JsonUtils.getJsonCodec(), i.e. this codec's default
ObjectMapper, and an AgentState carrying inline Base64 media (a 25 MB video is
33.5 million characters) saved successfully and then failed to load on the very
next turn. Because the load happens before the model is called, every later
turn of that session failed too, text-only ones included: a session bricked by
its own persisted state.

Configure the default ObjectMapper's JsonFactory with maxStringLength set to
Integer.MAX_VALUE so the reader accepts whatever the writer emitted. Nesting
depth, number length and name length keep their Jackson defaults; a caller-
supplied ObjectMapper is left untouched. Strings this large only ever reach the
codec from the framework's own persisted state -- model output and tool
arguments are bounded far below the old limit -- so no untrusted boundary
loses protection.

Offloading media out of AgentState (agentscope-ai#2867) remains the right long-term answer;
this restores the round-trip invariant the stores already rely on.

Fixes agentscope-ai#3465
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]: Offload base64 image data from AgentStateStore to reduce history retrieval overhead

3 participants