fix(gateway,acp): deliver plugin-transformed final_response through streaming gate#31433
Merged
Conversation
…ut hook now visible When streaming is active, streamed_message=True skipped the final_response update, causing plugin hooks like transform_llm_output to be silently invisible. Remove the `not streamed_message` guard so the final response (possibly transformed by plugins) is always delivered to the ACP client.
…s streaming suppression When a transform_llm_output hook modifies final_response after streaming, the gateway was silently discarding the transformed content because streamed=True / content_delivered=True triggered the final-send suppression. Three changes: 1. conversation_loop: set `_response_transformed=True` when a transform_llm_output hook returns a non-empty string, and expose it as `response_transformed` in the result dict. 2. gateway/run: skip the final-send suppression when `response_transformed` is True — the transformed response must reach the client even if streaming already sent the original text. 3. acp_adapter/server: remove `not streamed_message` guard so final_response is always delivered (ACP path fixed separately).
…turn dict run_sync() cherry-picks fields from the run_conversation result dict into a new response dict for the gateway. response_transformed was missing from the cherry-pick list, so the gateway always saw it as False and suppressed the final send even though a transform_llm_output hook had modified the content.
… response_transformed When a transform_llm_output hook appends content after streaming, the previous fix skipped the final-send suppression which caused the full response to be sent as a NEW message (duplicate). Instead, edit the existing streamed message in-place to append the transformed content, then set already_sent=True. Added stream_consumer.message_id and .accumulated_text public properties.
…ming Adds a test that fails without the gateway fix, exercising the response_transformed=True branch in _finalize_response: a streamed response whose final text was modified by a transform_llm_output plugin hook must be edit_message'd in place (not duplicate-sent), with already_sent=True so the normal final-send is skipped. Also drops two minor leftovers from the salvaged PR #29119: * accumulated_text property on GatewayStreamConsumer (unused) * duplicate _response_transformed=False inside the hook try block
Contributor
🔎 Lint report:
|
PR #29119 dropped the 'not streamed_message' guard unconditionally so that plugin-transformed responses (transform_llm_output hook) would reach ACP clients. That regressed test_prompt_does_not_duplicate_streamed_final_message: when no transform happened, the streamed text was re-sent as a duplicate final delivery. Tighten the condition to mirror the gateway side: deliver after streaming only when response_transformed=True. Otherwise keep the old guard. Adds test_prompt_delivers_transformed_response_after_streaming so the transformed path stays covered.
Collaborator
kenyonxu
added a commit
to kenyonxu/hermes-agent
that referenced
this pull request
Jun 2, 2026
记录PR NousResearch#31433 (fix: plugin-transformed final_response通过streaming gate) 已被合并到main。 原PR由@kenyonxu提交(NousResearch#29119),由@teknium1 salvage并合并。 嵌入Nous Research官方info graphic。
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.
Plugin hooks on
transform_llm_outputnow reach end users on streaming platforms (Discord, Telegram, ACP, etc.). Before this, the hook's output was silently discarded after the stream completed.Changes
agent/conversation_loop.py: setresponse_transformed=Truein the run dict when a hook returns a non-empty string.gateway/run.py: propagate the flag throughrun_sync(); when set, edit the existing streamed message in place with the transformed text instead of suppressing the final send (no duplicate message).gateway/stream_consumer.py: exposemessage_idso the gateway can target the streamed bubble.acp_adapter/server.py: deliver the final response after streaming whenresponse_transformed=True(otherwise keep the existingnot streamed_messageguard so non-transformed streams don't double-send).tests/gateway/test_run_progress_topics.pyandtests/acp/test_server.py.Validation
update_agent_message_textagent_message_chunkTargeted suite: 112 passed in tests/acp/test_server.py + tests/gateway/test_run_progress_topics.py + tests/test_transform_llm_output_hook.py.
Credit
Salvages PR #29119 by @kenyonxu — original commits cherry-picked, contributor authorship preserved.
Infographic