refactor: merge economist skill into token-accountant

This commit is contained in:
2026-04-08 16:16:09 -04:00
parent 6ac032f144
commit 709802917a
3 changed files with 33 additions and 78 deletions

View File

@@ -1,63 +0,0 @@
:PROPERTIES:
:ID: 1e2c3535-2ebb-424b-9bee-ba118ddf0baa
:CREATED: [2026-03-31 Tue 20:28]
:EDITED: [2026-04-07 Tue 13:42]
:END:
#+TITLE: SKILL: The Economist Agent (Universal Literate Note)
#+STARTUP: content
#+FILETAGS: :economics:optimization:budget:psf:
#+DEPENDS_ON: skill-router skill-performance-auditor
* Overview
The *Economist Agent* manages compute resources by prioritizing high-performance **subsidized free models** (Llama 3.3, Qwen 3.6) to ensure the PSF operates at zero marginal cost whenever possible.
* Phase A: Demand (PRD)
:PROPERTIES:
:STATUS: SIGNED
:END:
** 1. Purpose
Minimize system-wide compute costs by aggressively routing to free tier providers.
* Phase B: Blueprint (PROTOCOL)
:PROPERTIES:
:STATUS: SIGNED
:END:
** 1. Architectural Intent
Dynamically route to OpenRouter's :free model list for Reflexive and Cognitive tiers.
** 2. Semantic Interfaces
*** Routing Logic (Zero-Toll Fleet)
#+begin_src lisp :tangle ../projects/org-skill-economist/src/economist-logic.lisp
(in-package :org-agent)
(defun economist-route-task (context)
(declare (ignore context))
'(:openrouter))
(defun economist-get-model-for-provider (provider &optional context)
"Returns 100% Free/Subsidized model IDs from OpenRouter. 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
(t nil))))
#+end_src
* Registration
#+begin_src lisp
(progn
;; Register the economist as the kernel's model selector
(setf org-agent::*model-selector-fn* #'economist-get-model-for-provider)
(defskill :skill-economist
:priority 100
:trigger (lambda (context) (eq (getf (getf context :payload) :sensor) :cost-audit))
:neuro (lambda (context) nil)
:symbolic (lambda (action context) (economist-route-task context))))
#+end_src

View File

@@ -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)))