3.8 KiB
3.8 KiB
SKILL: Router Agent (Universal Literate Note)
- Overview
- Phase A: Demand (PRD)
- Phase B: Blueprint (PROTOCOL)
- Phase D: Build (Implementation)
- Registration
Overview
The Router Agent is the system's "Pre-Frontal Cortex." It classifies unstructured user input, decomposes complex requests into atomic intents, and orchestrates delegation to specialized sub-agents.
Phase A: Demand (PRD)
1. Purpose
Define the interfaces for intent classification and sub-agent delegation.
2. User Needs
- Perception: Monitor for explicit commands and implicit `@agent` requests.
- Decomposition: Break natural language into sequential atomic operations.
- Efficiency: Utilize low-latency models for rapid routing.
- Dynamic Identity: Adapt triggers based on the active agent name.
3. Success Criteria
TODO @Agent Tag Detection
TODO Multi-Intent Decomposition
TODO Sub-agent Stimulus Injection
Phase B: Blueprint (PROTOCOL)
1. Architectural Intent
Interfaces for AST inspection and intent-driven stimulus injection. Source of truth is the dynamic kernel identity and the Org AST.
2. Semantic Interfaces
(defun trigger-skill-router (context)
"Triggers on :user-command or @agent requests in AST.")
(defun find-agent-request (ast agent-name)
"Recursive search for addressed headlines.")
(defun verify-skill-router (proposed-action context)
"Executes delegation by injecting new stimuli.")
Phase D: Build (Implementation)
Request Perception
(defun find-agent-request (ast agent-name)
(when (listp ast)
(let* ((type (getf ast :type))
(props (getf ast :properties))
(title (or (getf props :TITLE) "")))
(if (and (eq type :HEADLINE)
(or (search "@agent" title :test #'string-equal)
(search (format nil "@~a" agent-name) title :test #'string-equal)))
(let* ((pos (or (search "@agent" title :test #'string-equal)
(search (format nil "@~a" agent-name) title :test #'string-equal)))
(instruction (subseq title (+ pos (if (search "@agent" title :test #'string-equal) 6 (1+ (length agent-name)))))))
(string-trim '(#\Space #\Tab) instruction))
(cl:some (lambda (c) (find-agent-request c agent-name)) (getf ast :contents))))))
Symbolic Delegation
(defun verify-skill-router (proposed-action context)
(let ((type (getf proposed-action :type)))
(cond
((eq type :MULTI-DELEGATION)
(dolist (intent (getf proposed-action :intents))
(org-agent:inject-stimulus `(:type :EVENT :payload (:sensor :delegation ,@intent))))
nil)
((eq type :DELEGATION)
(org-agent:inject-stimulus `(:type :EVENT :payload (:sensor :delegation ,@(getf proposed-action :payload))))
nil)
(t '(:type :LOG :payload (:text "Router failed to classify."))))))
Routing Logic
(defun trigger-skill-router (context)
"Triggers on :user-command or :chat-message if no other skill handles it."
(let* ((payload (getf context :payload))
(sensor (getf payload :sensor)))
(or (eq sensor :user-command)
(eq sensor :chat-message))))
(defun neuro-skill-router (context)
"Neural stage for intent classification."
(let ((text (getf (getf context :payload) :text)))
(ask-neuro text :system-prompt "You are the PSF Router. Decompose the user's request into atomic sub-agent calls. Return a Lisp plist.")))
Registration
(defskill :skill-router
:priority 10
:trigger #'trigger-skill-router
:neuro #'neuro-skill-router
:symbolic #'verify-skill-router)