chore: structural cleanup of projects and patches
This commit is contained in:
67
notes/org-skill-token-accountant.org~
Normal file
67
notes/org-skill-token-accountant.org~
Normal file
@@ -0,0 +1,67 @@
|
||||
#+TITLE: SKILL: Token Accountant Agent (Universal Literate Note)
|
||||
#+STARTUP: content
|
||||
#+FILETAGS: :infrastructure:budget:llm:psf:
|
||||
#+DEPENDS_ON: skill-router
|
||||
|
||||
* Overview
|
||||
The *Token Accountant* is the governor of the Neural Engine. it manages the cost and reliability of LLM providers on-the-fly.
|
||||
|
||||
* Phase B: Blueprint (PROTOCOL)
|
||||
:PROPERTIES:
|
||||
:STATUS: SIGNED
|
||||
:END:
|
||||
|
||||
** 1. Architectural Intent
|
||||
Maintain a dynamic, state-aware provider cascade. Detect provider "pain" (errors) and autonomously route around them.
|
||||
|
||||
** 2. Semantic Interfaces
|
||||
|
||||
*** Dynamic Routing Logic
|
||||
#+begin_src lisp :tangle ../projects/org-skill-token-accountant/src/accountant-logic.lisp
|
||||
(in-package :org-agent)
|
||||
|
||||
(defvar *provider-pain-table* (make-hash-table :test 'equal))
|
||||
|
||||
(defun token-accountant-record-pain (provider)
|
||||
"Marks a provider as 'pained' (failed). It will be de-prioritized."
|
||||
(setf (gethash provider *provider-pain-table*) (+ (get-universal-time) 600)) ; 10 min penalty
|
||||
(kernel-log "ACCOUNTANT - Provider ~a de-prioritized due to failure." provider))
|
||||
|
||||
(defun token-accountant-get-cascade (context)
|
||||
"Returns a dynamic list of providers, routing around pained ones."
|
||||
(let ((all-providers '(:groq :openrouter :gemini))
|
||||
(healthy nil)
|
||||
(pained nil)
|
||||
(now (get-universal-time)))
|
||||
(dolist (p all-providers)
|
||||
(if (> (or (gethash p *provider-pain-table*) 0) now)
|
||||
(push p pained)
|
||||
(push p healthy)))
|
||||
(append (nreverse healthy) (nreverse pained))))
|
||||
|
||||
(defun token-accountant-get-model-for-provider (provider &optional context)
|
||||
"Returns the recommended model for the provider."
|
||||
(case provider
|
||||
(:groq "llama-3.3-70b-versatile")
|
||||
(:openrouter "meta-llama/llama-3.3-70b-instruct:free")
|
||||
(:gemini "gemini-1.5-flash")
|
||||
(t nil)))
|
||||
|
||||
(defun token-accountant-patch-kernel ()
|
||||
"Hot-patches the kernel's cascade to use our dynamic logic."
|
||||
(setf *provider-cascade* #'token-accountant-get-cascade))
|
||||
#+end_src
|
||||
|
||||
* Registration
|
||||
#+begin_src lisp
|
||||
(progn
|
||||
(token-accountant-patch-kernel)
|
||||
(defskill :skill-token-accountant
|
||||
:priority 100
|
||||
:trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :tool-error))
|
||||
:neuro (lambda (context) nil)
|
||||
:symbolic (lambda (action context)
|
||||
(let ((p (getf (getf context :payload) :provider)))
|
||||
(when p (token-accountant-record-pain p))
|
||||
action))))
|
||||
#+end_src
|
||||
Reference in New Issue
Block a user