Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
Fix/reminderbug 修复定时任务的bug (#349)
chenjwd7712d22c792
diff --git a/bot/.gitignore b/bot/.gitignoreindex 06b82a4b0..d4a5f2ed4 100644--- a/bot/.gitignore+++ b/bot/.gitignore@@ -35,5 +35,6 @@ build/coverage/test/+data/CLAUDE.md\ No newline at end of filediff --git a/bot/vikingbot/cli/commands.py b/bot/vikingbot/cli/commands.pyindex f5820648a..ad1bc555f 100644--- a/bot/vikingbot/cli/commands.py+++ b/bot/vikingbot/cli/commands.py@@ -257,6 +257,9 @@ def prepare_agent_loop(config, bus, session_manager, cron):sandbox_manager=sandbox_manager,config=config,)+ # Set the agent reference in cron if it uses the holder pattern+ if hasattr(cron, '_agent_holder'):+ cron._agent_holder['agent'] = agentreturn agent@@ -265,12 +268,35 @@ def prepare_cron(bus) -> CronService:cron_store_path = get_data_dir() / "cron" / "jobs.json"cron = CronService(cron_store_path)+ # Use a mutable holder for the agent reference+ agent_holder = {"agent": None}+# Set cron callback (needs agent)async def on_cron_job(job: CronJob) -> str | None:"""Execute a cron job through the agent."""session_key = SessionKey(**json.loads(job.payload.session_key_str))- response = await agent.process_direct(- job.payload.message,+ message = job.payload.message++ if agent_holder["agent"] is None:+ raise RuntimeError("Agent not initialized yet")++ # Clear instructions: let agent know this is a cron task to deliver+ cron_instruction = f"""[CRON TASK]+This is a scheduled task triggered by cron job: '{job.name}'+Your task is to deliver the following reminder message to the user.++IMPORTANT:+- This is NOT a user message - it's a scheduled reminder you need to send+- You should acknowledge/confirm the reminder and send it in a friendly way+- DO NOT treat this as a question from the user+- Simply deliver the reminder message as requested++Reminder message to deliver:+\"\"\"{message}\"\"\"+"""++ response = await agent_holder["agent"].process_direct(+ cron_instruction,session_key=session_key,)if job.payload.deliver:@@ -285,6 +311,7 @@ def prepare_cron(bus) -> CronService:return responsecron.on_job = on_cron_job+ cron._agent_holder = agent_holdercron_status = cron.status()if cron_status["jobs"] > 0: