JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(cron): mode参数记录在cron_jobs中
cycong_1682eeca2506a
diff --git a/jiuwenclaw/agentserver/deep_agent/cron_runtime.py b/jiuwenclaw/agentserver/deep_agent/cron_runtime.pyindex aa276d4a89..ba6c242e09 100644--- a/jiuwenclaw/agentserver/deep_agent/cron_runtime.py+++ b/jiuwenclaw/agentserver/deep_agent/cron_runtime.py@@ -302,6 +302,18 @@ def _extract_legacy_params(out["enabled"] = bool(data.get("enabled"))if "wake_offset_seconds" in data:out["wake_offset_seconds"] = data.get("wake_offset_seconds")++ context_mode = getattr(context, "mode", None)+ mode_resolved = (+ context_mode+ or data.get("mode")+ or "agent"+ )+ out["mode"] = (+ str(mode_resolved).strip().lower()+ if isinstance(mode_resolved, str) and str(mode_resolved).strip()+ else "agent"+ )return outreturn datadiff --git a/jiuwenclaw/gateway/cron/controller.py b/jiuwenclaw/gateway/cron/controller.pyindex 4f3ae8c1d6..af20005af5 100644--- a/jiuwenclaw/gateway/cron/controller.py+++ b/jiuwenclaw/gateway/cron/controller.py@@ -127,6 +127,7 @@ class CronController:description = str(params.get("description") or "")wake_offset_seconds = params.get("wake_offset_seconds", None)raw_targets = params.get("targets")+ mode = params.get("mode")targets = self._normalize_targets(raw_targets)self._validate_schedule(cron_expr=cron_expr, timezone=timezone)@@ -145,6 +146,7 @@ class CronController:targets=targets,session_id=routing_sid,chat_type=chat_type,+ mode=mode,)await self._scheduler.reload()return job.to_dict()diff --git a/jiuwenclaw/gateway/cron/models.py b/jiuwenclaw/gateway/cron/models.pyindex 77b3fbb248..7c47654176 100644--- a/jiuwenclaw/gateway/cron/models.py+++ b/jiuwenclaw/gateway/cron/models.py@@ -104,6 +104,8 @@ class CronJob:updated_at: float | None = None# 记录定时任务是在群聊("group")还是私聊("p2p")中创建的,用于推送时决定是否走 IMOutboundPipelinechat_type: str | None = None+ # 定时任务执行时使用的 mode("plan" 或 "agent"),创建时从对话上下文继承;无上下文时默认 "agent"+ mode: str = "agent"def to_dict(self) -> dict[str, Any]:d: dict[str, Any] = {@@ -123,6 +125,8 @@ class CronJob:d["session_id"] = self.session_idif self.chat_type:d["chat_type"] = self.chat_type+ if self.mode:+ d["mode"] = self.modereturn d@staticmethod@@ -186,6 +190,12 @@ class CronJob:else None)+ mode_raw = data.get("mode", None)+ job_mode = (+ str(mode_raw).strip().lower()+ if isinstance(mode_raw, str) and str(mode_raw).strip()+ else "agent"+ )return CronJob(id=job_id,name=name,@@ -200,6 +210,7 @@ class CronJob:created_at=created_at_f,updated_at=updated_at_f,chat_type=job_chat_type,+ mode=job_mode,)diff --git a/jiuwenclaw/gateway/cron/scheduler.py b/jiuwenclaw/gateway/cron/scheduler.pyindex 5ca9ea526a..25d484bcef 100644--- a/jiuwenclaw/gateway/cron/scheduler.py+++ b/jiuwenclaw/gateway/cron/scheduler.py@@ -344,6 +344,7 @@ class CronSchedulerService:params={"content": job.description,"query": job.description,+ "mode": job.mode or "agent","cron": {"job_id": job.id,"job_name": job.name,diff --git a/jiuwenclaw/gateway/cron/store.py b/jiuwenclaw/gateway/cron/store.pyindex 14a8797b91..56d6e7ce44 100644--- a/jiuwenclaw/gateway/cron/store.py+++ b/jiuwenclaw/gateway/cron/store.py@@ -62,10 +62,12 @@ class CronJobStore:wake_offset_seconds: int | None = None,session_id: str | None = None,chat_type: str | None = None,+ mode: str | None = None,) -> CronJob:now = time.time()sid = str(session_id).strip() if isinstance(session_id, str) and session_id.strip() else Nonect = str(chat_type).strip() if isinstance(chat_type, str) and chat_type.strip() else None+ m = str(mode).strip().lower() if isinstance(mode, str) and mode.strip() else "agent"job = CronJob(id=str(job_id or "").strip() or uuid.uuid4().hex,name=str(name or "").strip(),@@ -79,6 +81,7 @@ class CronJobStore:created_at=now,updated_at=now,chat_type=ct,+ mode=m,)# validate via round-tripCronJob.from_dict(job.to_dict())@@ -131,6 +134,10 @@ class CronJobStore:updated = replace(updated, chat_type=new_ct)if "expired" in patch:updated = replace(updated, expired=bool(patch.get("expired")))+ if "mode" in patch:+ raw_mode = patch.get("mode")+ new_mode = str(raw_mode).strip().lower() if isinstance(raw_mode, str) and str(raw_mode).strip() else "agent"+ updated = replace(updated, mode=new_mode)updated.updated_at = time.time()CronJob.from_dict(updated.to_dict())diff --git a/jiuwenclaw/gateway/message_handler.py b/jiuwenclaw/gateway/message_handler.pyindex 04c70c7ea2..08d945cce9 100644--- a/jiuwenclaw/gateway/message_handler.py+++ b/jiuwenclaw/gateway/message_handler.py@@ -90,6 +90,7 @@ class MessageHandler(ABC):self._stream_tasks: dict[str, asyncio.Task] = {} # request_id -> taskself._stream_sessions: dict[str, str | None] = {} # request_id -> session_idself._stream_metadata: dict[str, dict[str, Any] | None] = {} # request_id -> request metadata+ self._stream_modes: dict[str, str] = {} # request_id -> mode (plan/agent)self._pending_evolution_approval: dict[str, str] = {} # session_id -> approval_request_idself._queued_supplement_input: dict[str, str] = {} # session_id -> queued_new_inputself._session_evolution_in_progress: set[str] = set()@@ -719,6 +720,10 @@ class MessageHandler(ABC):elif action == "get":data = await cc.get_job(str(params.get("job_id") or ""))elif action == "create":+ # 从原始请求中获取 mode,覆盖 LLM 工具调用的默认值+ request_mode = self._stream_modes.get(request_id)+ if request_mode:+ params["mode"] = request_modedata = await cc.create_job(params)elif action == "update":data = await cc.update_job(str(params.get("job_id") or ""), dict(params.get("patch") or {}))@@ -1160,6 +1165,9 @@ class MessageHandler(ABC):self._stream_tasks[stream_rid] = taskself._stream_sessions[stream_rid] = msg.session_idself._stream_metadata[stream_rid] = msg.metadata+ self._stream_modes[stream_rid] = (+ msg.params.get("mode", "plan") if isinstance(msg.params, dict) else "plan"+ )logger.info("[MessageHandler] Stream 任务已启动(后台运行): request_id=%s channel_id=%s 当前并发=%d",stream_rid, msg.channel_id, len(self._stream_tasks),@@ -1277,6 +1285,7 @@ class MessageHandler(ABC):self._stream_tasks.pop(rid, None)self._stream_sessions.pop(rid, None)self._stream_metadata.pop(rid, None)+ self._stream_modes.pop(rid, None)if session_id is not None and session_id not in self._stream_sessions.values():# Fallback cleanup when stream exits unexpectedly without evolution end signal.self._clear_session_evolution_in_progress(session_id)@@ -1441,6 +1450,7 @@ class MessageHandler(ABC):self._stream_tasks.clear()self._stream_sessions.clear()self._stream_metadata.clear()+ self._stream_modes.clear()self._session_evolution_in_progress.clear()self._pending_evolution_approval.clear()self._queued_supplement_input.clear()