mirror of https://github.com/aliasrobotics/cai.git
fix: inject compacted summary back into message_history and sharpen compaction prompt
After compaction, message_history.clear() wiped all context and the stored summary in COMPACTED_SUMMARIES was never re-injected, so the next runner turn started completely blank and the agent would repeat already-tried approaches. Fix: immediately after clearing, push a user+assistant exchange containing the summary into message_history so it flows through history_context on the next iteration as normal conversation context. Also: add an explicit 'Exhausted Approaches — DO NOT RETRY' section (§9) and 'Recommended Next Steps' section (§10) to the compaction prompt so the support model produces a checklist of dead ends the main agent must not revisit.
This commit is contained in:
parent
0235e9a284
commit
476efb3994
|
|
@ -1221,7 +1221,8 @@ After the analysis, provide a structured summary with these sections:
|
||||||
6. **All User Messages**: Complete list of user messages in order
|
6. **All User Messages**: Complete list of user messages in order
|
||||||
7. **Pending Tasks**: What still needs to be done
|
7. **Pending Tasks**: What still needs to be done
|
||||||
8. **Current Work**: What was being worked on when the conversation ended
|
8. **Current Work**: What was being worked on when the conversation ended
|
||||||
9. **Optional Next Step**: If there's a clear next action, mention it
|
9. **Exhausted Approaches — DO NOT RETRY**: Every technique, command, path, or attack vector that was attempted and failed. Format each as a bullet starting with ❌. Be specific (include exact commands, URLs, usernames, ports). This section is CRITICAL — the agent will use it to avoid wasting time on dead ends.
|
||||||
|
10. **Recommended Next Steps**: Concrete actions NOT yet tried, ordered by likelihood of success.
|
||||||
|
|
||||||
## Important Guidelines
|
## Important Guidelines
|
||||||
|
|
||||||
|
|
@ -1232,6 +1233,7 @@ After the analysis, provide a structured summary with these sections:
|
||||||
- Maintain technical accuracy - don't paraphrase technical terms
|
- Maintain technical accuracy - don't paraphrase technical terms
|
||||||
- The summary will be used as the primary context for resuming work, so completeness is crucial
|
- The summary will be used as the primary context for resuming work, so completeness is crucial
|
||||||
- When the conversation is resumed, it should feel like a natural continuation
|
- When the conversation is resumed, it should feel like a natural continuation
|
||||||
|
- Section 9 (Exhausted Approaches) is the most important section for offensive/hacking tasks: list every failed attempt so the agent doesn't loop.
|
||||||
|
|
||||||
This session is being continued from a previous conversation that ran out of context. The conversation is summarized below:"""
|
This session is being continued from a previous conversation that ran out of context. The conversation is summarized below:"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3525,6 +3525,28 @@ class OpenAIChatCompletionsModel(Model):
|
||||||
APPLIED_MEMORY_IDS[self.agent_name] = []
|
APPLIED_MEMORY_IDS[self.agent_name] = []
|
||||||
COMPACTED_SUMMARIES[self.agent_name] = [_summary]
|
COMPACTED_SUMMARIES[self.agent_name] = [_summary]
|
||||||
self.message_history.clear()
|
self.message_history.clear()
|
||||||
|
# Re-inject the summary as the first exchange so
|
||||||
|
# the next Runner turn has full context and won't
|
||||||
|
# repeat work that was already attempted.
|
||||||
|
self.message_history.append({
|
||||||
|
"role": "user",
|
||||||
|
"content": (
|
||||||
|
"<previous_session_memory>\n"
|
||||||
|
+ _summary
|
||||||
|
+ "\n</previous_session_memory>\n\n"
|
||||||
|
"This is your memory from the previous context window. "
|
||||||
|
"Use it to continue your work. "
|
||||||
|
"Do NOT retry any approach already marked as failed or exhausted."
|
||||||
|
),
|
||||||
|
})
|
||||||
|
self.message_history.append({
|
||||||
|
"role": "assistant",
|
||||||
|
"content": (
|
||||||
|
"Understood. I have reviewed my previous session memory. "
|
||||||
|
"I will continue the task using only new approaches "
|
||||||
|
"and will not repeat anything already attempted."
|
||||||
|
),
|
||||||
|
})
|
||||||
os.environ["CAI_CONTEXT_USAGE"] = "0.0"
|
os.environ["CAI_CONTEXT_USAGE"] = "0.0"
|
||||||
_console.print(
|
_console.print(
|
||||||
"[bold green]✓ Memory summary applied — "
|
"[bold green]✓ Memory summary applied — "
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue