How to Build a Self-Hosted AI Agent Stack (2026 Guide)
The short answer
Build it in six layers — model server, gateway, vector store, agent runtime, chat front end and tracing — and start from n8n’s Self-hosted AI Starter Kit, which brings up n8n, Ollama, Qdrant and PostgreSQL with one Docker Compose command. Then add a gateway, tracing and backups before any agent runs unattended. Versions below were read from each project’s GitHub releases on November 24, 2026.
The stack at a glance
| Layer | Default pick | Latest release (Nov 24, 2026) | Licence | Swap in |
|---|---|---|---|---|
| Model server | Ollama | v0.40.17 (Nov 10) | MIT | vLLM v0.34.0 (Nov 16), Apache-2.0, for GPU servers |
| Gateway | LiteLLM | v1.110.3 (Nov 24) | Open core | Any OpenAI-compatible proxy |
| Vector store | Qdrant | v1.20.2 (Nov 16) | Apache-2.0 | pgvector in your Postgres |
| Agent runtime | n8n (workflows) or OpenClaw (always-on agent) | n8n stable (Nov 23) · OpenClaw v2026.11.7 (Nov 23) | Fair-code · MIT | LangGraph, CrewAI, Mastra in code |
| Chat front end | Open WebUI | v0.13.4 (Nov 17) | Open WebUI License | AnythingLLM v1.20.0 (Nov 17), MIT |
| Tracing and evals | Langfuse | v4.84.0 (Nov 23) | Open core | OpenTelemetry to your own backend |
Step 1 — Pick the model and the server
Choose an open-weight model that fits your memory with room for context — see how to choose an open-weight LLM to self-host. On one workstation or Mac, run it with Ollama. On shared GPUs serving several agents, use vLLM, which batches concurrent requests and reuses cached prompt prefixes; agents resend the same system prompt and tool list on every step, so this matters more than raw tokens per second.
Done when: curl to the server’s OpenAI-compatible /v1/chat/completions returns a response with a tool call.
Step 2 — Start the base stack
git clone https://github.com/n8n-io/self-hosted-ai-starter-kit.git
cd self-hosted-ai-starter-kit
cp .env.example .env # change every secret and password
docker compose --profile gpu-nvidia up # pick the profile for your hardware
This starts self-hosted n8n, Ollama, Qdrant and PostgreSQL on one Docker network.
Done when: the n8n editor opens and an AI Agent node can call the local model.
Step 3 — Put a gateway in front of every model
Point agents at LiteLLM, not at Ollama directly. One OpenAI-compatible endpoint lets you swap models, add a hosted fallback for hard tasks, issue a key per agent, and set per-key budgets and rate limits. See best LLM gateways.
Done when: each agent has its own key and its calls appear in the gateway’s logs.
Step 4 — Add memory and documents
Store embeddings in Qdrant (or pgvector if you already run Postgres). Use a local embedding model through the same gateway so documents never leave the network.
Done when: an agent answers a question that is only in your documents and cites the source chunk.
Step 5 — Choose the agent runtime
- n8n for visual, trigger-based workflows across its 400+ integrations: “when a ticket arrives, classify, look up, draft a reply”.
- OpenClaw for an always-on personal or team agent that lives in chat channels, keeps memory and runs scheduled jobs.
- Code frameworks (LangGraph, CrewAI, Mastra) when agents are part of your product — see how to choose an AI agent framework.
Add Open WebUI or AnythingLLM if people also need a ChatGPT-style interface on the same models.
Step 6 — Trace, limit and back up before running unattended
- Tracing: send every model call and tool call to Langfuse so you can see why an agent did something.
- Least privilege: give agents read-only credentials first; require approval for writes, payments and deletes.
- Sandbox code execution — see best AI agent sandboxes.
- Back up Postgres, Qdrant and n8n volumes on a schedule, and test a restore.
- Keep the stack off the public internet; reach it through a VPN or tunnel with SSO.
Done when: you can replay any agent run from its trace and restore the previous day’s state from backup.
When not to self-host
If you have no GPU budget and no data-residency requirement, a hosted API plus a hosted agent platform is cheaper to run. Self-hosting pays off when data cannot leave your network, when request volume makes per-token pricing expensive, or when you need to pin a model version indefinitely. For production model serving in depth, see how to self-host an LLM for production.
Last verified: November 24, 2026.