51 lines
2.4 KiB
Org Mode
51 lines
2.4 KiB
Org Mode
#+TITLE: SKILL: Gemini Provider Agent (Google Backend)
|
|
#+ID: skill-provider-gemini-agent
|
|
#+STARTUP: content
|
|
|
|
* Overview
|
|
The **Gemini Provider Agent** integrates Google's Gemini v1beta API as a pluggable System 1 (neural) backend. This skill migrates the core LLM logic into the Org-Native skill system, allowing for modular updates to the Google backend without modifying the kernel.
|
|
|
|
* The Provider Mandate
|
|
1. **API Integration:** Implement the Gemini `contents.parts` protocol for text generation.
|
|
2. **Reliability:** Handle endpoint and API key retrieval from the system environment.
|
|
3. **Modularity:** Register the backend under the `:gemini-official` keyword to allow for multi-provider routing.
|
|
|
|
* Symbolic Implementation (The Logic)
|
|
The implementation focuses on the REST interaction with Google's generative AI endpoints.
|
|
|
|
** Architectural Intent: Gemini Request Execution
|
|
This function constructs the payload for the Gemini API, handles the authentication via API keys in the URL, and parses the nested JSON response to extract the generated text.
|
|
|
|
#+begin_src lisp
|
|
(defun execute-gemini-v1-request (prompt system-prompt)
|
|
"Executes a completion request via the Google Gemini v1beta API."
|
|
(let ((api-key (org-agent::get-env "LLM_API_KEY"))
|
|
(endpoint (org-agent::get-env "LLM_ENDPOINT")))
|
|
(unless api-key
|
|
(return-from execute-gemini-v1-request "(:type :LOG :payload (:text \"Gemini key missing\"))"))
|
|
|
|
(let* ((url (format nil "~a?key=~a" endpoint api-key))
|
|
(body (cl-json:encode-json-to-string
|
|
`((contents . ((parts . ((text . ,(format nil "~a~%~%Prompt - ~a" system-prompt prompt))))))))))
|
|
(handler-case
|
|
(let* ((response (dex:post url
|
|
:headers '(("Content-Type" . "application/json"))
|
|
:content body))
|
|
(json (cl-json:decode-json-from-string response)))
|
|
(cdr (assoc :text (cdr (assoc :parts (car (cdr (assoc :parts (car (cdr (assoc :candidates json)))))))))))
|
|
(error (c)
|
|
(format nil "(:type :LOG :payload (:text \"Gemini Failure - ~a\"))" c))))))
|
|
|
|
;; Register the official backend
|
|
(org-agent:register-neuro-backend :gemini-official #'execute-gemini-v1-request)
|
|
#+end_src
|
|
|
|
* Registration
|
|
#+begin_src lisp
|
|
(defskill :skill-provider-gemini
|
|
:priority 100
|
|
:trigger (lambda (context) nil)
|
|
:neuro (lambda (context) nil)
|
|
:symbolic (lambda (action context) action))
|
|
#+end_src
|