feat: enhance streaming support in conversational flow

- Introduced  function to determine if a result is a streaming output.
- Added  method to handle streaming results before accessing them.
- Updated  method to utilize the new streaming result handling.
- Implemented context management for LLM streaming in the conversational mixin.
- Added tests to verify streaming behavior and ensure proper handling of user messages during streaming.
This commit is contained in:
lorenzejay
2026-06-26 14:11:59 -07:00
parent b6fbe078d6
commit 1cb1fa8264
5 changed files with 191 additions and 17 deletions

View File

@@ -4,6 +4,8 @@ Two-column layout: left sidebar (tasks/agents/tokens) + main content
(task header, plan checklist, activity timeline, streaming output).
"""
from collections.abc import Iterable
import inspect
import json as _json
import re
import threading
@@ -45,6 +47,14 @@ def _is_save_to_memory_tool(tool_name: str | None) -> bool:
return (tool_name or "").replace(" ", "_").lower() == "save_to_memory"
def _is_streaming_output(value: Any) -> bool:
return (
isinstance(value, Iterable)
and inspect.getattr_static(value, "get_full_text", None) is not None
and inspect.getattr_static(value, "result", None) is not None
)
def _truncate_log_text(value: Any, limit: int) -> str | None:
if value is None:
return None
@@ -834,14 +844,18 @@ FooterKey .footer-key--key {
set_suppress_tracing_messages(True)
try:
result = self._flow.handle_turn(message)
if hasattr(result, "get_full_text") and hasattr(result, "result"):
for _chunk in result:
pass
result = result.result
result = self._consume_conversation_streaming_result(result)
self.call_from_thread(self._on_conversation_turn_done, result)
except Exception as e:
self.call_from_thread(self._on_conversation_turn_failed, str(e))
def _consume_conversation_streaming_result(self, result: Any) -> Any:
if not _is_streaming_output(result):
return result
for _chunk in result:
pass
return result.result
def _on_conversation_turn_done(self, result: Any) -> None:
with self._lock:
output = self._stringify_output(result)