fix:优化Agent参数校验,避免中止推理

This commit is contained in:
jxxghp
2026-01-09 20:26:49 +08:00
parent 57d4786a7f
commit b9bd303bf8
2 changed files with 16 additions and 8 deletions
+2 -1
View File
@@ -29,7 +29,8 @@ class QueryDownloadTasksTool(MoviePilotTool):
description: str = "Query download status and list download tasks. Can query all active downloads, or search for specific tasks by hash or title. Shows download progress, completion status, and task details from configured downloaders." description: str = "Query download status and list download tasks. Can query all active downloads, or search for specific tasks by hash or title. Shows download progress, completion status, and task details from configured downloaders."
args_schema: Type[BaseModel] = QueryDownloadTasksInput args_schema: Type[BaseModel] = QueryDownloadTasksInput
def _get_all_torrents(self, download_chain: DownloadChain, downloader: Optional[str] = None) -> List[Union[TransferTorrent, DownloadingTorrent]]: @staticmethod
def _get_all_torrents(download_chain: DownloadChain, downloader: Optional[str] = None) -> List[Union[TransferTorrent, DownloadingTorrent]]:
""" """
查询所有状态的任务(包括下载中和已完成的任务) 查询所有状态的任务(包括下载中和已完成的任务)
""" """
+14 -7
View File
@@ -151,18 +151,21 @@ class MoviePilotToolsManager:
normalized[key] = int(value) normalized[key] = int(value)
except (ValueError, TypeError): except (ValueError, TypeError):
logger.warning(f"无法将参数 {key}='{value}' 转换为整数,保持原值") logger.warning(f"无法将参数 {key}='{value}' 转换为整数,保持原值")
normalized[key] = value normalized[key] = None
elif field_type == "number" and isinstance(value, str): elif field_type == "number" and isinstance(value, str):
try: try:
normalized[key] = float(value) normalized[key] = float(value)
except (ValueError, TypeError): except (ValueError, TypeError):
logger.warning(f"无法将参数 {key}='{value}' 转换为浮点数,保持原值") logger.warning(f"无法将参数 {key}='{value}' 转换为浮点数,保持原值")
normalized[key] = value normalized[key] = None
elif field_type == "boolean" and isinstance(value, str): elif field_type == "boolean":
# 转换字符串为布尔值 if isinstance(value, str):
normalized[key] = value.lower() in ("true", "1", "yes", "on") normalized[key] = value.lower() in ("true", "1", "yes", "on")
elif isinstance(value, (int, float)):
normalized[key] = value != 0
else:
normalized[key] = True
else: else:
# 其他类型保持原样
normalized[key] = value normalized[key] = value
return normalized return normalized
@@ -199,7 +202,11 @@ class MoviePilotToolsManager:
elif isinstance(result, int, float): elif isinstance(result, int, float):
formated_result = str(result) formated_result = str(result)
else: else:
formated_result = json.dumps(result, ensure_ascii=False, indent=2) try:
formated_result = json.dumps(result, ensure_ascii=False, indent=2)
except Exception as e:
logger.warning(f"结果转换为JSON失败: {e}, 使用字符串表示")
formated_result = str(result)
return formated_result return formated_result
except Exception as e: except Exception as e: