How to design, ship, and operate an AI agent that is
reliable, efficient, performant, scalable, and secureenough to serve real companies β from a 5-person startup to a 50,000-person enterprise.This guide distills hard-won lessons from production agents (Claude Code, OpenHands, SWE-agent, GoClaw, Hermes, nanobot, PicoClaw, ZeroClaw, Multica, Paperclip) and grounds them in current engineering guidance from Anthropic and OpenAI plus the security and compliance standards you'll actually be audited against (OWASP Top 10 for Agentic Applications, NIST AI RMF, the EU AI Act, and 2025β2026 prompt-injection research). It focuses on the parts most articles skip: the
enterprise taxβ governance, security, compliance, integration, cost control, and the operating model β that separates a demo from a system a CISO will sign off on.
The single most important idea in agent engineering:
Reliability β Model capability Γ Harness quality
(mostly fixed) (your job)
The model is roughly fixed for the life of your project. The harness β system prompts, tools, sandboxes, memory, orchestration, guardrails, and observability β is where ~80% of production quality comes from. After hundreds of production sessions the pattern is consistent:
It's almost never a model problem. It's a configuration and harness problem.
For enterprise, add a second equation that most teams discover too late:
Enterprise-readiness β Harness quality Γ Trust surface
(security + governance + observability)
A brilliant agent that can't prove what it did, can't be scoped to a tenant, and can't be audited will not ship in a regulated company. Budget for the trust surface from day one β it is not a phase 2 feature.
Anthropic's guidance (Building Effective Agents, 2024) draws the line that matters:
Workflow | Agent | | |---|---|---| | Control flow | Predefined code paths | LLM directs its own steps | | Best for | Well-defined, decomposable tasks | Open-ended tasks, unknown # of steps | | Cost/latency | Low, predictable | Higher, variable | | Failure mode | Predictable | Compounding errors |
Rule: start with the simplest thing that works β a single well-prompted LLM call with retrieval often beats an agent. Add agentic autonomy only when the number of steps is genuinely unpredictable (e.g. coding, research, multi-system triage). Autonomy trades latency and cost for capability; make that trade deliberately.
The common production patterns, in rising order of complexity: augmented LLM β prompt chaining β routing β parallelization β orchestrator-workers β evaluator-optimizer β autonomous agent. Reach for the lowest rung that solves the problem.
For fixed business processes, make the control flow deterministic. Expense approvals, employee onboarding, KYC, and refund flows have known steps β encode them as an explicit state machine / durable workflow (e.g. LangGraph for the graph, Temporal for durable execution) and let the LLM be flexible only inside a bounded sub-task ("draft the summary," "classify this ticket"). This is the single most effective cure for the runaway-reasoning-loop failure in corporate settings: the agent literally cannot wander outside the defined transitions. Reserve open-ended autonomy for the genuinely unpredictable work. (Budgets, stuck detection, and circuit breakers in Part 4 and Part 7 back this up β a state machine bounds what can happen, budgets bound how long.)
| Path | When it's right | Watch out for |
|---|---|---|
| Buy a SaaS agent | ||
| Commodity use case (support deflection, meeting notes) | Data residency, lock-in, no access to the harness | |
| Assemble on a platform/SDK | ||
| You want control of the harness but not the kernel | Framework abstraction hiding prompts/tokens β insist you can see them | |
| Build the harness on raw LLM APIs | ||
| Differentiated workflow, strict data/compliance needs | Cost of the "last mile" to production is large |
Anthropic's advice holds: frameworks help you start but "reduce abstraction layers and build with basic components as you move to production." If a framework hides the prompts and token flow, you can't debug or cost-control it β a dealbreaker at scale.
A use case is a good agent fit when you can answer yes to most of these:
β Part 1 checklist
- [ ] Chose the lowestrung (workflow before agent) that solves the problem- [ ] Wrote down the success metric and how it's measured automatically
- [ ] Ran a build/buy/assemble decision with data-residency constraints included
- [ ] Estimated cost-per-task and confirmed the task value exceeds it
A consumer demo becomes an enterprise product when it satisfies requirements that have nothing to do with the model. Plan for these before the pilot, because retrofitting them is expensive.
| Requirement | What it means concretely |
|---|---|
| Identity & access | |
| SSO (SAML/OIDC), SCIM provisioning, role-based access to tools and data | |
| Multi-tenancy | |
| Hard isolation of data, secrets, workspaces, and cost per company/team | |
| Data governance | |
| Data residency/region pinning, retention limits, PII handling, "no-train" guarantees | |
| Auditability | |
| Every action attributable to a user + reproducible; immutable audit log | |
| Compliance | |
| SOC 2 Type II, ISO 27001, GDPR/CCPA, and sector rules (HIPAA, PCI-DSS, FINRA) | |
| Security | |
| Prompt-injection defense, secrets isolation, sandboxing, least privilege | |
| Reliability/SLA | |
| Uptime targets, graceful degradation, incident response, RTO/RPO | |
| Cost control | |
| Per-tenant budgets, rate limits, chargeback/showback, model routing | |
| Observability | |
| Tracing, evals, alerting β without logging sensitive conversation content | |
| Change management | |
| Versioned prompts/tools, safe rollout, rollback, user training |
The mindset shift: in traditional software a bug breaks a feature. In an agent, a minor change cascades β one bad step sends the agent down an entirely different trajectory (Anthropic, Multi-Agent Research System). The enterprise tax is what keeps those cascades observable, bounded, and reversible.
β Part 2 checklist
- [ ] Named the compliance regime(s) you must satisfy and the data classes involved
- [ ] Confirmed a "no-train / data-isolation" path with your model provider
- [ ] Decided the tenancy boundary (company / team / user) up front
- [ ] Made audit logging a P0, not a P2
Every production agent that works is recognizably the same system: a small reliable kernel loop wrapped in a thoughtfully engineered harness, exposed through thin surface adapters. Here is the enterprise-shaped version.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SURFACES (thin adapters) β
β Web app Β· Slack/Teams Β· IDE Β· API Β· Email Β· Cron/Webhook β
βββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β authenticated, per-tenant request
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GATEWAY / CONTROL PLANE β
β AuthN (SSO) Β· AuthZ (RBAC) Β· rate limit Β· budget check Β· routing β
βββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENT RUNTIME (the kernel) β
β Loop: Observe β Think β Act β Observe β
β Session state (append-only events) Β· iteration/cost budgets β
β Context engine (cache-stable prefix + compaction) β
β Sub-agent orchestration (context firewalls) β
βββββ¬βββββββββββββββββ¬ββββββββββββββββ¬ββββββββββββββββ¬ββββββββββββββββ
β β β β
βββββΌββββββ βββββββΌββββββ βββββββΌβββββββ ββββββΌββββββββββ
β TOOLS β β MEMORY β β SANDBOX β β MODEL LAYER β
β registryβ β L0/L1/L2 β β per-tenant β β provider β
β + MCP β β + files β β isolation β β abstraction β
βββββ¬ββββββ βββββββββββββ ββββββββββββββ ββββββββββββββββ
β enterprise connectors (RBAC-scoped, per-tenant secrets)
βββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SYSTEMS OF RECORD: DB Β· CRM Β· ticketing Β· data warehouse Β· APIs β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Cross-cutting: OBSERVABILITY (tracing, metrics, evals, cost) Β·
SECURITY (guardrails, secrets, audit) Β·
GOVERNANCE (policy, HITL approvals)
Design principles that make this scale (from OpenHands V1, Hermes, GoClaw):
ConversationState
, which you
β Part 3 checklist
- [ ] Kernel is one loop; surfaces are adapters
- [ ] State is append-only events (replayable/auditable)
- [ ] Control plane (auth/budget/routing) sits in front of the runtime
- [ ] Provider access goes through one abstraction, never scattered SDK calls
All production agents converge on Observe β Think β Act β Observe β 4β5 phases, not a callback web. Keep the kernel small and boring; put cleverness in the harness.
Three proven shapes:
step()
returning a typed unionforward_with_handling()
wraps the model call with "Skipped due to user message"
result so the model knows what didn't run.tool_use
/tool_result
invariant β the #1 correctness bug
Every tool_use
must have a paired tool_result
before the next model call (API requirement). On cancellation or error, emit a synthetic result ("Cancelled: Bash(mkdir) errored"
). OpenHands' runner enforces: drop orphan results, backfill missing ones, and microcompact each iteration. Get this wrong and you get random 400s and corrupted transcripts in production.
Battle-tested defaults (Hermes, Claude Code, OpenHands):
| Budget | Default | Why |
|---|---|---|
| Max iterations / task | 20β25 | Bound runaway loops |
| Per-task cost cap | ||
| e.g. $2β$3 | ||
| Cost is the real stop signal β step count varies 5Γ across models | ||
| Max requeries on parse fail | 3 | Don't loop on malformed output |
| Consecutive timeouts | 5 β hard abort | Escape stalls |
| Context overflow | compact at ~80%, then continue | Never hit a hard 400 |
Anthropic's own finding: token usage alone explains ~80% of task-performance variance on hard browse tasks. Budgets aren't just cost control β they're your primary lever on both quality and spend.
β Part 4 checklist
- [ ] Loop is 4β5 phases, kernel < a few hundred lines
- [ ] Synthetic
tool_result
emitted on every error/cancel path- [ ] Stop conditions are cost-based, with iteration/timeout backstops
- [ ] Steering queue lets a human correct mid-run
Tools are the agent's hands β and, per Anthropic, you should spend as much effort on the agent-computer interface (ACI) as on the prompt. On SWE-bench they spent more time optimizing tools than the overall prompt.
name
, image_url
(semantic) β not uuid
, 256px_image_url
(noise). Paginate and cap responses (~25K tokens) by default; steer toward many small searches over one giant dump.schedule_event
(finds availability list_users β list_events β create_event
. Fewer round-trips = fewer tokens, fewer errors.concise
vs detailed
; concise uses ~β
the tokens.read_only
/ coding
/ messaging
/ full
.read-only
vs mutating
, concurrency-safe or not.Bash("ls")
is safe; Bash("rm -rf")
is not. Tools self-register at import time (Hermes, PicoClaw) β no hand-maintained lists that drift.
The Model Context Protocol (MCP) is now the de-facto open standard ("USB-C for AI") for connecting agents to tools, data, and workflows, supported across Claude, ChatGPT, VS Code, Cursor, and more. For enterprise it gives you:
Enterprise cautions with MCP: agents encounter unfamiliar tools with wildly varying description quality (Anthropic). Curate an internal MCP catalog: vet each server, standardize descriptions, pin versions, and scope credentials per tenant. Treat a third-party MCP server as untrusted code and network egress β sandbox it. Anthropic even built a tool-testing agent that uses Claude to rewrite weak tool descriptions; the model-optimized definitions beat human-written ones on their internal Slack/Asana evals and helped reach state-of-the-art on SWE-bench Verified β so let the agent improve its own tool docs, then eval-gate the result before promoting it (Anthropic, Writing Effective Tools for AI Agents, 2025).
MCP has matured β build on the standard, don't reinvent it. Two 2025β2026 developments matter for enterprise: (1) the official MCP Registry (launched Sept 2025) is a curated server directory with provenance/ownership metadata β use it (or a private mirror) as the vetting front door to your internal catalog instead of hand-collecting servers; (2) the MCP authorization spec now aligns with OAuth 2.1 / OpenID Connect, adds Enterprise-Managed Authorization (IdP admins grant consent centrally rather than per-user prompt fatigue), and mandates issuer (iss
) validation (RFC 9207) to close a "mix-up" attack class inherent to MCP's one-client/many-server shape. Require these of any server you admit.
When the tool count gets large, don't load every schema. A vetted catalog can still be hundreds of tools; putting all their schemas in the prompt bloats context and hurts selection accuracy. Use tool search / progressive tool disclosure β the agent discovers and loads only the relevant definitions per request (Anthropic reports large should-call-rate gains from this), which also keeps the cache-stable prefix intact (Part 6.1) because schemas are appended, not swapped.
Skills are SKILL.md
files (YAML frontmatter + markdown procedure) loaded by progressive disclosure: a one-line description in the system prompt, full content on demand, referenced files only when invoked. Agents can write new skills after solving a hard problem (Hermes, Multica). Skills β not prompts β are the durable, reusable, portable asset; every run gets cheaper as the library grows.
β Part 5 checklist
- [ ] Tools are mistake-proofed and return semantic, paginated output
- [ ] Frequently-chained ops are consolidated into single tools
- [ ] Registry enforces profile + capability + per-invocation checks (fail closed)
- [ ] Enterprise systems integrated via a vetted, per-tenant-scoped MCP catalog
- [ ] A skills library exists and grows from solved problems
On agentic workloads, input tokens are ~90% of the bill (roughly a 100:1 input:output ratio). Context engineering is cost engineering.
Trigger at ~80% of the input budget. Summarize the oldest ~70% into a typed checkpoint (durable memory, execution summary, preserved requirements, skill refs) and keep the ~4β12 most recent messages verbatim. Offload bulky tool outputs to workspace files β keep head + tail + a path preview and reload on demand. Naive full-transcript replay is O(kΒ²); managed compaction makes it O(k).
| Tier | Contents | Loaded via |
|---|---|---|
| L0 working | ||
| current session events | in-context (append-only) | |
| L1 episodic | ||
| session summaries + embeddings, ~90-day retention | ||
memory_search tool |
||
| L2 semantic | ||
| knowledge-graph entities/relations, temporal validity | ||
memory_expand tool |
Start file-based (MEMORY.md
, USER.md
, history.jsonl
) β don't reach for a vector DB until you exceed ~1M tokens of durable knowledge. Read memory at session start, inject it immutably, and let updates take effect next session (frozen-snapshot pattern β Hermes). For long-horizon runs, persist the plan to memory before context truncates, and spawn fresh sub-agents with clean contexts via careful handoffs (Anthropic).
Most enterprise knowledge lives in systems of record, not the prompt β so retrieval (RAG) quality drives answer quality.
Enterprise note: memory is a data-governance and attack surface. Memory poisoning β an attacker getting malicious content written into memory that the agent later reads back as trusted β is a distinct, persistent threat (it's a top-ranked risk in the OWASP Agentic Top 10; unlike a one-shot prompt injection, a poisoned memory keeps misdirecting every future session that loads it). Scope memory per tenant, apply retention limits, attribute every write to an actor, keep an immutable version history so you can audit and redact, and scan memory for injection/exfiltration patterns before injecting it back into the prompt.
β Part 6 checklist
- [ ] Prompt is frozen; prefix is byte-stable and cached
- [ ] Compaction triggers at ~80%, keeps a live tail, uses a cheaper helper model
- [ ] Bulky outputs offloaded to files; loaded on demand
- [ ] Memory is per-tenant, retention-bounded, and injection-scanned
"In agentic systems, minor issues that would be trivial for traditional software can derail agents entirely." β Anthropic
| Failure type | Response |
|---|---|
| Rate limit / transient | Retry with exponential backoff + jitter |
| Malformed stream | Discard mid-stream cleanly, requery (max 3) |
| Stall / no progress | Timeout; break the pattern |
| Provider outage | Failover to backup provider/model |
| Permanent (auth, bad request) | Surface to human; do not loop |
Never silent-retry. Log every retry with its reason. Circuit-break when the model repeats an identical failing call 3Γ β back off instead of burning budget.
Detect repeated identical actions, oscillation between two states, or zero net change over K steps β break the loop. Have the agent track progress in a TODO.md
/NOTES.md
; an observer watches for no forward motion. Hard stops: max iterations, wall-clock timeout, cost ceiling.
Agents are stateful and errors compound; a restart from scratch is expensive and infuriating. Anthropic combines "the adaptability of the model with deterministic safeguards like retry logic and regular checkpoints," and resumes from where the error occurred. Concretely:
--continue
reloads history, recaps, and picks up.git diff
) and ship the partial result rather than losing everything.Agents are long-running, so a normal deploy can catch them mid-trajectory. Use rainbow deployments: run old and new versions simultaneously and shift traffic gradually, never cutting a running agent over mid-task (Anthropic).
One provider abstraction, multiple backends (Anthropic native, OpenAI-compatible, Bedrock/Vertex, CLI subprocess). Layer retry β cooldown β failover chain β cache. Normalize all provider stream formats to one internal shape so vendor JSON differences never leak into your loop. This also protects you from single-vendor outages and price changes β a real enterprise procurement requirement.
β Part 7 checklist
- [ ] Failures are classified; retries are logged, backed off, and circuit-broken
- [ ] Stuck detection with hard stops
- [ ] State checkpointed durably; runs resume, not restart
- [ ] Rainbow (or blue/green) deploys protect in-flight agents
- [ ] Multi-provider failover behind one abstraction
This is the part that gets an enterprise deal signed or killed.
| Layer | Control |
|---|
- Channel | allowlist users/chats/IPs before the loop sees input |
- Autonomy |
coarse mode (
read_only/supervised/full) + per-tool overrides | - Workspace |
workspace_only=true, forbidden-paths, resolve symlinks before enforcing | - Shell | command allowlist/blocklist + dangerous-flag/pipe pattern matching |
- Sandbox | OS isolation (Landlock/Bubblewrap, Seatbelt, Docker/microVM) per tenant |
- Audit | tamper-evident tool receipts (HMAC of session + name + args + result + ts) |
Every mutating action passes through a per-invocation check on the parsed input, and the sandbox is the trust boundary β a sandboxed backend can auto-approve because it can't escape.
Simon Willison's rule (2025): untrusted input + access to private data + a way to exfiltrate = disaster. Break at least one leg.
Detection is not containment β this is the single most important security lesson of the last year. In The Attacker Moves Second (2025; researchers from Anthropic, OpenAI, and Google DeepMind), adaptive attackers bypassed 12 published prompt-injection/jailbreak defenses with >90% success, and human red-teamers reached ~100% β against defenses that had originally reported near-zero vulnerability. The takeaway: a guardrail/classifier model is a useful layer but never the load-bearing one. Safety must come from architecturally breaking a leg of the trifecta (remove the private data, the tool reach, or the egress), not from detecting the injection. Operationalize it with the Agents "Rule of Two" (Meta, 2025): in a single un-supervised run, allow at most two of {processes untrusted input Β· can access private data/systems Β· can change state or communicate externally}. The moment a flow would have all three, insert a human approval or split the flow.
exec
/subprocess
.| Control | What to have ready | |---|---| SOC 2 Type II / ISO 27001 | Audited controls over the agent platform | GDPR / CCPA | Data residency/region pinning, DSAR support, retention limits, DPA with provider | No-train guarantee | Contractual assurance customer data isn't used to train models | Sector rules | HIPAA (BAA), PCI-DSS (never let the agent touch raw card data), FINRA/SEC record-keeping | AI governance | Model/prompt versioning + an AI risk register, aligned to the frameworks you'll be audited against: NIST AI RMF, the EU AI Act (GPAI transparency obligations and provider penalties become enforceable 2 Aug 2026 β a hard date, not a someday), and the OWASP Top 10 for Agentic Applications (2026) as the concrete threat checklist for the agent itself | Immutable audit log | Every action β which user, which tenant, which tool, which inputs, what result, when |
β Part 8 checklist
- [ ] Six-layer defense-in-depth implemented, fail-closed
- [ ] At least one leg of the lethal trifecta is broken for every risky flow
- [ ] High-impact actions gated by human approval
- [ ] Secrets in a vault, injected at execution, per-tenant isolated
- [ ] Agent acts with the user'sRBAC scope, not a superuser- [ ] Compliance artifacts (SOC 2, DPA, no-train, audit log) in place
Design for multi-tenancy from day one β retrofitting it is a rewrite.
session_key
(all work in a session is strictly serial β no history races); run different sessions in parallel. This is the simplest correct model for multi-tenant chat/agent workloads (nanobot, PicoClaw, GoClaw).tenant_id
in the WHERE
clause (or Postgres RLS) β never rely on app-level ACLs alone.Sub-agents / multi-agent where warranted: an orchestrator delegates to workers with separate context windows as context firewalls β each returns a distilled ~1β2K-token summary, and large artifacts are written to a filesystem and passed by reference to avoid the "game of telephone" (Anthropic). Cap nesting depth (β€3) and concurrent children (β5, semaphore-guarded). The tradeoff is real in both directions: multi-agent burns ~15Γ the tokens of a chat, but Anthropic's orchestrator-worker research system also outperformed a single agent by ~90% on their internal research eval β so reserve it for high-value, parallelizable work (research, breadth-first triage) where that quality lift pays for the tokens, not routine coding.
β Part 9 checklist
- [ ] Tenant is the first dimension everywhere (sessions, rows, paths, cost)
- [ ] DB-level tenant isolation (WHERE/RLS), not app-level only
- [ ] Per-tenant secrets, budgets, and rate limits
- [ ] Per-session serial / cross-session concurrent locking
- [ ] Multi-agent reserved for high-value parallel work, with firewalls + caps
You cannot operate what you cannot see β and agents are non-deterministic between runs even with identical prompts.
Every Action, Observation, and Thought is a typed event with timestamp + source. The event stream is the single source of truth: replayable, debuggable, audit-friendly. Add per-turn spans: tokens in/out, tool calls, latency, cost, model used. Anthropic monitors decision patterns and interaction structure without reading conversation content β critical for privacy/compliance. Full production tracing is what let them diagnose "agent can't find obvious info" failures systematically.
cost_exhausted
, not a surprise bill.
β Part 10 checklist
- [ ] Append-only event log; per-turn cost/latency/token spans
- [ ] Observability captures structure, not sensitive content
- [ ] Eval set (start ~20 cases) + LLM-judge + end-state checks + human review
- [ ] Per-task/tenant cost ceilings + model routing + showback
The same agent serves a 5-person startup and a 50,000-person regulated enterprise only if you can deliver it in different topologies without forking the codebase. Because the runtime is stateless with externalized state (Part 3) and every concern sits behind an interface, the same build can ship in four shapes β you pick per customer based on their data-residency, compliance, and ops appetite.
| Model | Who it's for | What runs where | Trade-offs |
|---|---|---|---|
| Multi-tenant SaaS | |||
| SMB β mid-market; fast self-serve | You host everything; tenants are logical slices (RLS, per-tenant secrets/budgets) | Lowest cost & fastest onboarding; customer must accept your cloud + a DPA/no-train guarantee | |
| Single-tenant SaaS (dedicated) | |||
| Regulated mid-market; noisy-neighbor-averse | You host, but one isolated stack per customer (own DB, own sandbox pool) | Stronger isolation & per-tenant SLAs; higher unit cost & ops overhead | |
| Self-hosted / BYOC (in customer VPC) | |||
| Large & regulated enterprise | Customer runs the platform in their cloud/on-prem; their keys, their egress | ||
| Meets data-residency & no-egress mandates; you lose direct observability β ship a support/telemetry bridge they control | |||
| Hybrid (split-plane) | |||
| Enterprises wanting managed control + private data | |||
| Control plane (auth, routing, billing, eval/skill/MCP catalogs, audit sink) hosted by you; data plane (runtime, sandbox, memory, model calls) in the customer VPC | |||
| Best of both β you operate the fleet, sensitive payloads never leave their boundary; most complex to build & version |
Keep a hard control-plane / data-plane split from day one (Part 3). The control plane is auth, RBAC, routing policy, budgets, the eval + skill + MCP catalogs, and the audit sink. The data plane is the kernel loop, sandboxes, memory, and provider calls. If those two never bleed into each other, "move the data plane into the customer's VPC" becomes a deployment flag, not a rewrite. Version the control-planeβdata-plane contract explicitly so a hosted control plane can talk to a slightly older data plane during rollout.
Model routing is a deployment lever too. The two-axis router (Part 8.3, Part 10.3) lets a single hybrid deployment send regulated payloads to a self-hosted in-VPC model (e.g. an open-weights model on vLLM) while non-sensitive reasoning uses a frontier API β so a customer gets frontier quality and no-egress compliance in the same agent, decided by data label.
Package for portability. Ship as a versioned OCI image set + Helm chart (or Terraform module) so self-hosted/BYOC customers deploy a known-good, signed artifact, and rainbow deploys (Part 7.4) apply equally in their cluster.
Onboarding a new org is configuration and connectors, not a code fork. Everything an org needs to differ is data the platform reads at runtime, in rising order of effort:
SOUL.md
, IDENTITY.md
, AGENTS.md
, TOOLS.md
) + a toolset profile (read_only
/coding
/messaging
/full
) + autonomy level. SKILL.md
procedures (their conventions, runbooks); the agent grows more via the eval-gated skill loop (Part 5.4). The honest boundary on "easily." Customization effort scales with how standard the org's systems are β a connector to a system with a maintained MCP server or clean REST API is an afternoon; a proprietary internal system with undocumented auth, no API, and a VPN requirement is a genuine integration project. The platform gives you the right seam (an RBAC-scoped MCP connector) and the sandbox/audit to run it safely β but you never fork the kernel. And customization never bypasses the trust surface: per-org skills, tools, and connectors are still production config β versioned, eval-gated, sandboxed, and subject to the lethal-trifecta rules (Part 8).
β Part 11 checklist
- [ ] The same build runs in all four topologies via config (no per-customer fork)
- [ ] Control plane and data plane are separately deployable with a versioned contract
- [ ] A customer can choose "data plane in my VPC" without a code change
- [ ] Shipped artifact is a signed image + Helm chart / Terraform module
- [ ] New orgs onboard via tenant config + agent definition + skills + surfaces + per-tenant MCP connectors
Enterprises don't buy agents β they adopt them in stages. Match your engineering to the stage; don't build stage-4 infrastructure for a stage-1 pilot.
| Stage | Scope | What matters most | What to build |
|---|
- Prototype | 1 team, 1 use case | Prove value fast | Raw API, minimal harness, manual eval, 20-case eval set |
- Pilot | 1 dept, real users | Reliability + safety basics | Budgets, sandbox, audit log, HITL on risky actions, tracing |
- Production | 1 org, SLA-backed | Multi-tenancy, cost, deploys | Control plane, per-tenant isolation, rainbow deploys, cost ceilings, evals in CI |
- Platform | Many teams/use cases | Reuse + governance | Shared agent platform, MCP catalog, skills library, self-serve, policy engine |
- Enterprise-wide | Whole company / external | Compliance + scale | SOC2/ISO, region pinning, multi-provider failover, AgentOps team, chargeback |
Rules for climbing:
β Part 12 checklist
- [ ] Know which stage you're in and built for thatstage- [ ] Audit log + HITL exist before real users (stage 1)
- [ ] Control plane introduced at first multi-team demand
- [ ] Harness (not model) standardized as a platform for reuse
Part 12 is about adoption (how an org grows into the agent). This part is the orthogonal, purely technical axis: serving thousands of simultaneous, long-running, token-heavy agent sessions efficiently β whether you run multi-tenant SaaS or a single-tenant/self-hosted stack for one large org. A stage-2 single-org deployment can still need 5,000 concurrent sessions, so treat throughput as its own concern.
The good news: the architecture in Part 3 was built for this. A stateless runtime with externalized state scales like any 12-factor service. The hard parts are the three things that aren't stateless web requests β long-running jobs, sandbox pools, and the provider's own rate limits.
An agent run is a job, not a request. It holds a "connection" for minutes, does dozens of model round-trips, and must survive a deploy. Never dedicate a synchronous request thread to a run.
[surfaces] β [gateway/control plane] β [durable queue] β [stateless worker pool] β [sandbox pool]
(auth, budget, admit) (per-session (pull one session, (per-tenant
FIFO key) run the loop) isolation)
session state + memory + event log live in Postgres/object store, never in the worker
The per-session serial / cross-session concurrent rule (Part 9) is exactly what makes throughput scaling safe:
session_key
to a partition so all work for one session is strictly serial (no history races) while different sessions run fully in parallel across the pool. This is consistent-hashing/sharding, and it's the whole trick.Every run needs an isolated sandbox (Part 8.1). Cold-starting one per run adds seconds and dominates tail latency.
At volume you hit provider TPM/RPM (tokens- and requests-per-minute) quotas long before you saturate your own compute. Plan for it:
When demand exceeds capacity, an unbounded system melts down. Bound it:
Retry-After
or return a clear "at capacity" rather than accepting work you can't finish.Agents are unusually chatty against state stores (append-only event writes, memory reads every turn):
Throughput economics change with the deployment shape (Part 11):
β Part 13 checklist
- [ ] Runs are async jobs on a durable queue, never a blocked request thread
- [ ] Workers are stateless; autoscale on queue depth/age, not CPU
- [ ] Route by session key (per-session serial / cross-session concurrent) to shard horizontally
- [ ] Warm sandbox pool with hard TTLs, reclamation, and per-tenant caps
- [ ] Provider TPM/RPM handled: per-tenant rate limits, connection pooling, failover-as-capacity, cached prefixes
- [ ] Admission control + fair scheduling + priority load-shedding + graceful degradation
- [ ] Data plane scaled: pooled DB connections, read replicas, object storage, cache tier
- [ ] Autoscaling policy shipped with the self-hosted/BYOC chart
Technology is half the battle; the other half is who owns it.
β Part 14 checklist
- [ ] Platform team owns the shared harness
- [ ] AgentOps owns SLA, evals-in-CI, cost, and behavioral incident response
- [ ] Governance signs off new tools/autonomy; risk register maintained
- [ ] Prompts/tools are versioned, reviewed, and eval-gated
Days 0β30 β Prove it.
Days 31β60 β Harden it.
Days 61β90 β Scale it.
| Anti-pattern | Why it hurts | Do instead |
|---|---|---|
| Reaching for a multi-agent swarm first | 15Γ token burn, coordination bugs | Start single-agent; add sub-agents only for high-value parallel work |
| Framework as a black box | Can't debug or cost-control hidden prompts | Insist on visibility into prompts/tokens; drop abstractions in prod |
| Mutating the system prompt mid-session | Destroys cache β cost explosion | Freeze the prefix; put volatiles in the tail |
| Stopping on step count | Step count varies 5Γ across models | Stop on cost with iteration/timeout backstops |
| Silent retries | Hides failures, burns budget | Classify, log, back off, circuit-break |
| Superuser service account | One injection β full blast radius | Act with the calling user's RBAC scope |
Feeding tool output straight to exec |
||
| Prompt injection / lethal trifecta | Treat all tool/retrieved content as untrusted | |
| Audit/observability as "phase 2" | You're blind the day it matters | Event log + audit from the first pilot |
| App-level tenant isolation only | One bug leaks cross-tenant data | Enforce tenant_id at the DB (WHERE/RLS) |
| Speculative "future-proof" architecture | Over-built stage-4 rig for a stage-1 pilot | Build for the stage you're in |
| No evals ("we'll add them later") | Can't tell if a change helped or hurt | 20 real cases on day one; LLM-judge + end-state |
| "Graph-RAG eliminates hallucination" | It doesn't; it's costly on flat data | Use Graph-RAG only for relational data; hybrid retrieval otherwise; always ground + cite |
| Trusting a guardrail model to stop injection | ||
| Detection defenses are bypassed by adaptive attackers (>90%) | Break a leg of the trifecta architecturally; the classifier is one layer, not the control | |
| Autonomous endpoint discovery from OpenAPI | Broad tool access β blast radius / injection | Curated, vetted, per-tenant tool catalog (MCP); auto-match within the allowlist only |
| Installing a public-registry MCP server / skill unvetted | Supply-chain poisoning β a popular server can turn malicious | Vet provenance (MCP Registry), pin versions, sandbox + least-privilege every third party |
| Auto-promoting agent-written skills | Ungoverned behavior change | Agent proposes β human/eval gate β version + promote |
The agents that actually serve enterprises are, underneath, the same system: a small, reliable kernel loop wrapped in a carefully engineered harness β cache-stable context, mistake-proofed tools, classified failures, durable state, defense-in-depth, per-tenant isolation, full observability, and cost governance. The differences between a demo and a product are almost never the model. They're the boring, disciplined harness and trust surface around it.
Three things to remember:
Copy the shape, pay the enterprise tax deliberately, and you don't have a chatbot β you have a platform.
This guide is the enterprise blueprint β the what-and-why of shipping an agent a CISO will sign off on. These documents live in this same repo and go deeper on the layers referenced above. Read the one that matches the part you're working on.
| Document | Why it pairs with this guide |
|---|---|
tool_result
, cache breaks, stuck loops) and their fixes.The production agents named in the intro, dissected. Each grounds a specific enterprise concern in real code.
| Document | Grounds |
|---|---|
tool_use
/tool_result
invariant, and append-only state (Parts 3, 4, 7).
Suggested reading path:
This guideβ decidewhether/whatto build and price the enterprise tax.- β [ποΈ Building High-Quality AI Agents]β the harness + tool foundations.- β [π€ Optimizing AI Agents: Token Economics]β make it cheap and fast.- β [π€ The Agentic Loop]+[β οΈ Common Issues & Fixes]β harden the kernel.- β [π¦ GoClaw]+[π OpenHands]deep dives β see multi-tenancy and the kernel in real code.- β [ποΈ Building Production-Grade Fullstack Products]β ship it end-to-end.
modelcontextprotocol.io
) β the open integration standard; the If you found this helpful, let me know by leaving a π or a comment!, or if you think this post could help someone, feel free to share it! Thank you very much! π