Self-hosting an agent framework is the easy half
Which self-hosted agent frameworks are actually permissively licensed, what durable execution buys you, and why I would not self-host inference first.
The license question, answered first
LangGraph is MIT. CrewAI is MIT. AutoGen is MIT. Letta is Apache 2.0. All four install with pip, run in a process you own, and keep state in a Postgres you own.
A self-hosted AI agent framework is an orchestration layer you run on your own infrastructure — LangGraph, CrewAI, AutoGen, Letta and Dify are the practical options — and choosing one is the easy half, because the framework does not keep your data inside your network unless you also self-host inference, state and tool execution.
Teams get stuck on the second half of that sentence, never the first. They do not need a library recommendation. They need to know which parts of the stack still phone home after the orchestrator is running in a container they built.
Three layers, and only one of them leaks
"Self-hosted" gets used to mean four different things. Separate them before you compare tools.
Run LangGraph on your own Kubernetes and call Claude or GPT over HTTPS, and every prompt, every retrieved document, every tool result that gets fed back into context has left your perimeter. Zero-retention terms and regional endpoints mitigate that, but they are contract terms, not network controls. A self-hosted orchestrator buys operational control. It buys nothing on data residency. If the reason you are self-hosting is a contract clause or a regulator — GDPR Chapter V transfer rules, a HIPAA business associate agreement, a public-sector tender that names a country — only the accent-coloured box in that diagram resolves it.
Most teams who think they want layer four want layers one through three: control over retries, control over state, no per-seat platform bill, the ability to pin a version. All of that comes from a pip install.
The field, with the license fine print
| Project | License | What it is | How you host it |
|---|---|---|---|
| LangGraph | MIT | Graph / state-machine orchestration from the LangChain team, with checkpointed state and durable execution | Library in your own process; LangGraph Platform is a separate commercial product |
| CrewAI | MIT | Role-based crews with task delegation; sequential or hierarchical process modes | Library |
| AutoGen | MIT | Multi-agent conversation runtime from Microsoft; the v0.4 rewrite in January 2025 moved it onto an event-driven actor model | Library, plus an optional Studio UI |
| Letta | Apache 2.0 | Agent server — agents persist and are addressed over REST; grew out of the 2023 MemGPT paper | Docker container you run, REST API on port 8283 |
| Dify | Dify Open Source License (Apache 2.0 plus conditions) | App platform with a visual workflow builder | Docker Compose or Helm |
| n8n | Sustainable Use License (source-available, not OSI-approved) | General workflow automation with AI nodes | Docker |
| smolagents | Apache 2.0 | Minimal loop from Hugging Face where the agent writes Python as its action | Library |
| Pydantic AI | MIT | Typed agent framework from the Pydantic team; outputs validated against Pydantic models | Library |
| OpenAI Agents SDK | MIT | Handoffs and guardrails loop, released March 2025 as the supported successor to the experimental Swarm; works against any OpenAI-compatible endpoint | Library |
Two rows in that table are not open source in the sense people assume. Dify ships under its own licence built on Apache 2.0, with added conditions covering multi-tenant resale and removal of branding. n8n ships under the Sustainable Use License: internal business use and non-commercial use are permitted, selling n8n itself as a service is not.
If your agent is a feature inside the product you sell, read both licences before the architecture review, not after. "It's on GitHub" and "we can embed it in our commercial product" are different claims, and only the second one is decided by the licence text.
Letta is the structural outlier. It is not a library you import into a request handler — it is a server where an agent is a long-lived, addressable object with persistent memory, which is a different mental model from LangGraph's "graph invocation with a checkpoint". For why those are genuinely different things, see what an AI agent actually is, and the two meanings.
Durable execution is the only feature that separates them in production
On day one, every framework in that table does the same thing: a loop that calls a model, parses a tool call, runs the tool, appends the result, calls the model again. You can write that in one Python file, and you should, once, before you adopt anything — build your first AI agent in one Python file.
On day ninety, the difference is what happens when the process dies at step 7 of 14.
LangGraph's answer is checkpointers: state is persisted after each node, and a run resumes from the last committed checkpoint rather than from the top. The library ships MemorySaver, SqliteSaver and PostgresSaver, and only the last two survive a pod restart. Temporal's answer is deterministic workflow replay — the engine re-executes your workflow code against a recorded event history so that a crashed worker resumes mid-function. Temporal is MIT-licensed. That makes "LangGraph nodes inside a Temporal workflow" a real pattern rather than a vendor pitch.
Unbounded loops are the most common production failure mode for agents, and the fix is not a prompt. It is a step cap and a token budget enforced outside the model, in the orchestrator, where the model cannot talk its way past them. LangGraph ships one by default: a recursion_limit of 25 super-steps per invocation, which raises a GraphRecursionError instead of a surprise invoice. A framework where the loop lives inside a provider's hosted runtime gives you an email about your bill.
MemorySaver is the default in several quickstarts, which means your "durable" agent loses everything on pod restart. Point it at Postgres before you ship.Why I would not self-host inference as the first move
The arithmetic settles it. Take a support-triage agent: twelve model calls per run, 8,000 input tokens and 600 output tokens per call, 20,000 runs a month. That is 96,000 input tokens per run, 1.92 billion input tokens and 144 million output tokens a month. Big numbers. Put your own model prices against them:
Arithmetic on published list prices. Retries are billed too, so a step that fails twice before working costs three times this.
Now price the alternative. A p4d.24xlarge — eight A100 80GB GPUs — lists at $32.77 an hour on-demand in us-east-1, roughly $23,000 a month if you leave it up, and you need at least two for failover, so call it $46,000 before anyone has written a line of inference code. GPU reservations, spot interruptions and a model-serving on-call rotation are now your problem. vLLM is excellent and Apache 2.0 — it came out of UC Berkeley's PagedAttention work and will serve an OpenAI-compatible endpoint that most of these frameworks accept with a base-URL change. That is not the hard part. Capacity planning is.
Self-host inference when the reason is a data clause, an airgap, a latency floor you cannot hit over the public internet, or a model you have fine-tuned and intend to keep. Those are good reasons. "It will be cheaper" is not one, and the trap is specific: per-token cost drops to zero while cost-per-run quietly moves into fixed infrastructure you pay for whether the agent runs or not. At 20,000 runs a month that $46,000 is $2.30 a run; at 2,000 runs it is $23. Cost per loop is the number worth tracking, not the sticker price of a token.
Ollama is the right answer for development. MIT, one binary, pulls open-weight models like the MIT-licensed DeepSeek-R1. Develop against it; run production against whatever the data constraint permits.
Tool execution is where self-hosting creates new risk
Self-hosting moves the agent's tool calls onto your network, behind your firewall, with your service credentials. That is the point. It is also the exposure.
Prompt injection sits at LLM01 in the OWASP Top 10 for LLM Applications — first in the 2023 list and still first in the 2025 revision — and a self-hosted agent with a shell tool and an internal API token is the highest-value version of that attack, because the attacker's payload arrives inside content the agent was asked to read: a support ticket, a scraped page, a PDF.
Two isolation options get used in production rather than blogged about. gVisor, open-sourced by Google in 2018 under Apache 2.0, is a user-space kernel written in Go that intercepts syscalls, so a container escape has to get through a second kernel implementation first; overhead sits above plain containers and below a VM. Firecracker, open-sourced by AWS the same year under Apache 2.0, runs microVMs with hardware-level isolation, boots in around 125 ms and adds under 5 MiB of memory overhead per microVM — it is the technology under AWS Lambda, a stronger boundary and more machinery to run. A shell tool that reads untrusted content gets the microVM and the extra machinery. A sandboxed Python interpreter can live with gVisor.
For tool exposure itself, the Model Context Protocol — published by Anthropic in November 2024 and since adopted across the major SDKs — has become the common interface, and its transport choice matters here. An MCP server running over stdio on the same host never opens a network socket, so a self-hosted agent can reach internal tools without those tools becoming reachable from anywhere else; the streamable HTTP transport introduced in the 2025-03-26 spec revision does, and needs auth in front of it. The framework-specific tool decorators in CrewAI or Pydantic AI are fine. They are also a rewrite when you change framework, which MCP servers are not.
Observability: keep the traces, or you are debugging blind
An agent failure is rarely one bad response. It is step 9 doing something defensible given what step 6 put in the context window. Without a trace of every call, you are reading a transcript and guessing.
Langfuse self-hosts via Docker, with an MIT-licensed core and enterprise features confined to a separately licensed ee/ directory of the repository — check which bucket the feature you need falls into before you depend on it. The vendor-neutral path is OpenTelemetry's GenAI semantic conventions, which define standard span and attribute names under the gen_ai.* namespace — gen_ai.request.model, gen_ai.usage.input_tokens — so your traces land in the collector you already run instead of a second observability silo. They are still marked experimental, so pin the convention version you instrument against.
Instrument three things: tokens per step, wall-clock per tool call, and the full tool input and output. The third is the expensive one to store. It is also the only one that ever explains anything.
What I would not use
I would not make a visual workflow builder the system of record for an agent that touches money or customer data.
Dify and n8n are good software. For internal automation and for proving out a flow in an afternoon, a builder beats a repository. But the graph lives as JSON in a database, so code review becomes diffing an exported blob, rollback becomes a manual import, and the moment two people edit the same workflow you have no merge story. Then there is the licence: if the agent becomes part of what you sell, the Sustainable Use License is a conversation with a vendor, not a pip install.
The second thing I would not do is let the model own control flow it does not need to own. A lot of multi-agent framing — a planner agent that spawns worker agents that spawn their own sub-tasks — is a loop with no ceiling and a non-deterministic branching factor, which is precisely the shape that generates a bill nobody approved. Anthropic's own write-up of its multi-agent research system, published in June 2025, put token usage for that architecture at roughly 15× a plain chat interaction. If the sequence is known, write the sequence. Use the model for the step where judgement is required and a for loop for the four steps where it is not. Fewer model calls, cheaper, and the failure is reproducible.
And I would not give an agent spend authority yet. Not because agents cannot execute a purchase — they can, and that shift is already underway — but because the controls that make it safe are budget ceilings, step caps and approval gates enforced in the orchestrator, outside the model, by code the model cannot reason with. Self-hosting is what puts that code under your control. It is the reason to do it, and it is also the whole job: the framework is a dependency, the guardrails are yours.
Sources
- LangGraph repository — MIT license; graph orchestration with checkpointed state and durable execution
- LangChain pricing — LangGraph Platform is a separate commercial product from the MIT library
- CrewAI repository — MIT license; role-based multi-agent orchestration
- Microsoft AutoGen repository — MIT license; multi-agent conversation runtime
- Letta repository — Apache 2.0; agent server with persistent memory exposed over REST
- Dify repository — Dify Open Source License — Apache 2.0 with multi-tenant and branding conditions
- n8n repository — Sustainable Use License — source-available, not OSI-approved; internal business use limits
- smolagents repository — Apache 2.0; code-writing agent loop
- Pydantic AI repository — MIT license; typed agent framework
- OpenAI Agents SDK (Python) — MIT license; works against any OpenAI-compatible endpoint
- Temporal repository — MIT license; durable execution engine that survives process crashes
- vLLM repository — Apache 2.0; OpenAI-compatible inference server for open weights
- Ollama repository — MIT license; local model runner
- DeepSeek-R1 model card — MIT-licensed open weights
- Model Context Protocol — Open protocol for exposing tools and resources to agents, including local stdio servers
- Langfuse repository — Self-hostable LLM tracing; MIT core with separately licensed enterprise directory
- OpenTelemetry GenAI semantic conventions — Standard span and attribute names for model and agent calls
- gVisor — User-space kernel that intercepts syscalls for container isolation
- Firecracker — MicroVM used for fast, isolated execution environments
- OWASP Top 10 for LLM Applications — Prompt injection ranked LLM01
- Amazon EC2 On-Demand Pricing — List hourly price for GPU instance types