Files
memex/notes/org-skill-provider-groq.org

2.6 KiB

SKILL: Groq Provider Agent (Universal Literate Note)

Overview

The Groq Provider Agent leverages Groq's LPU (Language Processing Unit) for ultra-low latency inference. It is ideal for reflexive tasks and rapid interaction loops.

Phase A: Demand (PRD)

1. Purpose

Enable high-speed neural completion via the Groq API.

2. User Needs

  • Latency: Sub-second response times for System 1 "hunches".
  • Compatibility: OpenAI-compatible endpoint.
  • Reliability: Secure management of `$GROQ_API_KEY`.

Phase B: Blueprint (PROTOCOL)

1. Architectural Intent

Interface for executing ultra-fast neural requests.

2. Semantic Interfaces

`execute-groq-request`

:signature `(execute-groq-request prompt system-prompt &key model) :string` :description "Direct call to the Groq Cloud API."

Phase D: Build (Implementation)

(in-package :org-agent)

(defun execute-groq-request (prompt system-prompt &key model)
  (let ((api-key (uiop:getenv "GROQ_API_KEY"))
        (endpoint "https://api.groq.com/openai/v1/chat/completions")
        (model-id (or model "llama-3.3-70b-versatile")))
    (unless api-key (return-from execute-groq-request "(:type :LOG :payload (:text \"Groq API Key missing\"))"))
    (let* ((headers `(("Content-Type" . "application/json")
                      ("Authorization" . ,(format nil "Bearer ~a" api-key))))
           (body (cl-json:encode-json-to-string
                  `((model . ,model-id)
                    (messages . (( (role . "system") (content . ,system-prompt) )
                                 ( (role . "user") (content . ,prompt) )))))))
      (handler-case (let* ((response (dex:post endpoint :headers headers :content body :connect-timeout 5 :read-timeout 10))
                           (json (cl-json:decode-json-from-string response)))
                      (cdr (assoc :content (cdr (assoc :message (car (cdr (assoc :choices json))))))))
        (error (c) (format nil "(:type :LOG :payload (:text \"Groq Failure: ~a\"))" c))))))

Registration

(progn
  (org-agent:register-neuro-backend :groq #'execute-groq-request)
  
  (defskill :skill-provider-groq
    :priority 80
    :trigger (lambda (context) nil)
    :neuro (lambda (context) nil)
    :symbolic (lambda (action context) action)))