2.9 KiB
2.9 KiB
SKILL: Anthropic Provider Agent (Universal Literate Note)
- Overview
- Phase A: Demand (PRD)
- Phase B: Blueprint (PROTOCOL)
- Phase D: Build (Implementation)
- Registration
Overview
The Anthropic Provider Agent integrates Anthropic's Claude family of models as a pluggable System 1 (neural) backend. It enables high-intelligence reasoning, drafting, and analysis within the PSF.
Phase A: Demand (PRD)
1. Purpose
Define the interface for reliable communication with the Anthropic Messages API.
2. User Needs
- Connectivity: Reliable I/O with Claude models.
- Configurability: Model selection via Environment Configuration.
- Context Management: Leverage Claude's large context windows.
- Safety: Graceful error handling for API failures or missing keys.
3. Success Criteria
TODO API Authentication
TODO Model Resolution Loop
TODO Response Parsing Verification
Phase B: Blueprint (PROTOCOL)
2. Semantic Interfaces
`execute-anthropic-request`
:signature `(execute-anthropic-request prompt system-prompt &key model) :string` :description "Direct call to the Anthropic Messages API."
Phase D: Build (Implementation)
(in-package :org-agent)
(defun execute-anthropic-request (prompt system-prompt &key model)
(let ((api-key (uiop:getenv "ANTHROPIC_API_KEY"))
(endpoint "https://api.anthropic.com/v1/messages")
(model-id (or model "claude-3-5-sonnet-20240620")))
(unless api-key (return-from execute-anthropic-request "(:type :LOG :payload (:text \"Anthropic API Key missing\"))"))
(let* ((headers `(("Content-Type" . "application/json")
("x-api-key" . ,api-key)
("anthropic-version" . "2023-06-01")))
(body (cl-json:encode-json-to-string
`((model . ,model-id)
(max_tokens . 4096)
(system . ,system-prompt)
(messages . (( (role . "user") (content . ,prompt) )))))))
(handler-case (let* ((response (dex:post endpoint :headers headers :content body :connect-timeout 10 :read-timeout 30))
(json (cl-json:decode-json-from-string response)))
;; Anthropic response structure: content[0].text
(cdr (assoc :text (car (cdr (assoc :content json))))))
(error (c) (format nil "(:type :LOG :payload (:text \"Anthropic Failure: ~a\"))" c))))))
Registration
(progn
(org-agent:register-neuro-backend :anthropic #'execute-anthropic-request)
(defskill :skill-provider-anthropic
:priority 110
:trigger (lambda (context) nil)
:neuro (lambda (context) nil)
:symbolic (lambda (action context) action)))