feat: stabilized org-agent two-way communication and UX
- Fixed kernel-to-Emacs communication bridge. - Resolved boot-time crashes in multiple skeletal skills. - Refined Chat skill prompt to eliminate conversational filler. - Updated Emacs UI to automatically clean up status markers. - Synchronized all fixes via Literate Org-mode documents. - Verified physical two-way interaction via simulation.
This commit is contained in:
@@ -20,11 +20,6 @@ Define the interface for unified communication with the OpenRouter API.
|
||||
- *Resilience:* Leverage auto-routing fallbacks.
|
||||
- *Transparency:* Proper identification via Referer and Title headers.
|
||||
|
||||
** 3. Success Criteria
|
||||
*** TODO Tiered Model Resolution
|
||||
*** TODO OpenAI-Compatible Payload Generation
|
||||
*** TODO Header Compliance Verification
|
||||
|
||||
* Phase B: Blueprint (PROTOCOL)
|
||||
:PROPERTIES:
|
||||
:STATUS: SIGNED
|
||||
@@ -38,35 +33,62 @@ Interfaces for executing neural completion requests via the unified OpenRouter g
|
||||
(defun execute-openrouter-request (prompt system-prompt)
|
||||
"Executes a completion request via the OpenRouter API.")
|
||||
|
||||
(defun get-openrouter-models ()
|
||||
"Returns a curated list of models across tiers.")
|
||||
(defun get-openrouter-tiered-model (tier)
|
||||
"Returns the preferred model ID for a given tier.")
|
||||
#+end_src
|
||||
|
||||
* Phase D: Build (Implementation)
|
||||
|
||||
** Request Execution
|
||||
#+begin_src lisp :tangle projects/org-skill-provider-openrouter/src/provider-logic.lisp
|
||||
(defun execute-openrouter-request (prompt system-prompt)
|
||||
(let ((api-key (uiop:getenv "OPENROUTER_API_KEY")))
|
||||
(unless api-key (return-from execute-openrouter-request "ERROR: Key missing"))
|
||||
(let ((model (get-tiered-model :fast "meta-llama/llama-3-70b-instruct")))
|
||||
;; Physical API call logic (mocked for refactor)
|
||||
(format nil "Executing OpenRouter request on ~a" model))))
|
||||
** Tiered Model Resolution
|
||||
#+begin_src lisp
|
||||
(defun get-openrouter-tiered-model (tier)
|
||||
(case tier
|
||||
(:powerful "anthropic/claude-3.5-sonnet")
|
||||
(:fast "google/gemini-2.0-flash-001")
|
||||
(:free "openrouter/auto")
|
||||
(t "openrouter/auto")))
|
||||
#+end_src
|
||||
|
||||
** Model Discovery
|
||||
#+begin_src lisp :tangle projects/org-skill-provider-openrouter/src/provider-logic.lisp
|
||||
(defun get-openrouter-models ()
|
||||
'((:id "anthropic/claude-3.5-sonnet" :context "200k" :tier :powerful)
|
||||
(:id "google/gemini-flash-1.5" :context "1m" :tier :fast)
|
||||
(:id "openrouter/auto" :context "varying" :tier :free)))
|
||||
** Request Execution
|
||||
#+begin_src lisp
|
||||
(defun execute-openrouter-request (prompt system-prompt)
|
||||
(let ((api-key (uiop:getenv "OPENROUTER_API_KEY"))
|
||||
(endpoint "https://openrouter.ai/api/v1/chat/completions"))
|
||||
|
||||
(unless api-key
|
||||
(return-from execute-openrouter-request
|
||||
"(:type :LOG :payload (:text \"OpenRouter API Key missing in environment\"))"))
|
||||
|
||||
(let* ((model (get-openrouter-tiered-model :fast))
|
||||
(headers `(("Content-Type" . "application/json")
|
||||
("Authorization" . ,(format nil "Bearer ~a" api-key))
|
||||
("HTTP-Referer" . "https://github.com/amr/org-agent")
|
||||
("X-Title" . "org-agent Sovereign Kernel")))
|
||||
(body (cl-json:encode-json-to-string
|
||||
`((model . ,model)
|
||||
(messages . (( (role . "system") (content . ,system-prompt) )
|
||||
( (role . "user") (content . ,prompt) )))))))
|
||||
|
||||
(handler-case
|
||||
(let* ((response (dex:post endpoint :headers headers :content body))
|
||||
(json (cl-json:decode-json-from-string response)))
|
||||
;; Extract content from OpenAI-style response: choices[0].message.content
|
||||
(cdr (assoc :content (cdr (assoc :message (car (cdr (assoc :choices json))))))))
|
||||
(error (c)
|
||||
(format nil "(:type :LOG :payload (:text \"OpenRouter Error: ~a\"))" c))))))
|
||||
#+end_src
|
||||
|
||||
* Registration
|
||||
#+begin_src lisp
|
||||
;; Register the backend with the kernel at load-time
|
||||
(org-agent:register-neuro-backend :openrouter #'execute-openrouter-request)
|
||||
|
||||
;; Update the cascade to prefer OpenRouter
|
||||
(setf org-agent:*provider-cascade* '(:openrouter :gemini))
|
||||
|
||||
(defskill :skill-provider-openrouter
|
||||
:priority 100
|
||||
:trigger (lambda (context) nil)
|
||||
:trigger (lambda (context) nil) ; Provider skills don't trigger OODA loops
|
||||
:neuro (lambda (context) nil)
|
||||
:symbolic (lambda (action context) action))
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user