修复#251:定时任务输出写入会话历史#282
Conversation
|
Thanks for the effort, but this approach conflicts with GA's core session management philosophy. In GA, the agent's memory = LLM conversation history + global memory. There is no separate "session store" that gets injected from outside. If the agent never produced or received certain information through its conversation loop, it shouldn't "remember" it. This PR injects scheduled task outputs into the user message at the frontend level — content that never went through the LLM's dialogue cycle. This creates an implicit state channel that bypasses the agent's own information retrieval mechanism. The correct pattern in GA: scheduled task results are already written to Please consider redesigning around this principle: let the agent discover the information through its normal tool-use flow, not through frontend-side injection. |
Summary
定时任务执行完成后,若通过 IM connector 向用户发送消息,该消息对用户可见,但不会进入当前聊天会话历史。这导致用户后续在同一入口追问「刚才日报说了什么」时,GA 像从未发过该消息一样,需要重新读取文件或重新推断。
Root Cause:
agentmain.py --reflect模式下的任务结果仅写入temp/reflect_logs/文件,IM 前端的会话历史(agent.history)无法感知这些输出。Fix: 引入
scheduled_context.py作为轻量通知日志模块,在 reflect runner 完成任务后将输出写入temp/scheduled_context.jsonl,前端在处理用户下一条消息时自动将最近 6 小时内(最多 3 条)的定时任务输出作为上下文预填充到 prompt 中。Changes
record_scheduled_output(): 每次 reflect 任务完成后追加一条记录到temp/scheduled_context.jsonlrecent_scheduled_context(): 读取最近 6 小时内最多 3 条记录,返回格式化上下文字符串record_scheduled_output()with_scheduled_context()包装用户消息,在AgentChatMixin.run_agent()中自动注入run_agent()也使用with_scheduled_context()Testing
python3 -m py_compile scheduled_context.py agentmain.py frontends/chatapp_common.py frontends/fsapp.py— 语法校验通过temp/scheduled_context.jsonl有正确的 JSONL 条目写入修复 #251