refactor: merge economist skill into token-accountant
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
:PROPERTIES:
|
||||
:ID: f3e3a6b3-8cd8-4e64-a835-5cdf5d13b75b
|
||||
:CREATED: [2026-04-07 Tue 13:42]
|
||||
:EDITED: [2026-04-07 Tue 13:42]
|
||||
:EDITED: [2026-04-08 Wed 11:45]
|
||||
:END:
|
||||
#+TITLE: SKILL: Token Accountant Agent (Universal Literate Note)
|
||||
#+STARTUP: content
|
||||
#+FILETAGS: :infrastructure:budget:llm:psf:
|
||||
#+FILETAGS: :infrastructure:budget:llm:psf:economics:
|
||||
#+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.
|
||||
The *Token Accountant* is the governor of the Neural Engine. It manages the cost, reliability, and routing of LLM providers. Its primary mission is to ensure the PSF operates at maximum intelligence with minimum marginal cost by aggressively prioritizing subsidized free models when appropriate.
|
||||
|
||||
* Phase A: Demand (PRD)
|
||||
:PROPERTIES:
|
||||
:STATUS: SIGNED
|
||||
:END:
|
||||
|
||||
** 1. Purpose
|
||||
Autonomously manage the provider cascade and model selection to optimize for cost, speed, and reliability.
|
||||
|
||||
* Phase B: Blueprint (PROTOCOL)
|
||||
:PROPERTIES:
|
||||
@@ -17,11 +25,11 @@ The *Token Accountant* is the governor of the Neural Engine. it manages the cost
|
||||
:END:
|
||||
|
||||
** 1. Architectural Intent
|
||||
Maintain a dynamic, state-aware provider cascade. Detect provider "pain" (errors) and autonomously route around them.
|
||||
Maintain a state-aware provider cascade that routes around "pain" (failures) and dynamically selects models based on task complexity.
|
||||
|
||||
** 2. Semantic Interfaces
|
||||
|
||||
*** Dynamic Routing Logic
|
||||
*** Routing and Pain Management
|
||||
#+begin_src lisp :tangle ../projects/org-skill-token-accountant/src/accountant-logic.lisp
|
||||
(in-package :org-agent)
|
||||
|
||||
@@ -44,19 +52,27 @@ Maintain a dynamic, state-aware provider cascade. Detect provider "pain" (errors
|
||||
(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
|
||||
(:openrouter "moonshotai/kimi-k2.5")
|
||||
(:groq "llama-3.3-70b-versatile")
|
||||
(:gemini "gemini-1.5-flash-latest")
|
||||
(t nil)))
|
||||
"Returns the recommended model for the provider, prioritizing free/subsidized models. Updated April 2026."
|
||||
(let ((complexity (ignore-errors (uiop:symbol-call :org-agent.skills.org-skill-router :router-classify-complexity context))))
|
||||
(case provider
|
||||
(:openrouter
|
||||
(case complexity
|
||||
(:REASONING "meta-llama/llama-3.3-70b-instruct:free") ; High fidelity, zero cost
|
||||
(:COGNITION "qwen/qwen3.6-plus:free") ; Latest interaction, zero cost
|
||||
(t "meta-llama/llama-3.2-3b-instruct:free"))) ; Ultra-fast reflex, zero cost
|
||||
(:groq
|
||||
(case complexity
|
||||
(:REASONING "llama-3.3-70b-versatile")
|
||||
(t "llama-3.1-8b-instant")))
|
||||
(:gemini
|
||||
"gemini-1.5-flash-latest")
|
||||
(t nil))))
|
||||
|
||||
(defun token-accountant-patch-kernel ()
|
||||
"Hot-patches the kernel's cascade and model selector to use our dynamic logic."
|
||||
(setf org-agent:*provider-cascade* #'token-accountant-get-cascade)
|
||||
(setf org-agent:*model-selector-fn* #'token-accountant-get-model-for-provider))
|
||||
(setf org-agent::*model-selector-fn* #'token-accountant-get-model-for-provider))
|
||||
#+end_src
|
||||
|
||||
* Registration
|
||||
@@ -65,7 +81,9 @@ Maintain a dynamic, state-aware provider cascade. Detect provider "pain" (errors
|
||||
(token-accountant-patch-kernel)
|
||||
(defskill :skill-token-accountant
|
||||
:priority 100
|
||||
:trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :tool-error))
|
||||
:trigger (lambda (context)
|
||||
(let ((sensor (getf (getf context :payload) :sensor)))
|
||||
(or (eq sensor :tool-error) (eq sensor :cost-audit))))
|
||||
:neuro (lambda (context) nil)
|
||||
:symbolic (lambda (action context)
|
||||
(let ((p (getf (getf context :payload) :provider)))
|
||||
|
||||
Reference in New Issue
Block a user