Repository navigation
feat(llm): Anthropic-native backend; deploy: hardened systemd unit + env template - #16
Merged
Merged
Conversation
…env template ENGRAM_LLM_PROVIDER=anthropic (or auto: an sk-ant- key / anthropic.com base URL) routes every LLM task through the official anthropic SDK — auto_extract, consolidation audit, gc scoring, merge, reflex drafting, skill validation, and the file summarizer (summarize.py now goes through the shared LLM layer under this provider). The OpenAI-compatible and Ollama paths are unchanged; the SDK is an optional extra ([anthropic]). - src/llm_anthropic.py: Messages API via anthropic.Anthropic; default model claude-opus-5-5; per-task overrides as before; ENGRAM_LLM_EFFORT → output_config.effort; server-side refusal fallbacks (beta server-side-fallback-2026-07-01, fallbacks="default") only on models that support them, with a TypeError fallback to plain messages.create on older SDKs; most-specific-first error chain; text-or-None, never raises; refusals logged with their category - src/llm.py: llm_provider(), dispatch in call_ollama_generate / call_chat_completion / is_llm_available (models.retrieve probe), get_llm_status gains provider + sdk_installed - deploy/systemd/engram-serve.service (User=engram, EnvironmentFile /etc/engram/engram.env, ExecStart engram serve, ProtectSystem=strict, ReadWritePaths=/var/lib/engram, loopback only), deploy/engram.env.example (placeholders only; embeddings default fastembed — Anthropic has no embeddings API), deploy/README.md (install, tailscale serve --accept-app-caps, grant snippets, operations) - tests: fake anthropic module injected per test (no network) covering provider selection, default model, request shapes, fallbacks vs plain create, effort, system-turn merging, refusal, every SDK error class, missing SDK, availability probe, summarizer routing; deploy file tests (unit parses, loopback-only, placeholder keys) Verification: ruff clean, pyright 0 errors (llm.py + llm_anthropic.py added to the include list), Cloak 0 errors, full suite 1502 passed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
7 of 18 tasks
4 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two pieces of ADR-0009 Phase 1 (#12): the systemd deployment, and the piece that makes "use my Anthropic key wherever I can" true on the VM.
Anthropic-native LLM backend.
ENGRAM_LLM_PROVIDER=anthropic(or auto-detected from ansk-ant-key or ananthropic.combase URL) routes every LLM task through the officialanthropicSDK: auto_extract / nightly digest, consolidation audit, gc scoring, merge, reflex drafting, skill validation tests, and the file summarizer. The OpenAI-compatible and Ollama paths are untouched; the SDK is an optional extra (pip install 'engram-memory[anthropic]').claude-opus-5-5;ENGRAM_LLM_MODEL,ENGRAM_LLM_EXTRACT_MODEL,ENGRAM_LLM_AUDIT_MODELoverride as before;ENGRAM_LLM_EFFORTsets reasoning depth.fallbacks: "default") on the models that support them, with a transparent fall back to plainmessages.createon older SDKs.None, never raises. Missing SDK, bad key, unknown model, rate limit, connection error, and refusals all degrade to "unavailable" and are logged.engram llm-status/memory_llm_statusreportproviderandsdk_installed.Deployment (
deploy/):systemd/engram-serve.service(runsengram serveasengram, loopback only,EnvironmentFile=/etc/engram/engram.env,ProtectSystem=strict,ReadWritePaths=/var/lib/engram),engram.env.example(placeholders only), anddeploy/README.mdwith the user/dirs/venv steps, thetailscale serve --accept-app-capspublish step, and the grant snippets. Anthropic has no embeddings API, so the template defaults embeddings tofastembedin-process with the Gemini option commented beside it.Verification
tests/test_llm_anthropic.py: a fakeanthropicmodule is injected per test — no network — covering provider selection, default model, request shapes, fallbacks vs plain create, effort, system-turn merging, refusal, every SDK error class, missing SDK, the availability probe, and summarizer routingtests/test_deploy_files.py: unit parses, loopback only, never the MCP server, placeholder keys only/etc/engram/engram.env(engram llm-statusthen onememory_auto_extract)🤖 Generated with Claude Code