Repository navigation
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
Conversation
…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( |
There was a problem hiding this comment.
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_resultsuggests "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 likewrite_text_content=True(a positive flag controlling the action) would be more readable.
2. Silent data loss / inconsistency
- When
is_resultis 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=Noneused as a boolean is acceptable, butis_result=Falseas 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 = Trueso call sites read naturally (stream_text=Falsefor silent intermediate stages). -
Testing: Add tests covering both branches — particularly that reasoning content is still streamed when
is_resultis 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.
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.