Skip to content

feat: auto-load recent sessions after restart (#218)#293

Open
succ985 wants to merge 1 commit into
lsdefine:mainfrom
succ985:feat/issue-218-startup-recall
Open

feat: auto-load recent sessions after restart (#218)#293
succ985 wants to merge 1 commit into
lsdefine:mainfrom
succ985:feat/issue-218-startup-recall

Conversation

@succ985
Copy link
Copy Markdown
Contributor

@succ985 succ985 commented May 7, 2026

Summary

After restart, automatically inject recent session context into the first user message so the agent doesn't lose conversational memory. Fixes #218.

Changes

  • frontends/startup_recall.py (new, ~150 lines): Scans model_responses/ for recent sessions, extracts real user-agent conversations, formats recall context.
  • agentmain.py (+10 lines): Centralized hook in GenericAgent.run() — triggers once per restart on first user message only.

Design Decisions

Decision Reason
Hook in agentmain.run() not per-frontend One code path covers all frontends (wechat/tg/feishu/discord/qq)
source == 'user' filter No injection for reflect/scheduler/internal tasks
History stays clean Recall injected into raw_query after history.append(), so session history isn't polluted
Env vars only, no mykey.py Simpler config: GA_STARTUP_RECALL_SESSIONS=5, GA_STARTUP_RECALL_LINES=8 (set SESSIONS=0 to disable)
Regex exact-match for trivial messages `^(hi

Config

Env Var Default Description
GA_STARTUP_RECALL_SESSIONS 5 Recent sessions to scan. 0 disables feature
GA_STARTUP_RECALL_LINES 8 Conversation turns per session to extract

Testing

  • ✅ Syntax check: all files pass py_compile
  • ✅ Unit tests: trivial message detection, disable via SESSIONS=0, recall extraction
  • ✅ End-to-end: restarted wechatapp.py 4 times, verified recall injection on first message each time
  • ✅ History integrity: self.history does not contain recall content

PR Checklist

After restart, inject recent session context into the first user message
so the agent doesn't lose all conversational memory.

- New module: frontends/startup_recall.py
  - Scans model_responses/ for recent sessions
  - Extracts real user-agent conversations (filters AUTO/autonomous)
  - Strips internal <summary> tags, keeps user-facing content
  - Configurable via GA_STARTUP_RECALL_SESSIONS and GA_STARTUP_RECALL_LINES

- agentmain.py: centralized hook in GenericAgent.run()
  - Triggers once per restart, only on first user message
  - source='user' filter (no injection for reflect/scheduler)
  - History stays clean (recall only in raw_query, not in history)

Closes lsdefine#218
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.

feat: auto-load recent sessions after restart to avoid cold-start memory loss

1 participant