feat(memory-reflection)+feat(self-improvement): focus self-improvement flow and support dedicated reflection agent#43
Conversation
|
Local + CI verification looks good on my side (cli-smoke / gateway load / export+import dry-run / delete-bulk dry-run / migrate check / reembed dry-run). Before moving this PR from Draft -> Ready, I suggest addressing two items (also mentioned in the PR description):
(Optional) The embedded runner import path may be sensitive to OpenClaw install layout changes; a clearer warn + fallback strategy would help if layout changes in the future. Once these are addressed and the PR is marked Ready, I can give LGTM and proceed with merge + release. |
- squash prior commits 51b6bb6 + 2293550 with current changes - add embedded -> openclaw agent --local --json -> fallback chain - validate memoryReflection.agentId with warn + runtime fallback - remove /root workspace hardcode; prefer runtime workspace and home fallback - harden reflection file naming/write collision handling and session file mtime fallback - update README/README_CN behavior docs for trigger/store conditions
2293550 to
94389e9
Compare
The "Invariants & Reflections" naming adjustment is included in the final result (retained as net effect). |
Code Review — Cross-Model AnalysisPR scope: +2,118 / −197 lines across 7 files Recommendation: Split Into Two PRsSelf-Improvement and Memory Reflection share no state, data flow, or config namespace. Recommend splitting into:
#43a — Self-Improvement: Looks GoodThe tool implementations are clean, #43b — Memory Reflection: Issues to Discuss1. Default Behavior Regression (Breaking Change)Upgrading silently switches all existing users from no session hooks to Suggestion: Default to 2.
|
# Conflicts: # index.ts # src/tools.ts
|
@rwmjhb Thanks for the cross-model review. I re-checked all discussed points and applied the requested fixes in this PR branch. Addressed in this PR
Clarifications on review suggestionsOn splitting into two PRs: I prefer to keep this as one PR at this point. On the large On PR management updates
Included recent commits
|
PR43 Comment DraftThanks for the detailed follow-up and for addressing the items from @rwmjhb's review. I re-tested specifically against the updated memoryReflection half, and the fixes you listed here do look aligned with the code on this branch. What still seems blocked on my side is not the revised hook registration itself, but the runtime behavior of Gateway 2026.3.2. In my QA environment:
What I expected to see, but did not see:
So at this point I’m leaning toward this being an upstream Gateway 2026.3.2 runtime issue / regression, rather than a problem in this updated PR branch itself. Could you help confirm:
From my side, the remaining concern is mainly this upstream runtime blocker around the memoryReflection trigger path. |
…etry-once fix: retry reflection transient upstream failures once
|
Follow-up update for this PR:
|
|
@AliceLJY Thanks — I re-checked this specifically against my local OpenClaw On my side, with 2026.3.2:
So at least in my environment, the reset/new hook path is not universally non-functional. I think the remaining concern needs a narrower config/runtime split before we classify it as a Gateway blocker:
So the remaining possibilities seem narrower:
My suggestion would be to confirm the exact QA config first (especially |
…slices (#2) * refactor(reflection): split invariants vs derived and tighten slice extraction * fix(memory-reflection): recover sessions from agent dirs --------- Co-authored-by: furedericca <263020793+furedericca-lab@users.noreply.github.com>
…nt-reflection-agent
Co-authored-by: furedericca <263020793+furedericca-lab@users.noreply.github.com>
…nt-reflection-agent
|
Final update for this PR:
Current branch status after the final sync/review:
Verification run used for the added focused coverage:
At this point I do not see a remaining known blocker on this branch from my side. |
|
Follow-up after a more complete runtime check on Gateway 2026.3.2. I think the main blocker here is now narrowed down to a plugin-side What I verified:
I tested 3 paths:
In all cases, hook dispatch is reachable, but The likely root cause is in
That matches what I observed in runtime:
One more important distinction:
Suggested fix:
Something like: const sourceAgentId = parseAgentIdFromSessionKey(sessionKey) || "main";
searchDirs.add(join(homedir(), ".openclaw", "agents", sourceAgentId, "sessions"));
searchDirs.add(join(workspaceDir, "sessions"));and if unresolved: api.logger.warn(
`memory-reflection: could not resolve session file for ${sessionKey} (${currentSessionId}); searched: ${Array.from(searchDirs).join(", ")}`
);At this point my current conclusion is:
|
Background
In long-running agent setups, users need more than one-off replies. They need a durable behavior system that can:
This PR aligns two feature tracks to support that system:
Self-ImprovementmemoryReflectionWhy This Feature Is Needed
Self-Improvementhandles governance and accumulation (log,review,skill extraction).memoryReflectionhandles session reflection memoryization and exports inheritance/derived deltas for subsequent runs.Together, they upgrade the agent from single-turn behavior into a cumulative, reusable, self-correcting long-term behavior system.
What This PR Changes
1. Self-Improvement governance workflow
self_improvement_logself_improvement_reviewself_improvement_extract_skillsrc/self-improvement-files.ts.learnings/LEARNINGS.md.learnings/ERRORS.md.learnings/FEATURE_REQUESTS.md2. memoryReflection closed-loop workflow
/newand/reset, generates structured reflection from recent session JSONL.<inherited-rules>(stable constraints)<derived-focus>/<error-detected>(execution deltas and error reminders)3. Dedicated reflection runner agent
memoryReflection.agentId.memory-distiller).4. Runtime hardening and schema/docs updates
embedded runner->openclaw agent --local --json->minimal fallback textworkspaceDir~/.openclaw/workspace(no/roothardcode)memoryReflection.agentIdagainst configured agents:mtimeopenclaw.plugin.json,README.md, andREADME_CN.mdto match current behavior.scripts/jsonl_distill.py(stale comment removal).5. Post-review compatibility and reflection correctness fixes
sessionStrategytosystemSessionMemory(compatibility-first behavior for existing users).sessionMemory.enabledmapping semantics unchanged (true -> systemSessionMemory,false -> none).conversation.slice(-maxInputChars)) instead of oldest-first clipping.Trigger Conditions
Reflection generation trigger
sessionStrategymust bememoryReflection(explicitly configured; not default).command:new/command:reset.cfg, missing session file, or no readable conversation content).Reflection runner chain
runEmbeddedPiAgent).openclaw agent --local --json.LanceDB write trigger
memoryReflection.storeToLanceDB(effective only whensessionStrategy=memoryReflection).> 0.97hit skips storing).Compatibility Notes
memoryReflection.agentIdbehavior is additive and optional.sessionStrategy.Findings (By Severity)
Medium (Addressed in this PR updates)
sessionStrategyfrommemoryReflectiontosystemSessionMemoryto avoid implicit behavior shift for existing users.slice(0, maxInputChars)toslice(-maxInputChars)so recent decisions are preserved.Low (Addressed)
/root/.openclaw/workspacein multiple places (Resolved): now prefers runtimecontext.workspaceDir/toolCtx.workspaceDir; fallback ishomedir() + "/.openclaw/workspace"(no/roothardcode).memoryReflection.agentIdvalidation and fallback (Resolved): when configured id is absent incfg.agents.list, plugin logslogger.warnand forces fallback to current runtime agentId (no silent degrade).Residual Risk
openclaw agent --local --jsonoutput prelude may vary across CLI versions; parser tolerates leading non-JSON lines, but still depends on recoverable JSON payloads.memoryReflectionremains an opt-in path, but when enabled it adds pre-reset work (/newand/reset) and can increase latency under CLI fallback/timeout scenarios.index.tswith limited focused unit tests for key helpers (for example secret redaction and reflection-slice extraction).Test Checklist
npm test(CLI smoke) passed.openclaw --helpopenclaw agent --helpopenclaw agent --local --jsonexecution verified and JSON payload shape inspected in this environment./root/.openclaw/workspaceliterals in plugin source scope.Included Commits
9cab679feat: integrate memory-reflection/self-improvement and harden session safetye3bd720feat: focused self-improvement and memory-reflection pipeline1206e14fix(memory-reflection): prevent stale derived-focus replay on fallback94389e9feat(memory-reflection): harden runner fallback and reflection flow7fdb06eMerge remote-tracking branch 'upstream/main'3f6769efix(session-strategy): keep default compatible and trim reflection input tail6a6fb51refactor(types): narrow reflection runner boundary from any to unknown5c2ee3cfeat(reflection): unify reflection category and display tag format828f7f3docs: document mdMirror dual-write behavior and reflection tag format10bad30Merge remote-tracking branch 'upstream/main'