mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 23:47:41 +08:00
feat(agent): log tool execution result summary and truncate if too long
This commit is contained in:
@@ -212,8 +212,15 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta):
|
|||||||
# 执行具体工具逻辑
|
# 执行具体工具逻辑
|
||||||
try:
|
try:
|
||||||
result = await self.run(**kwargs)
|
result = await self.run(**kwargs)
|
||||||
result_len = len(str(result)) if result is not None else 0
|
|
||||||
logger.debug(f"Tool {self.name} executed, raw result length: {result_len}")
|
# 记录工具执行结果摘要日志
|
||||||
|
str_result = serialize_tool_result_for_agent(result)
|
||||||
|
if len(str_result) > 500:
|
||||||
|
summary = str_result[:500] + f"...(已截断,总长度: {len(str_result)})"
|
||||||
|
else:
|
||||||
|
summary = str_result
|
||||||
|
logger.info(f"Agent工具 {self.name} 执行完成,结果摘要: {summary}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_message = f"工具执行异常 ({type(e).__name__}): {str(e)}"
|
error_message = f"工具执行异常 ({type(e).__name__}): {str(e)}"
|
||||||
logger.error(f"Tool {self.name} execution failed: {e}", exc_info=True)
|
logger.error(f"Tool {self.name} execution failed: {e}", exc_info=True)
|
||||||
|
|||||||
@@ -260,11 +260,16 @@ class MoviePilotToolsManager:
|
|||||||
# 调用工具的run方法。HTTP/MCP 工具调用不会经过 BaseTool._arun,
|
# 调用工具的run方法。HTTP/MCP 工具调用不会经过 BaseTool._arun,
|
||||||
# 因此这里也必须复用同一套返回值格式化和兜底截断逻辑。
|
# 因此这里也必须复用同一套返回值格式化和兜底截断逻辑。
|
||||||
result = await tool_instance.run(**normalized_arguments)
|
result = await tool_instance.run(**normalized_arguments)
|
||||||
return format_tool_result_for_agent(
|
|
||||||
result,
|
# 记录工具执行结果摘要日志
|
||||||
tool_name=tool_name,
|
str_result = format_tool_result_for_agent(result, tool_name=tool_name, max_chars=getattr(tool_instance, "result_max_chars", None))
|
||||||
max_chars=getattr(tool_instance, "result_max_chars", None),
|
if len(str_result) > 500:
|
||||||
)
|
summary = str_result[:500] + f"...(已截断,总长度: {len(str_result)})"
|
||||||
|
else:
|
||||||
|
summary = str_result
|
||||||
|
logger.info(f"Agent工具 {tool_name} 执行完成,结果摘要: {summary}")
|
||||||
|
|
||||||
|
return str_result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"调用工具 {tool_name} 时发生错误: {e}", exc_info=True)
|
logger.error(f"调用工具 {tool_name} 时发生错误: {e}", exc_info=True)
|
||||||
error_msg = json.dumps(
|
error_msg = json.dumps(
|
||||||
|
|||||||
Reference in New Issue
Block a user