feat(acp): keep the conversation when the AgentKit process restarts

Aperta
#38 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, backend

Direzione di ricerca

Start in runtimes/common/agentkit_serve_common/acp.py, especially the state.history append around line 872, and read the existing session/new and session/cancel handling. Run the ACP tests and add coverage for saving, resuming and closing sessions, including the listed error cases and file permissions. Done means the process can resume prior conversation text without replaying history notifications, and close cancels work and removes saved history.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/acp area/orka enhancement

Problem

When Orka runs an AgentKit agent, it starts agentkit-serve --protocol acp as a child process, one process per conversation. Orka and that process talk over ACP, the Agent Client Protocol. ACP is a set of JSON messages for starting a conversation, which ACP calls a session, sending a prompt, and getting the answer back.

AgentKit keeps the conversation history only in that process's memory. If the process stops between two messages, the history is gone. A crash, running out of memory, or a kill can all cause this.

AgentKit has no way to pick a conversation back up, so the next message fails. Orka then starts a new session and hands it a shortened text copy of the chat that Orka keeps on its side. That copy keeps only the most recent 50 messages by default and leaves out tool call details. Long conversations lose context.

What

Add two ACP requests to AgentKit's ACP mode in runtimes/common/agentkit_serve_common/acp.py.

  1. session/resume connects a fresh AgentKit process to an existing conversation by its session ID. The next prompt continues where the old process stopped.
  2. session/close ends a conversation cleanly when Orka deletes it. Today Orka can only stop the process.

Both requests are stable in ACP v1. See the ACP session setup docs.

Out of scope:

  • session/load. It sends the whole conversation back to the caller, and the ACP v2 draft removes it.
  • session/fork. ACP still marks it unstable, so its shape can change.
  • Keeping a conversation after Orka replaces the whole runtime Pod. Each session's files live in a temporary directory that goes away with the Pod.

Why

Orka is adding its side of this in orka-agents/orka#737. When an agent process stops between messages, Orka's supervisor, the program that starts and watches agent processes, starts a new one and sends session/resume. It only does this if the agent says it supports resume. Codex, Claude and OpenCode already do. AgentKit doesn't, so AgentKit conversations still fall back to the shortened copy.

With this change, an AgentKit conversation keeps its full history when the process restarts. Orka would use the shortened copy only when resume really can't work, for example after the Pod is replaced.

How

  1. Save the history to a file. After each successful prompt, right where acp.py appends to state.history around line 872, write the history to $XDG_STATE_HOME/agentkit/sessions/<session-id>.json. Orka gives every session its own private XDG_STATE_HOME. Fall back to ~/.local/state when the variable isn't set. Write to a temp file first and then rename it, so a crash never leaves a half-written file. Create the file with mode 0600. Save only the user and assistant text that history already holds. Never write environment variables, tokens or provider settings.
  2. Say that resume and close work. In the initialize response, change "sessionCapabilities": {} to {"resume": {}, "close": {}}.
  3. Handle session/resume. Run the same checks as session/new. That means one session per process, a cwd that matches the process working directory, at most one MCP server, and no additionalDirectories. Check that the session ID looks like agentkit- plus 32 hex characters before you use it in a file path. Load the saved history, build the runtime the same way _create_session does, and register the session under the same ID. Don't send the old messages back as session/update notifications, because the spec says resume must not replay history. If the file is missing or can't be parsed, return a JSON-RPC error. Orka then falls back to its own copy, which is the safe outcome.
  4. Handle session/close. Cancel any running prompt the same way session/cancel does, shut down the runtime, and delete the history file.

Done when

  • initialize reports resume and close under sessionCapabilities.
  • A test starts the ACP process, sends a prompt that states a fact, kills the process, starts a new one, resumes the session, and asks about that fact. The model request carries the earlier history, and the process sends no history back as notifications.
  • Resume returns a clear error for an unknown ID, a malformed ID, a missing or corrupt file, and a different cwd.
  • session/close cancels a running prompt and deletes the history file.
  • The history file has mode 0600 and contains only conversation text.
  • After this lands, the runtime support table that orka-agents/orka#737 adds to workers/acp/images/README.md can list AgentKit as supporting resume and close.
Lingua principale
Python
Stelle
7
Fork
5
Merge medio
3h 39m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di orka-agents/agentkit

Tutte le issue di orka-agents/agentkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.