From 80559bdd7dd38b19df26d6293720d288d84f4cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Tue, 31 Mar 2026 14:29:24 +0800 Subject: [PATCH] _call_agent_v3 --- services/schedule_executor.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/services/schedule_executor.py b/services/schedule_executor.py index 07430cf..6fd6227 100644 --- a/services/schedule_executor.py +++ b/services/schedule_executor.py @@ -138,7 +138,7 @@ class ScheduleExecutor: logger.info(f"Executing scheduled task: {task_id} ({task.get('name', '')}) for bot={bot_id} user={user_id}") # 调用 agent - response_text = await self._call_agent_v2(bot_id, user_id, task) + response_text = await self._call_agent_v3(bot_id, user_id, task) # 写入日志 duration_ms = int((time.time() - start_time) * 1000) @@ -188,6 +188,31 @@ class ScheduleExecutor: return data["choices"][0]["message"]["content"] + async def _call_agent_v3(self, bot_id: str, user_id: str, task: dict) -> str: + """通过 HTTP 调用 /api/v3/chat/completions 接口(从数据库读取配置)""" + url = "http://127.0.0.1:8001/api/v3/chat/completions" + + payload = { + "messages": [{"role": "user", "content": task["message"]}], + "stream": False, + "bot_id": bot_id, + "session_id": f"schedule_{task['id']}", + "user_identifier": user_id, + } + + headers = { + "Content-Type": "application/json", + } + + async with aiohttp.ClientSession() as session: + async with session.post(url, json=payload, headers=headers, timeout=aiohttp.ClientTimeout(total=300)) as resp: + if resp.status != 200: + body = await resp.text() + raise RuntimeError(f"API returned {resp.status}: {body}") + data = await resp.json() + + return data["choices"][0]["message"]["content"] + def _update_task_after_execution(self, task_id: str, tasks_file: Path): """执行后更新 tasks.yaml""" try: