Skip to content

feat(llm): Anthropic-native backend; deploy: hardened systemd unit + env template - #16

Merged
luiscota99 merged 1 commit into
mainfrom
feat/anthropic-llm-and-systemd
Oct 15, 2026
Merged

luiscota99 merged 1 commit into
mainfrom
feat/anthropic-llm-and-systemd

Conversation

@luiscota99

Copy link
Copy Markdown
Owner

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 an sk-ant- key or an anthropic.com base URL) routes every LLM task through the official anthropic SDK: 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]').

  • Default model claude-opus-5-5; ENGRAM_LLM_MODEL, ENGRAM_LLM_EXTRACT_MODEL, ENGRAM_LLM_AUDIT_MODEL override as before; ENGRAM_LLM_EFFORT sets reasoning depth.
  • Server-side refusal fallbacks (fallbacks: "default") on the models that support them, with a transparent fall back to plain messages.create on older SDKs.
  • Same contract as the rest of the LLM layer: text or 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_status report provider and sdk_installed.

Deployment (deploy/): systemd/engram-serve.service (runs engram serve as engram, loopback only, EnvironmentFile=/etc/engram/engram.env, ProtectSystem=strict, ReadWritePaths=/var/lib/engram), engram.env.example (placeholders only), and deploy/README.md with the user/dirs/venv steps, the tailscale serve --accept-app-caps publish step, and the grant snippets. Anthropic has no embeddings API, so the template defaults embeddings to fastembed in-process with the Gemini option commented beside it.

Verification

  • tests/test_llm_anthropic.py: a fake anthropic module 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 routing
  • tests/test_deploy_files.py: unit parses, loopback only, never the MCP server, placeholder keys only
  • Full suite: 1502 passed; ruff clean; pyright 0 errors; Cloak 0 errors
  • Live call against the real API from the VM once the key is in /etc/engram/engram.env (engram llm-status then one memory_auto_extract)

🤖 Generated with Claude Code

…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>
@luiscota99
luiscota99 merged commit cfa7f6f into main Oct 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant