AgentForge: Multi-Tenant Runtime for LLM Agents
AgentForge is a production-grade, scalable runtime engineered for deploying LLM agents (e.g., LangGraph, CrewAI, or custom AutoGPT-style workflows) in a multi-tenant environment. It enforces sandboxing for isolation, capability policies for controlled execution, scheduling for fair resource allocation, resource quotas per tenant, and billing integrations for usage-based metering.
High-Level Architecture
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Tenants/Users │───▶│ API Gateway │───▶│ Scheduler │
│ (AuthN/Z) │ │ (gRPC/HTTP/WS) │ │ (Kubernetes │
└─────────────────┘ └──────────┬───────┘ │ + Custom Queue) │
│ └──────────┬───────┘
▼ │
┌──────────┼───────┐ │
│ LLM Proxy │Billing│ │
│ (Rate │Engine │ │
│ Limits) │(Stripe│ │
└──────────┼──┬────┘ │
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ Sandbox Executor Cluster │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Pod 1 │ │ Pod 2 │ │ Pod N │ ... │
│ │ ┌─gVisor──┐ │ │ ┌─gVisor──┐ │ │ ┌─gVisor──┐ │ │
│ │ │ Agent │ │ │ Agent │ │ │ Agent │ │ │
│ │ │ Sandbox │ │ │ Sandbox │ │ │ Sandbox │ │ │
│ │ │ (Wasm/ │ │ │ (Wasm/ │ │ │ (Wasm/ │ │ │
│ │ │ Container│ │ │ Container│ │ │ Container│ │ │
│ │ └──────────┘ │ └──────────┘ │ └──────────┘ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Monitoring │ │ Resource Quotas │ │ Observability │
│ (Prometheus) │ │ (Kubernetes │ │ (Jaeger/OTEL) │
└─────────────────┘ │ CRDs + Admission│ └──────────────────┘
│ Controller) │
└──────────────────┘
- Deployment: Kubernetes (EKS/GKE/AKS) for orchestration, with Firecracker microVMs or gVisor for lightweight sandboxing.
- Scalability: Horizontal pod autoscaling (HPA) based on queue depth and GPU utilization.
- Tech Stack:
| Component | Tech |
|---|
| Orchestration | Kubernetes + Operators |
| Sandboxing | gVisor + WasmEdge |
| Queue/Scheduling | Celery + Redis/Kafka |
| LLM Proxy | LiteLLM |
| Billing | Stripe + Hasura |
| Monitoring | Prometheus + Grafana |
| API | FastAPI + Pydantic |
1. Sandboxing (Isolation & Security)
Agents run in ephemeral, namespaced sandboxes to prevent cross-tenant interference:
- Runtime: WasmEdge (for JS/Python agents) or Docker-in-Docker with seccomp/AppArmor profiles.
- Kernel Isolation: gVisor (user-space kernel) or Kata Containers (Firecracker VMs) for untrusted code.
- Capabilities:
- Network: Proxy all outbound traffic through LLM Gateway (no direct internet).
- Filesystem: tmpfs + read-only base images (e.g.,
python:slim with LangChain pre-installed).
- Memory/CPU: cgroup v2 limits per pod.
- Enforcement: Kubernetes NetworkPolicies + PodSecurityPolicies (PSP) or OPA/Gatekeeper.
- Agent Lifecycle:
# Example agent execution in sandbox
def execute_agent(tenant_id, agent_spec):
pod_spec = {
"sandbox": {"type": "gvisor", "capabilities": policy.get(tenant_id)},
"image": "agentforge/runtime:latest",
"cmd": ["python", "-m", "agent_runner", agent_spec.json()],
}
kube_client.create_pod(pod_spec)
2. Capability Policies
Policy Engine (OPA/Rego-based) defines per-tenant what agents can do:
- YAML/JSON Policies:
tenants:
acme-corp:
capabilities:
llm_calls: { models: ["gpt-4o", "claude-3"], max_tokens: 10k }
tools: ["web_search", "db_query"] # Whitelist
code_exec: false # No arbitrary code
max_steps: 50 # Agent loop limit
rate_limit: 10 req/min
- Enforcement:
- Admission webhook validates
CreateAgentRun API calls.
- Sandbox runtime (e.g., LangGraph executor) checks policies at each step.
- Violations: Reject/terminate with audit log.
3. Scheduling
Hybrid Scheduler for fair, priority-based execution:
- Queue: Redis + Celery for async jobs; WebSocket for streaming.
- Priorities: FIFO + tenant tiers (e.g., Enterprise > Free).
- Kubernetes Integration:
- Custom Resource Definitions (CRDs):
AgentRun with spec/status.
- Scheduler Plugin: Preempt low-priority pods for high-priority.
- Backpressure: If cluster saturated, queue with ETA; notify via API.
- Example Flow:
- User submits
POST /v1/agents/run.
- Scheduler enqueues to tenant's priority queue.
- Worker pod claims job, spins up sandbox.
4. Resource Quotas
Per-Tenant Limits enforced via Kubernetes + Custom Metrics:
| Resource | Unit | Quota Example |
|---|
| Compute | CPU/Mem/GPU | 10c/50Gi/4 |
| LLM Tokens | Input+Output | 1M/day |
| Storage | PersistentVol | 100Gi/tenant |
| Network | Egress GB | 1TB/month |
5. Billing Integrations
Usage-Based Metering with real-time tracking:
Implementation Roadmap
- MVP (1 sprint): Single-node K8s + gVisor + LiteLLM proxy + basic quotas.
- Beta: Celery scheduling + OPA policies + Stripe.
- Prod: Multi-region, GPU autoscaling, Wasm agents.
Getting Started
# Helm install
helm repo add agentforge https://trailblazer-labs.github.io/charts
helm install agentforge agentforge/agentforge --set tenantId=your-tenant
# API Example
curl -X POST http://agentforge.example.com/v1/agents/run \
-H "Authorization: Bearer $TOKEN" \
-d '{
"agent": {"type": "langgraph", "spec": {...}},
"policy": "default"
}'
This design ensures secure, cost-effective scaling for 1000s of tenants. Source code prototype available on request—let's iterate! 🚀