steps B.3/B.4/B.5 complete: bidirectional WS handler, _tool_loop verified, clean final frame

This commit is contained in:
2026-03-05 00:06:11 +01:00
parent 27c087d5d8
commit 6d9a16e513
2 changed files with 9 additions and 11 deletions

View File

@@ -144,14 +144,15 @@ async def orchestrate_stream(
request: ChatRequest,
reg: AgentRegistry | None = None,
) -> AsyncGenerator[str, None]:
"""Streaming orchestration — yields text chunks then a final JSON frame.
"""Streaming orchestration — yields plain text chunks only.
The final frame is a JSON object:
``{"done": true, "response": "...", "actions": []}``.
The WebSocket handler in ``app/api/routes/chat.py`` is responsible for
wrapping each chunk in a ``text_chunk`` frame and sending the final
``final`` frame once the generator is exhausted.
Agents do not yet support token-level streaming; the full response is
fetched first, then emitted in fixed-size chunks. Token-level streaming
will be wired in Step 6 when agents expose ``astream()``.
fetched first (which may involve multiple WS round-trips for tool calls),
then emitted in fixed-size chunks.
"""
if reg is None:
reg = _default_registry
@@ -163,6 +164,3 @@ async def orchestrate_stream(
chunk_size = 50
for i in range(0, len(response_text), chunk_size):
yield response_text[i : i + chunk_size]
final = ChatResponse(response=response_text)
yield json.dumps({"done": True, **final.model_dump()})