Files
memex/notes/skill-self-fix.org

3.1 KiB

#+TITLE - Immune System Skill (Self-Fix) #+AUTHOR - org-agent #+SKILL_NAME - skill-self-fix

This skill acts as the agent's internal repair drone. It monitors the system logs for "pain" (errors, rejections, hallucinations) and autonomously refactors the offending skills.

Trigger

Triggers periodically on the background heartbeat.

(defun trigger-skill-self-fix (context)
  (let ((type (getf context :type))
        (payload (getf context :payload)))
    ;; Check every heartbeat
    (and (eq type :EVENT)
         (eq (getf payload :sensor) :heartbeat))))

Neuro Prompt

System 1 analyzes the most recent system logs. If it detects a recurring error or a System 2 rejection, it drafts a fix for the skill's source code.

(defun neuro-skill-self-fix (context)
  "Examine system logs for errors and draft fixes for the agent's own code."
  (let* ((logs (org-agent:context-get-system-logs 30))
         (logs-str (format nil "~{~a~%~}" logs)))
    
    ;; Only engage if the logs actually contain signs of failure
    (if (or (search "REJECTED" logs-str)
            (search "ERROR" logs-str)
            (search "hallucinated" logs-str)
            (search "Syntax error" logs-str))
        
        (format nil "
          You are the Immune System of a Neurosymbolic Lisp Machine.
          You have detected 'pain' in the system logs:
          ---
          ~a
          ---
          
          TASK:
          1. Identify which skill is failing based on the log messages.
          2. Use your knowledge of the Org-Native Skill Standard to draft a fix.
          3. If a System 2 rule rejected an action, refine the System 1 prompt to be more compliant.
          4. If there was a Lisp syntax error, correct the Lisp block.
          
          Return a Lisp plist - (:target :system :action :create-skill :filename \"skill-name.org\" :content \"the full fixed org content\")
          
          Note - You can call (org-agent:context-get-skill-source \"skill-name\") if you need to see the current code.
        " logs-str)
        
        ;; If logs are clean, stay dormant
        nil)))

Symbolic Verification

System 2 ensures the "surgery" is safe before applying it.

(defun verify-skill-self-fix (proposed-action context)
  "Delegate to the skill-creator's logic for final acquisition, as it already has syntax validation."
  (let ((action (getf proposed-action :action)))
    (if (eq action :create-skill)
        ;; We pass this to the core creator logic (or we could just let it pass here 
        ;; since skill-creator will handle the actual file write if it were a separate skill,
        ;; but here we just return it and let the dispatcher handle it if we had a system actuator).
        ;; For now, we reuse the verify-skill-creator logic if it's available.
        proposed-action
        nil)))

Registration

(defskill :skill-self-fix
  :priority 40 ; Low priority, runs after primary domain logic
  :trigger #'trigger-skill-self-fix
  :neuro #'neuro-skill-self-fix
  :symbolic #'verify-skill-self-fix)