Skip to content

fix(agent): preserve complete model messages through tools and history - #44502

Draft
WH-2099 wants to merge 1 commit into
mainfrom
fix/agent-message-replay
Draft

WH-2099 wants to merge 1 commit into
mainfrom
fix/agent-message-replay

Conversation

@WH-2099

@WH-2099 WH-2099 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of #41092; replaces the closed, unmerged #41095 with the joint upgrade against current main.

Agents rebuild provider responses from visible text, losing signed/encrypted state and ordered content blocks during tool turns and later history restoration.
Preserve complete messages in legacy Function Calling/CoT, workflow Agent strategies, and Agent v2; extract text only at display or text-parsing boundaries.

Legacy Agent thoughts store provider/model-scoped messages in the new nullable model_messages column.
Workflow Agents store the reserved model_history snapshot in execution process data and remove it from public node outputs.
History reads validate tenant, app, workflow run, node, provider, and model ownership.
Agent v2 retains original Dify content in its existing serialized provider details while Pydantic AI remains the owner of native tool calls.
Changed providers/models use the existing visible-message fallback, and incomplete saved tool calls receive interrupted results.

History trimming retains complete conversation turns, including tool observations and retrieval images.
Structured output accepts text contained in content blocks.
The existing Graphon result accumulator replaces duplicated stream aggregation.

Dependencies and release gates

This draft is blocked on publication of its Graphon dependency.
The API and Agent v2 locks select Graphon candidate bfeca97726f91eab257e513357b72d456de851b2, containing merged #261, #344, and the public incremental accumulator change.
That candidate is currently local: lock generation and frozen installation used a local Git mirror of the exact commit.
It must be published before a remote checkout can install these dependencies.
The current Main CI, Docker build, autofix, and both Pyrefly workflows stop at dependency installation with upload-pack: not our ref bfeca977....
The Graphon candidate must become reachable before these checks can run.

The coordinated release also needs SDK #390, daemon #828, official plugins #4034, and #4035.
Replace review Git pins with the selected published releases and set the official plugins' minimum Dify versions when the target version is confirmed.

Validation

  • API: 338 relevant Agent, memory, structured-output, and workflow tests passed; the subsequent history-trimming suite passed 238 tests.
  • After frozen candidate installation, all 9 replay/history/turn-trimming boundary tests passed again.
  • Agent v2: 925 passed, 5 skipped with frozen dependencies; package lint and type checks passed.
  • Graphon candidate: 1,013 tests passed and its source/wheel builds passed.
  • API Ruff, changed-file formatting, response contracts, both AST guards, dotenv lint, all 69 import contracts, and type checks for changed modules passed.
  • The new Alembic migration ran on isolated PostgreSQL.
  • Actual Dify API, daemon, SDK, official plugins, PostgreSQL, and Redis completed 36 controlled acceptance cases: model calls, legacy Agents, workflow strategies including Self Refine, Agent v2, stored history, ordinary chat/vision, and structured output.
  • Workflow Function Calling/ReAct also completed the actual SDK/serverless HTTP request path.

The provider endpoints supplied controlled responses; no paid model service was called.
Vendor cryptographic signature acceptance, production deployment, and the repository-wide Dify integration suite remain release checks.

Screenshots

Not applicable: backend behavior only.

Checklist

From Codex

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

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant