fix: enforce long-term memory settlement on completion - #790
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of correctness/robustness issues in the updated logging flow and the new tests (determinism depends on filesystem/CWD) that should be fixed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR enforces the “15+ turns must trigger start_long_term_update on completion” requirement at runtime by adding a one-time completion gate that starts long-term memory evaluation before exiting long-running tasks (while preserving exemptions like autonomous flows and tool-unavailable configurations).
Changes:
- Add a per-task, one-time completion gate in
GenericAgentHandler.do_no_tool()that triggers long-term memory evaluation whenturn >= 15and settlement hasn’t started yet. - Track settlement gating state via
long_term_update_pending, and prevent duplicate settlement after explicitdo_start_long_term_update(). - Align EN/CN tool schema wording to “15 or more turns”, and add regression tests for threshold + one-time gate behavior.
File summaries
| File | Description |
|---|---|
ga.py |
Adds the turn >= 15 completion gate and refactors long-term update initiation to prevent duplicate settlement. |
agentmain.py |
Initializes the handler’s gate based on tool availability and autonomous-flow detection. |
assets/tools_schema.json |
Aligns English description wording to “15 or more turns”. |
assets/tools_schema_cn.json |
Aligns Chinese description wording to “达到15轮…”. |
tests/test_long_term_update_gate.py |
Adds regression coverage for threshold behavior and one-time gating. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
The auto-gate path inlines the long-term-update “tool result” into next_prompt instead of passing it via the normal tool_results channel, which can change prompt structure/behavior across backends and should be corrected before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
| outcome = yield from self.do_start_long_term_update({}, response) | ||
| return StepOutcome(None, next_prompt=f'{outcome.data}\n{outcome.next_prompt}') |
Closes #789
Summary
start_long_term_updatecallturn >= 15This forces memory evaluation, not unconditional memory modification. The evaluation may still conclude that nothing should be stored.
Behavior
The gate is scoped to one task. A new user request creates a new handler and resets the gate.
Testing
pytest tests/test_long_term_update_gate.py -qpython -m py_compile ga.py agentmain.pygit diff --check