Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions astrbot/core/agent/runners/tool_loop_agent_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,32 @@ async def _complete_with_assistant_response(self, llm_resp: LLMResponse) -> None
logger.error(f"Error in on_agent_done hook: {e}", exc_info=True)
self._resolve_unconsumed_follow_ups()

def _yield_llm_result_response(
self, llm_resp: LLMResponse
) -> T.Generator[AgentResponse, None, None]:
"""Yield an AgentResponse for llm_result based on llm_resp content."""
if llm_resp.result_chain:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(chain=llm_resp.result_chain),
)
elif llm_resp.completion_text:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(
chain=MessageChain().message(llm_resp.completion_text),
),
)
elif llm_resp.reasoning_content:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(
chain=MessageChain(type="reasoning").message(
llm_resp.reasoning_content,
),
),
)

@override
async def reset(
self,
Expand Down Expand Up @@ -718,18 +744,8 @@ async def step(self):
await self._complete_with_assistant_response(llm_resp)

# 返回 LLM 结果
if llm_resp.result_chain:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(chain=llm_resp.result_chain),
)
elif llm_resp.completion_text:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(
chain=MessageChain().message(llm_resp.completion_text),
),
)
for response in self._yield_llm_result_response(llm_resp):
yield response

# 如果有工具调用,还需处理工具调用
if llm_resp.tools_call_name:
Expand All @@ -739,18 +755,8 @@ async def step(self):
logger.warning(
"skills_like tool re-query returned no tool calls; fallback to assistant response."
)
if llm_resp.result_chain:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(chain=llm_resp.result_chain),
)
elif llm_resp.completion_text:
yield AgentResponse(
type="llm_result",
data=AgentResponseData(
chain=MessageChain().message(llm_resp.completion_text),
),
)
for response in self._yield_llm_result_response(llm_resp):
yield response
await self._complete_with_assistant_response(llm_resp)
return

Expand Down
Loading