feat: preserve opaque_body provider state on prompt messages and LLM results - #261
Open
hpiclaranet wants to merge 1 commit into
Open
feat: preserve opaque_body provider state on prompt messages and LLM results#261hpiclaranet wants to merge 1 commit into
hpiclaranet wants to merge 1 commit into
Conversation
…results Plugin LLM results carry provider round-trip state in opaque_body (e.g. signed/encrypted thinking blocks, Gemini thought_signature), matching the dify_plugin SDK entities. Graphon dropped that state in two places: - AssistantPromptMessage / PromptMessageContent had no opaque_body field, so daemon -> core Pydantic validation silently discarded it. - _LLMChunkAccumulator and _StreamingInvokeAccumulator rebuilt the assistant message from content and tool calls only. Add the field (same name, type and default as the plugin SDK) and carry the last non-None snapshot through both accumulators. Refs: langgenius#260
|
All contributors on this pull request have signed the CLA. |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Important
!Related Issue
Closes #260
Summary
Plugin LLM results can carry provider round-trip state in
opaque_body(e.g. signed/encrypted Claude thinking blocks, Geminithought_signature). The plugin SDK (dify_plugin >= 0.10.0) defines the field on bothAssistantPromptMessageandPromptMessageContent, and the plugin daemon passes it through to Dify core — but graphon dropped it in two places:AssistantPromptMessage/PromptMessageContenthad noopaque_bodyfield, so the daemon → core Pydantic boundary silently discarded it duringLLMResultChunk/LLMResultvalidation._LLMChunkAccumulatorand_StreamingInvokeAccumulatorrebuilt the assistant message from content + tool calls only, dropping the field even when chunks carried it (affects non-stream normalization of stream-only models and streaming callback bookkeeping).This change:
opaque_body: JsonValue | None = NonetoAssistantPromptMessageandPromptMessageContent, mirroring the plugin SDK field name, type, and default exactly (message-level for reasoning state; content-block-level for per-part state such as Geminithought_signature).Nonechunk wins, and laterNonechunks do not clobber a captured snapshot.LLMResultChunk.model_validate_json), backward compatibility for payloads without the field, and accumulator preservation for both stream and non-stream paths.Compatibility notes:
Nonedefault); no behavior change for providers that do not use the field.opaque_body: nullwhen unset, matching the plugin SDK's existing serialization behavior at the daemon boundary.dsl/slim/llm.py), workflow LLM node prompt reconstruction (nodes/llm/llm_utils.py), and parameter extractor message building — none of them are on the agent-loop path this issue covers.Context: langgenius/dify#41092 (Claude extended thinking dropped between Agent tool-use rounds), plugin-side counterpart langgenius/dify-official-plugins#3715, prior core attempt langgenius/dify#31566.
Validation:
uv run pytest(742 passed),uv lock --check,uv run ruff format --check,uv run ruff check,uv run ty checkall green. I will sign the CLA if CLA Assistant prompts.Checklist
!