Persist active run event history

This commit is contained in:
武阳
2026-05-07 17:40:46 +08:00
parent 847b74ffb8
commit d57570e527
5 changed files with 316 additions and 24 deletions
+26 -3
View File
@@ -1270,9 +1270,15 @@ class LocalCodingAgent:
self.last_run_result = result
return result
final_output = (
last_content
or 'Stopped: max turns reached before the model produced a final answer.'
final_output = self._build_max_turns_output(
max_turns=self.runtime_config.max_turns,
last_content=last_content,
tool_calls=tool_calls,
)
session.append_assistant(
final_output,
message_id=f'assistant_{len(session.messages)}',
stop_reason='max_turns',
)
_append_final_text_stream_events(stream_events, final_output)
result = AgentRunResult(
@@ -1299,6 +1305,23 @@ class LocalCodingAgent:
self.last_run_result = result
return result
@staticmethod
def _build_max_turns_output(
*,
max_turns: int,
last_content: str,
tool_calls: int,
) -> str:
lines = [
f'已达到本轮最大步骤上限({max_turns} 轮),为了避免继续空转,当前任务已暂停。',
]
if tool_calls:
lines.append('最后一轮已经执行完工具,但还没有来得及整理成最终回复。')
if last_content.strip():
lines.append(f'最后一次阶段说明:{last_content.strip()}')
lines.append('你可以继续补充指令,我会基于当前会话结果接着处理。')
return '\n\n'.join(lines)
def _query_model(
self,
session: AgentSessionState,