2.9 KiB
2.9 KiB
Model Explorer Skill
This skill dynamically discovers all loaded LLM provider skills and lists their available models. It intercepts the `@agent list models` command and renders an Org-mode table.
Trigger Logic
(defun trigger-skill-model-explorer (context)
(let* ((payload (getf context :payload))
(sensor (getf payload :sensor))
(text (or (getf payload :text) "")))
(and (eq sensor :buffer-update)
(search "@agent list models" text :test #'string-equal))))
Symbolic Execution
Because this is a purely deterministic retrieval task, it completely bypasses the LLM (System 1) and executes entirely in the Symbolic (System 2) layer.
(defun build-org-table-for-models ()
"Introspects all skills to find providers and builds an Org-mode table string."
(let ((table-rows (list "| Provider | Model ID | Context |"
"|----------+----------+---------|")))
;; Iterate through all loaded skills in the kernel
(maphash (lambda (name skill)
(when (uiop:string-prefix-p "SKILL-PROVIDER-" (string-upcase name))
;; Extract the provider name cleanly (e.g., "OPENAI")
(let* ((provider-name (subseq (string-upcase name) 15))
(pkg-name (intern (format nil "ORG-AGENT.SKILLS.~a" (string-upcase name)) :keyword))
(pkg (find-package pkg-name))
(fn (when pkg (find-symbol "GET-AVAILABLE-MODELS" pkg))))
(when (and fn (fboundp fn))
(let ((models (funcall fn)))
(dolist (model models)
(push (format nil "| ~a | ~a | ~a |"
provider-name
(getf model :id)
(getf model :context))
table-rows)))))))
org-agent:*skills-registry*)
(format nil "~{~a~^~%~}" (nreverse table-rows))))
(defun execute-skill-model-explorer (proposed-action context)
"Constructs the Emacs actuator command to insert the table."
(declare (ignore proposed-action)) ; We don't use System 1's proposal
(let* ((table-string (build-org-table-for-models))
;; We use Emacs lisp to safely insert the table on the next line and align it.
(elisp-code (format nil "(progn (end-of-line) (insert \"\\n~a\\n\") (search-backward \"| Provider |\") (org-table-align))" table-string)))
`(:type :REQUEST
:target :emacs
:payload (:action :eval :code ,elisp-code))))
Registration
(defskill :skill-model-explorer
:priority 85 ; High priority to intercept before the general Router
:trigger #'trigger-skill-model-explorer
:neuro (lambda (context) nil) ; Bypass System 1
:symbolic #'execute-skill-model-explorer)