mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
core/agent: record every tool result before yielding them
A caller that goes away mid-batch (cancel, display error) left the results of tools that had already run out of history, so the retry ran them again. Append the collected results first, then emit the events.
This commit is contained in:
@@ -124,10 +124,14 @@ async def _execute_tool_calls(
|
||||
else:
|
||||
results = [await _run_one_tool(tools, call, max_result_chars=max_result_chars) for call in tool_calls]
|
||||
|
||||
# Record every result before yielding any: a caller that goes away mid-batch
|
||||
# (cancel, display error) must not lose work that already ran, or the retry
|
||||
# runs that tool a second time.
|
||||
for tool_msg, _err in results:
|
||||
messages.append(tool_msg)
|
||||
for tool_msg, err in results:
|
||||
if err is not None:
|
||||
yield err
|
||||
messages.append(tool_msg)
|
||||
yield ToolResultEvent(message=tool_msg)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user