Libr delegate

From fritzprix/libr-agent · View interactive version

Libr delegate is an AI agent skill from the GitHub repository fritzprix/libr-agent. Delegate work to a running LibrAgent desktop/headless instance via the local HTTP Session API (`POST /api/sessions`, messages, status, children, resume, terminate, delete). Use from Cursor (or other external harnesses) when LibrAgent is up and you need a LibrAgent session to run a task — optionally

How to use this skill

Skill file

Libr Delegate (Cursor → LibrAgent Session API)

Spawn and steer LibrAgent sessions over HTTP from Cursor. LibrAgent must

already be running (desktop or headless). This skill does not ship into

LibrAgent bundled_skills.

vs in-app `delegate`

| Caller | Mechanism |

| ----------------------------- | ---------------------------------------- |

| Cursor / scripts / Harbor | This skill → HTTP /api/sessions |

| Inside a LibrAgent agent turn | In-app delegate → agent__* tools |

Base URL

PORT=""
for f in "$HOME"/.libragent/http_port.*; do
  p=$(cat "$f" 2>/dev/null) || continue
  curl -sf -m 1 "http://127.0.0.1:$p/api/health" >/dev/null 2>&1 && PORT=$p && break
done
BASE="http://127.0.0.1:${PORT:-3030}"

Each backend writes its bound port to ~/.libragent/http_port.<pid> when

its HTTP server binds; several backends on one profile coexist, so the loop

picks the first port that answers health. Fallback is 3030.

Workflow

  1. Confirm LibrAgent is up — GET $BASE/api/health (or assistants list)
  2. Resolve assistantId — GET $BASE/api/assistants
  3. Write a self-contained handoff (LibrAgent child does not see Cursor

chat, parent workspace instructions, or workspace-local skills unless you

pass an absolute workspacePath)

  1. Create — write JSON payload to a file, validate non-empty JSON, then

POST $BASE/api/sessions (include request or create idle). See

references/session-api.md (preferred file recipe + empty-body guard)

  1. If idle — POST $BASE/api/sessions/:id/messages with {"content":"..."}
  2. Poll — GET $BASE/api/sessions/:id until terminal (prefer

scripts/poll-until-done.sh)

  1. Read result — GET $BASE/api/sessions/:id/messages
  2. On paused after crash — POST …/resume, then poll again
  3. Optional lineage — set parentSessionId; list with GET …/children
  4. Extract transcript before delete — dump

GET …/messages?limit=500 to a file (see below)

  1. Cleanup one-shot sessions — POST …/terminate then

DELETE …/sessions/:id (delete cascades descendants)

Curl recipes: references/session-api.md. Handoff / isolation:

references/handoff.md. Poll helper: scripts/poll-until-done.sh.

Extract transcript (API-side "trace") then delete

There is no HTTP /api/sessions/:id/trace and no ATIF/Markdown export

endpoint on the Session API. UI session export (Markdown / ATIF) is separate.

For Cursor/harness handoffs, the recoverable history is message JSON:

# After idle (or error) — save BEFORE delete
curl -sS "$BASE/api/sessions/$SID/messages?limit=500" \
  > ".libragent/work/libr-delegate-${SID}-messages.json"

debugging tool calls / failures (role user | assistant | tool)

expects .trace.json shape — only use it if the dump matches that format;

otherwise inspect the messages JSON directly

One-shot / automation default: always extract (or confirm you only need the

final assistant text) then terminate+delete so sessions do not accumulate.

Create payload essentials

{
  "assistantId": "<from GET /api/assistants>",
  "request": "<self-contained task + deliverable format>",
  "workspacePath": "/absolute/path/optional",
  "parentSessionId": "<optional exact parent session id>",
  "executionMode": "normal | yolo | unsafe",
  "name": "optional label"
}

tools must also auto-run

Polling rules

Wire status is always lowercase (serde(rename_all = "lowercase")):

idle | busy | paused | error | queued | provisioning.

| Status (wire) | Action |

| ---------------------------------- | --------------------------------------------------------- |

| busy / queued / provisioning | Wait with backoff; do not spam |

| idle (after work) | Read messages; treat latest assistant text as result |

| paused | POST …/resume once, then poll |

| error | Fail the handoff; do not claim success from partial prose |

Preferred poll (normalizes case; exits on terminal):

./.agents/skills/libr-delegate/scripts/poll-until-done.sh "$SID" "$BASE"

If writing a one-off loop, lowercase before match:

status=$(curl -sS "$BASE/api/sessions/$SID" \
  | python3 -c 'import sys,json; print(json.load(sys.stdin).get("status","").lower())')
case "$status" in idle|error|paused) break ;; esac

Follow-ups: another POST …/messages (queued if still busy).

Isolation (critical)

The LibrAgent session is not a clone of this Cursor chat:

workspacePath is set to that absolute path

Anti-patterns

a case Idle) branch never fires and the poll loops until timeout even

after the session finished (postmortem: editObject smoke, 2026-04)

(they are not part of the Session API)

workspacePath: WORKSPACE) → NameError → empty payload file → create

400 EOF while parsing a value

Related repo docs

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.