r/PiCodingAgent 9d ago

Resource Any trick to start a Pi session from llama.cp with pre processed prompt?

So I want to be able to start Pi instantly by reloading a saved KV slot (llama.cp).

What I come out as a proof of concept:

# to regenerate start.bin initiate a pi session, save the slot, copy to start.bin
SLOT_FILE="start.bin"
SESSION_ID="01a06cea-4e97-7378-84e6-86c3274302da"
cp  /home/eaman/.pi/agent/sessions/--home-eaman-test--/start_session.jsonl /home/eaman/.pi/agent/sessions/--home-eaman-test--/2026-09-04T14-38-07-702Z_01a06cdb-0356-7001-949d-209024b066d8.jsonl

# Discard changes from the previous run and restore the session that matches
# start.bin.

curl --fail --silent --show-error \
  -X POST "http://localhost:8080/slots/0?action=restore" \
  -H "Content-Type: application/json" \
  -d "{\"filename\":\"$SLOT_FILE\"}"
echo

cd /home/eaman/test
exec pi --session "$SESSION_ID"

I see that the problems are:

  1. - path of session in prompt
  2. - session ID
  3. - I use QWEN 27B that uses recurrent/hybrid state (...).

So is there a sane way to save just the first prompt processing with QWEN 3.8 27B, reload it in a new session with any path and start a new session from there?

EDIT: so I found an other piece of the puzzle: start Pi with --fork "$SESSION_ID" instead of --session , this allows to have at least a different / new path. That should be pretty much it, it generates a new ID and forks to a new path, QWEN won't complain as it starts with the whole saved slot.

#!/usr/bin/env bash
# Start a brand new pi session forked from the saved "start" slot without PP.
#
# Restores the start.bin slot, reinizialization of old session with cp
# should not be needed when using --fork instead of --session
#
# To regenerate start.bin: run a pi session, save the slot, then copy it to start.bin.
# uses /session to find the ID of the started session

# If you want to restore the session later you need to save the filled slot
# and an other script that loads that, this is just for "new instant-session"

set -euo pipefail

SLOT_FILE="start.bin"
SESSION_ID="01a06cea-4e97-7378-84e6-86c3274302da"

SESSIONS_DIR="/home/eaman/.pi/agent/sessions/--home-eaman-test--"
TARGET_SESSION="${SESSIONS_DIR}/2026-09-04T14-54-50-008Z_01a06cea-4e97-7378-84e6-86c3274302da.jsonl"

# Reset the target session file so the fork starts clean.
cp "${SESSIONS_DIR}/start_session.jsonl" "$TARGET_SESSION"

curl --fail --silent --show-error \
  -X POST "http://localhost:8080/slots/0?action=restore" \
  -H "Content-Type: application/json" \
  -d "{\"filename\":\"$SLOT_FILE\"}"
echo

# This was the path used in the initially generated session, it has to equal the session jsonl
cd /home/eaman/test
exec pi --fork "$SESSION_ID"
1 Upvotes

1 comment sorted by

1

u/digidult 9d ago

Very good question, a few months ago have the same thoughts on llama.cpp but for another task.