Self-hosted agentic AI is two decisions, not one
Self-hosting the model and self-hosting the agent loop are different problems with different payoffs. Which to do first, which I'd skip, and what breaks.
140 GB of weights, 80 GB of VRAM
A 70-billion-parameter model at bf16 is roughly 140 GB of weights — two bytes per parameter, before a single token of KV cache. An H100 SXM card holds 80 GB of HBM3 (NVIDIA). So the first honest sentence about self-hosted agentic AI is that the most-downloaded open weight class does not fit on the most-available data centre GPU, and you are already choosing between sharding, quantizing, or a smaller model. Sharding is not free: tensor parallelism across two cards (--tensor-parallel-size 2 in vLLM) makes every forward pass pay an all-reduce over NVLink, and it doubles the thing you have to keep healthy on-call.
Self-hosted agentic AI means running both the model inference and the agent's control loop on infrastructure you own. Two separate decisions. Only one of them is about GPUs.
The inference plane is weights, a serving runtime, and VRAM. The control plane is everything that decides what happens next: the loop, the step counter, the retry policy, the tool allowlist, the state store, the audit trail. "Self-hosted agentic AI" is usually sold as the first one. The second is what decides whether the thing is safe to leave running overnight.
You can mix them, and most working systems do. A self-hosted orchestrator calling a hosted model API is a legitimate architecture. The reverse — a local Ollama install driving a loop that runs in someone else's cloud — is self-hosted in the least useful sense: your weights are private, and your prompts, tool definitions, intermediate state and customer records are not.
People self-host for three reasons, and only the first is binary. Data residency or contractual isolation either holds or it doesn't: the payload leaves your network or it stays. Unit cost at saturation is an arithmetic question, not a principle — a rented GPU bills for all 168 hours in a week whether the agent is thinking or idle, a token API bills per token, and utilization decides the winner. A card busy 20% of the day is paying roughly five times the effective per-token rate of the same card run flat out. Freedom from vendor dependency is the weakest of the three, because you still depend on the weights publisher, the serving runtime, and the licence; you have swapped one set of counterparties for another.
Be clear which one you're buying. They lead to different stacks.
What a serving layer has to do that a laptop demo doesn't
Agent loops are the worst-shaped workload for a naive local server. Long inputs, short outputs, many sequential turns, bursty concurrency, and total intolerance for a malformed tool call.
| Ollama / llama.cpp | vLLM / SGLang | |
|---|---|---|
| Built for | single-user local inference | throughput under concurrency |
| Batching | basic | continuous batching, PagedAttention KV management (vLLM), reported at 2–4× the throughput of prior serving systems at matched latency (SOSP '23 paper) |
| API | OpenAI-compatible endpoint (docs), tool calling (docs) | OpenAI-compatible server (docs) |
| Where it belongs | development, single-operator side projects, air-gapped laptops | anything with more than one agent running at once |
Two numbers decide the hardware. Context length and concurrency, multiplied.
Llama-3.3-70B-Instruct advertises a 128k context window (model card). Qwen3-32B is 32,768 tokens natively and 131,072 with YaRN (model card). Those are ceilings on paper. Serving a long context to twenty concurrent agents is a KV-cache memory problem, and the KV cache is what actually eats the card.
The arithmetic is fixed by the architecture, so you can do it before you buy anything. Llama-3.3-70B has 80 layers and 8 key/value heads of 128 dimensions, so at fp16 one token of cache costs 2 × 8 × 128 × 2 bytes × 80 layers ≈ 320 KB. A single sequence at the full 128k window is about 41 GB of cache. Twenty agents each holding 16k tokens is about 105 GB — more than the card, before the weights are loaded at all. Quantizing a 70B to 4-bit takes the weights to roughly 35 GB, which fits one 80 GB card with room left; that remaining ~45 GB is the real capacity limit, and at 16k tokens per agent it buys you about eight concurrent runs.
The quietest failure in this layer is context truncation. In Ollama, the usable window is set by num_ctx in the Modelfile, and the documented default is small relative to what an agent trace needs (Modelfile reference). A twenty-five step ReAct trace carrying tool output is tens of thousands of tokens — twenty-five steps at 1,500 tokens of tool output each is 37,500 tokens before you count the system prompt or the task. When the front of that conversation falls off the window, the model doesn't error. It appears to forget the goal. Teams then spend a week rewriting the system prompt to fix a config value.
Quantization deserves one more line, because agents are more sensitive to it than chatbots are. A chat response degraded by 4-bit rounding is a slightly worse sentence. A tool call degraded by 4-bit rounding is invalid JSON, a failed step, a retry, and — if the loop has no cap — a spiral. The compounding is the problem: a 1% per-call rate of malformed arguments across a twenty-five step run is a 22% chance of at least one broken step per run. Test tool-call validity rates on the quantization you plan to ship, not just answer quality.
Licences are part of the architecture
This is where self-hosting bites people who intend to resell. The weights and the orchestrator each carry terms, and "open" covers at least four different things.
| Component | Licence | The clause that matters |
|---|---|---|
| Llama 3.3 70B | Llama 3.3 Community License (model card) | Separate licence required above 700M monthly active users; naming and attribution requirements |
| Qwen3-32B | Apache 2.0 (model card) | None for most commercial use |
| vLLM | Apache 2.0 (repo) | None |
| n8n | Sustainable Use License (LICENSE.md) | Internal business use permitted; hosting it as a service for third parties is not |
| Dify | Apache 2.0 plus conditions (LICENSE) | No multi-tenant service without authorization; no removing logo or copyright |
| Langfuse | MIT core, enterprise-licensed features (self-hosting) | Some features in the repo are not MIT |
If the agent is an internal worker, most of this is noise. If you are charging other companies for access to it, the licence of your orchestration tool determines whether you have a product or a violation. That is the same problem as metering and margin, from the legal side — I wrote about the commercial half in selling AI agents as SaaS.
Where the limits live
The most common production failure in agent systems is not a bad answer. It is an unbounded loop: the model keeps choosing "call the tool again," the tool keeps returning something ambiguous, and nothing in the system is counting. Self-hosting does not fix this. It changes who gets the bill — from a token invoice to a saturated GPU and a queue of stalled jobs.
The fix is structural. Caps are enforced outside the model, by the orchestrator, as code. Not in the system prompt. A prompt instruction to "stop after five attempts" is a suggestion to a stochastic process; a counter in the loop is a guarantee.
What belongs in the control plane, self-hosted, every time:
- A hard step cap per run, checked in the loop before the next model call — not described in the prompt.
- A token or wall-clock budget per run, with the run killed on breach and the partial state persisted.
- An idempotency key on every side-effecting tool, because retry is the default behaviour and double-sending is the default bug. Payment APIs settled this pattern years ago: Stripe accepts an
Idempotency-Keyheader on POST requests and replays the saved result for 24 hours (docs). - A full trace of every step written somewhere queryable before you need it.
A plain Python while loop with try/except is where most self-hosted agents start, and it is fine for a cron job that reads and writes nothing important. It is not fine the first time a host reboots while the agent is halfway through a six-step sequence that already charged a card. Durable execution exists because that failure is boring, certain, and expensive.
Who holds the loop is also the definition of the word "agent" — I argued that case in autonomous agents, defined by who chooses the next step.
The tool plane is the attack surface, not the model
Prompt injection sits at LLM01 in the OWASP Top 10 for LLM Applications, and has held that top slot across both the 2023/2024 and 2025 editions of the list (OWASP GenAI). Self-hosting the weights does nothing about it. Injection arrives in tool output — a web page, a support ticket, a PDF, a row in a CRM — and the model has no mechanism to distinguish instructions-from-you from instructions-embedded-in-data.
Which means the controls are in the tool layer:
- Isolation for anything that executes code. gVisor intercepts syscalls in a user-space kernel written in Go rather than handing them to the host kernel; Firecracker microVMs give stronger separation between tenants or runs and still boot in roughly 125 ms with under 5 MiB of memory overhead each. A shared container with the host Docker socket mounted is not a sandbox.
- Egress allowlists. An agent that can reach any host can exfiltrate anything it has read — one HTTP GET with the data in the query string is enough. The allowlist is cheap and it is the single highest-value control in the stack.
- Scoped credentials per agent, per run. Not the admin key. The confused-deputy problem is the whole risk: the agent has legitimate authority, and the injected instruction borrows it.
- MCP servers treated as untrusted dependencies. The Model Context Protocol spec defines stdio and Streamable HTTP transports and the authorization expectations for remote servers (spec, 2025-06-18). A tool server you pulled from a registry runs with whatever rights you hand it. Pin versions. Read the code.
Self-hosting genuinely helps with one slice of this: an air-gapped deployment removes exfiltration-over-the-internet as a path. It does not remove data destruction, wrong-recipient sends, or an agent that quietly corrupts a production table for three weeks.
What I would not do
I would not self-host inference first, to save money. Not unless the GPU is near saturation. An idle rented card bills the same as a busy one, and early agent workloads are spiky by nature. Self-hosting inference wins on residency, on latency floor, and on cost-per-token once you are running the hardware hot. If you are building the first agent, use a hosted API for the model and spend the engineering on the loop. The loop is the part you will still own in two years.
I would not use Ollama as the production serving layer. It is excellent at what it is for — one operator, one machine, fast iteration, an OpenAI-compatible endpoint you can point a framework at in a minute. It is not a concurrency story. Continuous batching and paged KV management are why vLLM exists.
I would not make a workflow builder the system of record. n8n and Dify are quick to stand up and genuinely useful as an interface. But when your agent's state, retry history and audit trail live inside a visual tool's internal tables, you cannot easily replay a run, diff two versions of a prompt, or hand an auditor a straight answer. Keep state in Postgres — with pgvector if you need retrieval in the same database — and let the builder be a front end.
I would not grant an agent spend authority on a self-hosted stack because it feels safer. It isn't safer. It is less observed. Hosted vendors at least show you a usage graph.
Observability is the part you cannot bolt on later
A self-hosted agent that does not write a trace is a black box you pay the electricity for. You need, per run: the full message sequence, every tool call with arguments and result, token counts per step, latency per step, and the terminal reason — completed, capped, errored, killed.
Langfuse self-hosts for this and keeps the traces inside your network, which matters if the whole point of self-hosting was that the payloads stay put. Read the licence detail first: the core is MIT and some features carry an enterprise licence. If you would rather not run another product, emit spans against the OpenTelemetry GenAI semantic conventions and send them wherever your existing traces already go. The conventions give you standard attribute names — gen_ai.request.model, token-usage counts, and the rest — which means your model spans sit next to your HTTP spans in the same waterfall rather than in a separate tool nobody opens. They are still published as experimental, so pin the semconv version you emit and expect attribute renames between releases.
The trace does three jobs, and the third is the one people discover late. It answers "why did it do that," which is incident response. It becomes the eval set, because the only honest test cases are real runs that went wrong. And it is the billing record: the rows that prove the agent did the work are the same rows an outcome- or action-priced invoice is computed from, which is the case made in build a billable AI agent and the ledger that bills for it.
Decide your retention before you start. Agent traces contain whatever the agent read, which on a self-hosted stack is frequently the exact data you self-hosted to protect — and under GDPR's storage limitation principle (Article 5(1)(e)) personal data cannot be kept in identifiable form for longer than the purpose requires. A trace store with no deletion policy is a second copy of your customer database, indexed for search, built by accident.
Sources
- NVIDIA H100 Tensor Core GPU — 80 GB HBM capacity per H100 SXM card
- vLLM (project repository) — PagedAttention, continuous batching, OpenAI-compatible server, Apache 2.0 licence
- vLLM documentation — Serving and deployment reference for the inference plane
- Ollama — OpenAI compatibility — Ollama exposes an OpenAI-compatible endpoint, which is why agent frameworks point at it
- Ollama — tool support — Tool/function calling via the Ollama API
- llama.cpp — CPU/GPU local inference, GGUF quantization formats
- SGLang — Alternative high-throughput serving runtime
- Llama-3.3-70B-Instruct model card — 128k context length; Llama 3.3 Community License including the 700M monthly-active-user clause
- Qwen3-32B model card — Apache 2.0 licence; 32,768 native context, 131,072 with YaRN
- n8n licence (Sustainable Use License) — Internal business use permitted; hosting it as a service for third parties restricted
- Dify licence — Apache 2.0 plus additional conditions on multi-tenant service and branding removal
- Temporal documentation — Durable execution: workflow state survives process and host failure
- LangGraph — Graph orchestration with checkpointed state, self-hostable
- OWASP Top 10 for LLM Applications — Prompt injection ranked LLM01; excessive agency and supply chain risks
- Model Context Protocol specification (2025-06-18) — stdio and Streamable HTTP transports; authorization requirements for tool servers
- gVisor documentation — User-space kernel sandbox for untrusted code execution
- Firecracker microVM — MicroVM isolation for multi-tenant workloads
- Langfuse self-hosting guide — Self-hosted LLM tracing; core MIT with enterprise-licensed features
- OpenTelemetry GenAI semantic conventions — Standard span and attribute names for model and agent telemetry
- pgvector — Vector search inside Postgres, avoiding a separate hosted index