Skip to content

fix: [AI Agent] When the "Return Content" toggle is disabled for an AI conversation node, text is still output to the frontend chat box; the toggle is ineffective. - #7724

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_ai_chat_result
Nov 6, 2026

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: [AI Agent] When the "Return Content" toggle is disabled for an AI conversation node, text is still output to the frontend chat box; the toggle is ineffective.

…I conversation node, text is still output to the frontend chat box; the toggle is ineffective.
)
if reasoning_content_chunk and model_setting.get("reasoning_content_enable", False):
reasoning_setting["is_reasoning"] = True
self.write(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Analysis

What the Change Does

The patch adds an is_result parameter to _stream_response, which when falsy, skips writing streaming text chunks to the output (but still writes reasoning content).

Potential Issues

1. Logic seems inverted or unclear

  • The flag name is_result suggests "this is a final result," yet when it's falsy you suppress content. If intermediate/tool-call steps shouldn't stream text, a clearer name like write_text_content=True (a positive flag controlling the action) would be more readable.

2. Silent data loss / inconsistency

  • When is_result is falsy, text chunks are dropped entirely — they're neither written nor stored elsewhere. If downstream consumers expect the full transcript, this creates inconsistent output between contactenated and streamed paths. Consider whether the text should be accumulated and written at the end instead of discarded.
  • Also consider: only the chunk write is guarded. If there's a later "final write" of the full text elsewhere in the function (not shown in the diff), that path may still execute — verify behavior is consistent.

3. Mutable default pattern is fine here, but...

  • is_result=None used as a boolean is acceptable, but is_result=False as default is simpler and more explicit if it's purely a flag.

4. Duplication

  • The repeated Position(self.get_node_id()) calls add noise throughout _stream_response. Several instances appearing in sequence suggests refactoring opportunity (precompute once per call if the node doesn't change mid-stream).

Optimization Suggestions

  • Early branching: Instead of checking if is_result: inside the loop on every chunk, branch once before the streaming loop and use two slightly different write lambdas/helpers. This reduces per-chunk conditionals:
text_writer = self._make_text_writer(text_content_id, node_info) if is_result else None
...
if text_writer:
    self.write(text_writer(content_chunk))
  • Naming: Rename to stream_text: bool = True so call sites read naturally (stream_text=False for silent intermediate stages).

  • Testing: Add tests covering both branches — particularly that reasoning content is still streamed when is_result is false, since that asymmetry is easy to break accidentally.

Summary

Functionally the patch looks safe, but verify: (a) discarding text intentionally vs. needing accumulation, (b) no other writes to text_content_id later bypass the flag, and (c) rename the flag to something positively-phrased for clarity.

@shaohuzhang1
shaohuzhang1 merged commit 557fd3d into v3 Nov 6, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@fix_ai_chat_result branch November 6, 2026 09:11
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.

1 participant