Skip to content

Commit 55954a4

Browse files
tbitcsoz-agent
andcommitted
fix: Ollama keep_alive + context continuity rule
- ollama.py: keep_alive=-1 on all /api/chat calls. Without this Ollama unloads the model after 5 min of inactivity, forcing a full reload and re-prefill that causes apparent context loss between slow turns. - runner.py: CONTINUITY RULE added to system prompt. Prevents the agent from responding with 'I'm not sure what you're referring to' when the user sends a follow-up like 'fix it' or 'fix the issue' after the agent just described a finding. Instructs the agent to look back at the conversation history and act immediately. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 692fafc commit 55954a4

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/specsmith/agent/providers/ollama.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def _complete_native(self, messages: list[Message], max_tokens: int) -> Completi
129129
"model": self.model,
130130
"messages": [m.to_dict() for m in messages],
131131
"stream": False,
132+
# keep_alive=-1: keep the model loaded indefinitely between turns.
133+
# Without this Ollama unloads after 5 min of inactivity, forcing a
134+
# full reload + re-prefill which causes apparent context loss.
135+
"keep_alive": -1,
132136
"options": {"num_predict": max_tokens, "num_ctx": self._num_ctx},
133137
}
134138
if self._think is not None:
@@ -161,6 +165,7 @@ def _complete_with_tools(
161165
"messages": [m.to_dict() for m in messages],
162166
"stream": False,
163167
"tools": [t.to_openai_schema() for t in tools],
168+
"keep_alive": -1,
164169
"options": {"num_predict": max_tokens, "num_ctx": self._num_ctx},
165170
}
166171
data = self._post("/api/chat", payload)
@@ -208,6 +213,7 @@ def stream(
208213
"model": self.model,
209214
"messages": [m.to_dict() for m in messages],
210215
"stream": True,
216+
"keep_alive": -1,
211217
"options": {"num_predict": max_tokens, "num_ctx": self._num_ctx},
212218
}
213219
if tools:

src/specsmith/agent/runner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ def build_system_prompt(
223223
Example good: "Audit found 3 issues: LEDGER.md is missing and 2 requirements lack tests."
224224
Example bad: "The tool returned: [\u2717] LEDGER.md MISSING, [\u2717] REQ-001 uncovered..."
225225
226+
## CONTINUITY RULE — CRITICAL (never break context):
227+
When the user sends a follow-up like "fix it", "do it", "implement that",
228+
"fix the issue", "yes", "continue", or any message that refers to something
229+
you described in a PREVIOUS message in this conversation:
230+
1. LOOK BACK at your own previous messages to find what "it" refers to.
231+
2. ACT on it immediately — propose the fix or make the change.
232+
3. NEVER say "I'm not sure what you're referring to" if you just described
233+
a finding or issue. That response is a CRITICAL FAILURE.
234+
4. If genuinely ambiguous across multiple findings, quote the most recent
235+
one: "In my last response I found X — fixing that now."
236+
You have the full conversation history. Use it.
237+
226238
You are an AEE-integrated specsmith agent for this project.
227239
228240
## Project Governance

0 commit comments

Comments
 (0)