3.7 KiB
3.7 KiB
SKILL: Anthropic Provider Agent (Claude Backend)
Overview
The Anthropic Provider Agent integrates Anthropic's Claude family of models as a pluggable System 1 (neural) backend for the Neurosymbolic Kernel. It enables the agent to utilize high-intelligence models for complex reasoning, drafting, and analysis tasks.
The Provider Mandate
- Connectivity: Ensure reliable communication with the Anthropic Messages API.
- Configurability: Dynamically resolve the specific Claude model to use based on the system's Environment Configuration.
- Context Management: Leverage Claude's large context windows (up to 200k) for deep codebase analysis.
- Safety: Handle API failures and missing credentials gracefully by logging errors rather than crashing the kernel.
Symbolic Implementation (The Logic)
The implementation focuses on the API request/response cycle and model discovery.
Architectural Intent: Backend Request Execution
This function handles the physical I/O with the Anthropic API. It retrieves credentials from the environment, model settings from the Config skill, and formats the request according to the Anthropic Messages protocol.
(defun execute-anthropic-request (prompt system-prompt)
"Executes a completion request via the Anthropic (Claude) API."
(let ((api-key (org-agent::get-env "ANTHROPIC_API_KEY"))
(config-pkg (find-package :org-agent.skills.skill-environment-config)))
(unless api-key
(return-from execute-anthropic-request "(:type :LOG :payload (:text \"Anthropic key missing\"))"))
(let* ((get-config-fn (when config-pkg (find-symbol "GET-CONFIG-ATTRIBUTE" config-pkg)))
(model (if (and get-config-fn (fboundp get-config-fn))
(funcall get-config-fn :LLM_MODEL_ANTHROPIC "claude-3-5-sonnet-20240620")
"claude-3-5-sonnet-20240620"))
(url "https://api.anthropic.com/v1/messages")
(body (cl-json:encode-json-to-string
`((model . ,model)
(max_tokens . 1024)
(system . ,system-prompt)
(messages . (((role . "user") (content . ,prompt))))))))
(handler-case
(let* ((response (dex:post url
:headers `(("Content-Type" . "application/json")
("x-api-key" . ,api-key)
("anthropic-version" . "2023-06-01"))
:content body))
(json (cl-json:decode-json-from-string response)))
;; Extract content from Anthropic response
(cdr (assoc :text (car (cdr (assoc :content json))))))
(error (c)
(format nil "(:type :LOG :payload (:text \"Anthropic Failure (~a) - ~a\"))" model c))))))
;; Register the backend
(org-agent:register-neuro-backend :anthropic #'execute-anthropic-request)
(org-agent:register-neuro-backend :claude #'execute-anthropic-request)
Architectural Intent: Model Discovery
Provides the Model Explorer with a list of supported models and their context limits, allowing the user to inspect capabilities.
(defun get-available-models ()
"Returns the list of LLM models supported by this provider."
'((:id "claude-3-5-sonnet-20240620" :context "200k")
(:id "claude-3-opus-20240229" :context "200k")
(:id "claude-3-haiku-20240307" :context "200k")))
Registration
(defskill :skill-provider-anthropic
:priority 100
:trigger (lambda (context) nil)
:neuro (lambda (context) nil)
:symbolic (lambda (action context) action))