# INFERENCE — sovereign LLM execution Hugging Chat / the HF router is fine for prototyping, but the critical path is an endpoint you control that the harness hits programmatically. Two paths, both OpenAI-compatible — no code changes, only env: ```bash export FREESTREAM_AGENT=llm export FREESTREAM_LLM_BASE_URL=/v1 export FREESTREAM_LLM_API_KEY= export FREESTREAM_LLM_MODEL=local # llama.cpp/MLX serve any model name export FREESTREAM_CHARACTER_CARD=identity/characters/vera-steel.json ``` ## A. Dedicated HF Space (shipped — [freestream-llm](https://huggingface.co/spaces/LoveLogicAI/freestream-llm)) Docker Space running **llama.cpp server** (Qwen2.5-7B-Instruct Q4_K_M, auto-downloaded on boot). Endpoint: ``` https://lovelogicai-freestream-llm.hf.space/v1/chat/completions ``` Setup once: Space settings → upgrade hardware to **CPU Upgrade** (8 vCPU) → add the `LLM_API_KEY` secret → optionally enable persistent storage (`/data`) so the 4.7GB model survives restarts. **Pause the Space when idle** — a 24/7 CPU-upgrade Space bills continuously, and sovereignty shouldn't mean a standing bill. Measured throughput will be reported in docs/LATENCY.md after the probe job. ## B. Mac mini (recommended primary — your hardware, no standing bill) ```bash cd freestream ./scripts/serve_local_llm.sh mlx # MLX, fastest on Apple Silicon # or: ./scripts/serve_local_llm.sh cpp export FREESTREAM_LLM_BASE_URL=http://localhost:8080/v1 export FREESTREAM_LLM_MODEL=local export FREESTREAM_LLM_API_KEY=local python tests/e2e_roleplay.py # the harness hits localhost programmatically ``` - **MLX**: `pip install mlx-lm`, serves `mlx-community/Qwen2.5-7B-Instruct-4bit` via `python -m mlx_lm.server` (OpenAI-compatible). - **llama.cpp**: `brew install llama.cpp`, `llama-server -hf ` — same API. The 4s assistant-profile win condition stays a **cloud-burst** feature (router/GPU); sovereign local inference is the **roleplay/agentic profile** (gates 20s/30s) — measure your mini's tok/s and record it in LATENCY.md. ## Harness wiring (both paths) Every e2e harness reads the same env; nothing is hardcoded to the router. `load_agent` accepts keyless **local** endpoints (localhost / *.local) without falling back to the rule stub — set `FREESTREAM_LLM_API_KEY=local` for hosts that ignore auth headers. ## Endpoint contract CharacterAgent needs exactly one route: `POST {base}/chat/completions` with `{"model", "messages", "max_tokens", "temperature"}` → `choices[0].message.content`. Any OpenAI-compatible server satisfies it (llama-server, mlx_lm.server, vLLM, Ollama with `base=/v1`).