fix: handle LLM response and execute event hook in ToolLoopAgent

This commit is contained in:
Soulter
2025-06-29 15:58:22 +08:00
parent 8e9c7544cf
commit 5f1dfa7599
@@ -89,19 +89,15 @@ class ToolLoopAgent(BaseAgentRunner):
)
continue
llm_resp_result = llm_response
break # got final response
break # got final response
if not llm_resp_result:
return
# 执行事件钩子
await self.pipeline_ctx.call_event_hook(
self.event, EventType.OnLLMResponseEvent, self.final_llm_resp
)
# 处理 LLM 响应
llm_resp = llm_resp_result
logger.info(f"LLMResp: {llm_resp}")
if llm_resp.role == "err":
# 如果 LLM 响应错误,直接返回错误信息
self.final_llm_resp = llm_resp
@@ -120,6 +116,11 @@ class ToolLoopAgent(BaseAgentRunner):
self.final_llm_resp = llm_resp
self.is_done = True
# 执行事件钩子
await self.pipeline_ctx.call_event_hook(
self.event, EventType.OnLLMResponseEvent, llm_resp
)
# 返回 LLM 结果
if llm_resp.result_chain:
yield AgentResponse(