-
Notifications
You must be signed in to change notification settings - Fork 19.9k
feat: support opaque_body from plugin LLM calls #31566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…om plugin LLM call (and fix the tool call parsing in streaming mode)
Summary of ChangesHello @BeautyyuYanli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the system's capability to handle and retain custom, unstructured data associated with LLM responses from plugins. By integrating Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces end-to-end support for preserving the assistant's opaque_body from plugin LLM calls. This includes adding opaque_body fields to message entities, parsing it during LLM invocations (both streaming and non-streaming), persisting it in message metadata, and restoring it when rebuilding memory prompt history. The changes are well-implemented and supported by new unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds runtime + app-layer plumbing to preserve and persist an assistant opaque_body returned from plugin-based LLM calls, including streaming flows, so it can be restored into prompt history later.
Changes:
- Extend model-runtime message entities to carry
opaque_bodyat both message and content levels. - Preserve assistant
opaque_bodywhen aggregating plugin LLM chunks (streaming and non-streaming) and expose it in after-invoke callbacks. - Capture assistant
opaque_bodyduring app streaming, persist it intomessage_metadataasassistant_opaque_body, and restore it inTokenBufferMemory.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| api/tests/unit_tests/core/model_runtime/__base/test_llm_invoke_opaque_body.py | Adds unit coverage ensuring opaque_body survives plugin LLM invoke (stream/non-stream). |
| api/core/model_runtime/model_providers/__base/large_language_model.py | Aggregates opaque_body (and tool calls) across chunks into final LLMResult / after-callback result. |
| api/core/model_runtime/entities/message_entities.py | Introduces opaque_body fields on prompt content and assistant messages. |
| api/core/memory/token_buffer_memory.py | Restores persisted assistant_opaque_body from message_metadata into AssistantPromptMessage. |
| api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py | Persists assistant opaque_body into message_metadata under assistant_opaque_body. |
| api/core/app/apps/base_app_runner.py | Captures opaque_body during streaming and includes it in the emitted final LLMResult. |
| agent-notes/.gitkeep | No functional change (repo housekeeping). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py
Outdated
Show resolved
Hide resolved
api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py
Outdated
Show resolved
Hide resolved
| def __init__(self) -> None: | ||
| self.after_result = None | ||
|
|
||
| def on_before_invoke(self, **kwargs: Any) -> None: # noqa: ANN401 |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method requires 1 positional argument, whereas overridden Callback.on_before_invoke requires at least 6.
| def on_before_invoke(self, **kwargs: Any) -> None: # noqa: ANN401 | |
| def on_before_invoke( # noqa: ANN401 | |
| self, | |
| arg1: Any, | |
| arg2: Any, | |
| arg3: Any, | |
| arg4: Any, | |
| arg5: Any, | |
| arg6: Any, | |
| *args: Any, | |
| **kwargs: Any, | |
| ) -> None: |
| def on_before_invoke(self, **kwargs: Any) -> None: # noqa: ANN401 | ||
| return None | ||
|
|
||
| def on_new_chunk(self, **kwargs: Any) -> None: # noqa: ANN401 |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method requires 1 positional argument, whereas overridden Callback.on_new_chunk requires at least 7.
| def on_new_chunk(self, **kwargs: Any) -> None: # noqa: ANN401 | |
| def on_new_chunk(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401 |
| def on_new_chunk(self, **kwargs: Any) -> None: # noqa: ANN401 | ||
| return None | ||
|
|
||
| def on_after_invoke(self, result: LLMResult, **kwargs: Any) -> None: # noqa: ANN401 |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method requires 2 positional arguments, whereas overridden Callback.on_after_invoke requires at least 7.
| def on_after_invoke(self, result: LLMResult, **kwargs: Any) -> None: # noqa: ANN401 | |
| def on_after_invoke( | |
| self, | |
| tenant_id: str | None = None, # type: ignore[unused-argument] | |
| model_provider_instance_id: str | None = None, # type: ignore[unused-argument] | |
| model_instance_id: str | None = None, # type: ignore[unused-argument] | |
| model: str | None = None, # type: ignore[unused-argument] | |
| credentials: dict[str, Any] | None = None, # type: ignore[unused-argument] | |
| prompt_messages: list[PromptMessage] | None = None, # type: ignore[unused-argument] | |
| result: LLMResult | None = None, | |
| **kwargs: Any, # noqa: ANN401 | |
| ) -> None: |
| def on_after_invoke(self, result: LLMResult, **kwargs: Any) -> None: # noqa: ANN401 | ||
| self.after_result = result | ||
|
|
||
| def on_invoke_error(self, **kwargs: Any) -> None: # noqa: ANN401 |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method requires 1 positional argument, whereas overridden Callback.on_invoke_error requires at least 7.
| def on_invoke_error(self, **kwargs: Any) -> None: # noqa: ANN401 | |
| def on_invoke_error(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401 |
fb409cb to
688b2cf
Compare
Summary
This is a part of langgenius/dify-official-plugins#2492
Adds end-to-end support for preserving assistant
opaque_bodyproduced by plugin LLM calls.opaque_bodyfields in model runtime prompt/message entities.opaque_bodyfrom plugin LLM invocations (including streaming tool-call parsing).opaque_bodyduring app run streaming, persists it intomessage_metadataasassistant_opaque_body, and restores it when rebuilding memory prompt history.Testing
api/tests/unit_tests/core/model_runtime/__base/test_llm_invoke_opaque_body.py