refactor(chat): stream agent events via stream_output and remove parity v2 flag

This commit is contained in:
CREDO23 2026-05-07 19:40:10 +02:00
parent 7e07092f67
commit 78f4747382
17 changed files with 76 additions and 1676 deletions

View file

@ -33,7 +33,7 @@ def iter_chat_model_stream_frames(
reasoning_delta = parts["reasoning"]
text_delta = parts["text"]
if state.parity_v2 and reasoning_delta:
if reasoning_delta:
if state.current_text_id is not None:
yield streaming_service.format_text_end(state.current_text_id)
if content_builder is not None:
@ -100,7 +100,7 @@ def iter_chat_model_stream_frames(
if content_builder is not None:
content_builder.on_text_delta(state.current_text_id, text_delta)
if state.parity_v2 and parts["tool_call_chunks"]:
if parts["tool_call_chunks"]:
for tcc in parts["tool_call_chunks"]:
idx = tcc.get("index")

View file

@ -77,12 +77,11 @@ def iter_tool_start_frames(
yield emit_thinking_step_frame(**frame_kw)
matched_meta: dict[str, str] | None = None
if state.parity_v2:
taken_ui_ids = set(state.ui_tool_call_id_by_run.values())
for meta in state.index_to_meta.values():
if meta["name"] == tool_name and meta["ui_id"] not in taken_ui_ids:
matched_meta = meta
break
taken_ui_ids = set(state.ui_tool_call_id_by_run.values())
for meta in state.index_to_meta.values():
if meta["name"] == tool_name and meta["ui_id"] not in taken_ui_ids:
matched_meta = meta
break
tool_call_id: str
langchain_tool_call_id: str | None = None
@ -97,13 +96,12 @@ def iter_tool_start_frames(
if run_id
else streaming_service.generate_tool_call_id()
)
if state.parity_v2:
langchain_tool_call_id = match_buffered_langchain_tool_call_id(
state.pending_tool_call_chunks,
tool_name,
run_id,
state.lc_tool_call_id_by_run,
)
langchain_tool_call_id = match_buffered_langchain_tool_call_id(
state.pending_tool_call_chunks,
tool_name,
run_id,
state.lc_tool_call_id_by_run,
)
yield streaming_service.format_tool_input_start(
tool_call_id,
tool_name,