diff --git a/src/cai/repl/commands/memory.py b/src/cai/repl/commands/memory.py index 9f963d4e..f2e283c8 100644 --- a/src/cai/repl/commands/memory.py +++ b/src/cai/repl/commands/memory.py @@ -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 7. **Pending Tasks**: What still needs to be done 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 @@ -1232,6 +1233,7 @@ After the analysis, provide a structured summary with these sections: - Maintain technical accuracy - don't paraphrase technical terms - 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 +- 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:""" diff --git a/src/cai/sdk/agents/models/openai_chatcompletions.py b/src/cai/sdk/agents/models/openai_chatcompletions.py index eac4cf30..4390f82d 100644 --- a/src/cai/sdk/agents/models/openai_chatcompletions.py +++ b/src/cai/sdk/agents/models/openai_chatcompletions.py @@ -3525,6 +3525,28 @@ class OpenAIChatCompletionsModel(Model): APPLIED_MEMORY_IDS[self.agent_name] = [] COMPACTED_SUMMARIES[self.agent_name] = [_summary] 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": ( + "\n" + + _summary + + "\n\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" _console.print( "[bold green]✓ Memory summary applied — "