feat(api): Update Chat Stream Protocol for Orchestrator Architecture
This commit is contained in:
@@ -56,7 +56,8 @@ async def stream_agent_events(
|
||||
initial_state,
|
||||
config,
|
||||
version="v2",
|
||||
checkpointer=checkpointer
|
||||
checkpointer=checkpointer,
|
||||
subgraphs=True
|
||||
):
|
||||
kind = event.get("event")
|
||||
name = event.get("name")
|
||||
@@ -71,8 +72,8 @@ async def stream_agent_events(
|
||||
"data": data
|
||||
}
|
||||
|
||||
# Buffer assistant chunks (summarizer and researcher might stream)
|
||||
if kind == "on_chat_model_stream" and node_name in ["summarizer", "researcher", "clarification"]:
|
||||
# Buffer assistant chunks (synthesizer and clarification might stream)
|
||||
if kind == "on_chat_model_stream" and node_name in ["synthesizer", "clarification"]:
|
||||
chunk = data.get("chunk", "")
|
||||
# Use utility to safely extract text content from the chunk
|
||||
chunk_data = convert_to_json_compatible(chunk)
|
||||
@@ -83,7 +84,7 @@ async def stream_agent_events(
|
||||
assistant_chunks.append(str(chunk_data))
|
||||
|
||||
# Buffer and encode plots
|
||||
if kind == "on_chain_end" and name == "executor":
|
||||
if kind == "on_chain_end" and name == "data_analyst_worker":
|
||||
output = data.get("output", {})
|
||||
if isinstance(output, dict) and "plots" in output:
|
||||
plots = output["plots"]
|
||||
@@ -95,7 +96,7 @@ async def stream_agent_events(
|
||||
output_event["data"]["encoded_plots"] = encoded_plots
|
||||
|
||||
# Collect final response from terminal nodes
|
||||
if kind == "on_chain_end" and name in ["summarizer", "researcher", "clarification"]:
|
||||
if kind == "on_chain_end" and name in ["synthesizer", "clarification"]:
|
||||
output = data.get("output", {})
|
||||
if isinstance(output, dict) and "messages" in output:
|
||||
last_msg = output["messages"][-1]
|
||||
|
||||
Reference in New Issue
Block a user