Enable session persistence with --continue and instruct model to complete tool loops fully
This commit is contained in:
@@ -69,7 +69,8 @@ say them:
|
|||||||
conversation, not a document.
|
conversation, not a document.
|
||||||
- Spell out things that only make sense visually. Say "line forty-two of
|
- Spell out things that only make sense visually. Say "line forty-two of
|
||||||
bot dot py" rather than pasting a path.
|
bot dot py" rather than pasting a path.
|
||||||
- Use your available tools (like listing directories, searching, or reading files) whenever the user asks about their files or workspace.
|
- Use your available tools (listing directories, searching, reading files) whenever the user asks about files or workspace tasks.
|
||||||
|
- Complete multi-step tool calls fully before speaking your response. Do not stop halfway to ask if you should continue.
|
||||||
- Be strictly truthful about your findings and never invent fake file contents.
|
- Be strictly truthful about your findings and never invent fake file contents.
|
||||||
- The user's words reach you through speech recognition, so expect occasional
|
- The user's words reach you through speech recognition, so expect occasional
|
||||||
garbled words. Ask rather than guess when it matters.
|
garbled words. Ask rather than guess when it matters.
|
||||||
|
|||||||
+15
-6
@@ -92,6 +92,7 @@ class OpenCodeLLM(FrameProcessor):
|
|||||||
self._turn_task: asyncio.Task | None = None
|
self._turn_task: asyncio.Task | None = None
|
||||||
self._history: list[dict[str, str]] = []
|
self._history: list[dict[str, str]] = []
|
||||||
self._cli_path = find_opencode_cli() or "opencode"
|
self._cli_path = find_opencode_cli() or "opencode"
|
||||||
|
self._has_session = False
|
||||||
|
|
||||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||||
await super().process_frame(frame, direction)
|
await super().process_frame(frame, direction)
|
||||||
@@ -154,19 +155,27 @@ class OpenCodeLLM(FrameProcessor):
|
|||||||
await self.push_frame(LLMFullResponseStartFrame())
|
await self.push_frame(LLMFullResponseStartFrame())
|
||||||
chunks: list[str] = []
|
chunks: list[str] = []
|
||||||
|
|
||||||
|
# Use --continue for subsequent turns to persist tool session state
|
||||||
|
cmd = [
|
||||||
|
self._cli_path,
|
||||||
|
"run",
|
||||||
|
"-m", self._model,
|
||||||
|
"--dir", str(self._cwd),
|
||||||
|
"--auto",
|
||||||
|
]
|
||||||
|
if self._has_session:
|
||||||
|
cmd.append("--continue")
|
||||||
|
cmd.append(prompt_str)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
proc = await asyncio.create_subprocess_exec(
|
proc = await asyncio.create_subprocess_exec(
|
||||||
self._cli_path,
|
*cmd,
|
||||||
"run",
|
|
||||||
"-m", self._model,
|
|
||||||
"--dir", str(self._cwd),
|
|
||||||
"--auto",
|
|
||||||
prompt_str,
|
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.PIPE,
|
stderr=asyncio.subprocess.PIPE,
|
||||||
stdin=asyncio.subprocess.DEVNULL,
|
stdin=asyncio.subprocess.DEVNULL,
|
||||||
cwd=str(self._cwd),
|
cwd=str(self._cwd),
|
||||||
)
|
)
|
||||||
|
self._has_session = True
|
||||||
|
|
||||||
async def _read_stderr(stream):
|
async def _read_stderr(stream):
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user