Skip to content

修复#251:定时任务输出写入会话历史#282

Open
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-251-scheduled-task-history
Open

修复#251:定时任务输出写入会话历史#282
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:fix/issue-251-scheduled-task-history

Conversation

@Kailigithub
Copy link
Copy Markdown
Contributor

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

  • scheduled_context.py (新增): 定时任务输出日志模块
    • record_scheduled_output(): 每次 reflect 任务完成后追加一条记录到 temp/scheduled_context.jsonl
    • recent_scheduled_context(): 读取最近 6 小时内最多 3 条记录,返回格式化上下文字符串
  • agentmain.py (修改): reflect loop 完成后调用 record_scheduled_output()
  • frontends/chatapp_common.py (修改): with_scheduled_context() 包装用户消息,在 AgentChatMixin.run_agent() 中自动注入
  • frontends/fsapp.py (修改): Feishu 前端独立 run_agent() 也使用 with_scheduled_context()

Testing

  • python3 -m py_compile scheduled_context.py agentmain.py frontends/chatapp_common.py frontends/fsapp.py — 语法校验通过
  • 模拟 scheduler 触发后,手动检查 temp/scheduled_context.jsonl 有正确的 JSONL 条目写入
  • 模拟用户发送消息,验证上下文被正确预填充到 prompt

修复 #251

@lsdefine
Copy link
Copy Markdown
Owner

lsdefine commented May 7, 2026

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 temp/reflect_logs/. When the user asks about them, the agent should use its tools to read those files autonomously. That's how GA works — the agent fetches information itself, rather than having the frontend pre-fill context on its behalf.

Please consider redesigning around this principle: let the agent discover the information through its normal tool-use flow, not through frontend-side injection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants