Files
passepartout/skills/org-skill-llama-backend.org

2.6 KiB

SKILL: Llama.cpp Neuro-Backend (Sovereign Inference)

Overview

The Llama.cpp Backend allows the OpenCortex to use local, air-gapped inference. It connects to a `llama.cpp` server (typically running on the local network) and registers itself as a provider in the kernel's probabilistic cascade.

Phase B: Blueprint (PROTOCOL)

1. Architectural Intent

This skill acts as a proxy between the OpenCortex kernel and the Lisp-agnostic `llama.cpp` REST API. It implements the standard backend signature required by `register-probabilistic-backend`.

2. Semantic Interfaces

  • Endpoint: `(uiop:getenv "LLAMACPP_ENDPOINT")` (e.g., "http://10.10.10.x:8080")
  • Method: `POST /completion`
  • Response: JSON (parsed into Lisp)

Phase D: Build (Implementation)

Package Context

(in-package :opencortex)

The Inference Engine (llama-inference)

(defun llama-inference (prompt system-prompt &key (model "local-model"))
  "Sends a completion request to the local llama.cpp server."
  (let ((endpoint (uiop:getenv "LLAMACPP_ENDPOINT")))
    (unless endpoint
      (harness-log "LLAMA ERROR: LLAMACPP_ENDPOINT not set in environment.")
      (return-from llama-inference (list :error "LLAMACPP_ENDPOINT_MISSING")))

    (handler-case
        (let* ((full-prompt (format nil "System: ~a~%User: ~a~%Assistant:" system-prompt prompt))
               (payload (cl-json:encode-json-to-string 
                         `((:prompt . ,full-prompt)
                           (:n_predict . 1024)
                           (:stop . ("User:" "System:")))))
               (response (dex:post (format nil "~a/completion" endpoint)
                                   :content payload
                                   :headers '(("Content-Type" . "application/json"))))
               (data (cl-json:decode-json-from-string response)))
          (cdr (assoc :content data)))
      (error (c)
        (harness-log "LLAMA ERROR: Connection failed -> ~a" c)
        (list :error (format nil "~a" c))))))

Registration

(progn
  (register-probabilistic-backend :llama #'llama-inference)
  (harness-log "LLAMA: Local backend registered and active."))

(defskill :skill-llama-backend
  :priority 50
  :trigger (lambda (ctx) (declare (ignore ctx)) nil) ; Pure infrastructure skill
  :probabilistic nil
  :deterministic (lambda (action ctx) (declare (ignore ctx)) action))