From Prompt to Production AI Agent: The Complete 30-Day Architecture & Builder Guide


Rohit Gite, Founder @MewCP
Thirty lessons, one path. Everything this series taught about building AI agents, condensed into key rules, a reference architecture, a reference implementation, a builder roadmap and one production checklist.
Thirty days ago this series started with one question: what is an AI agent?
The common answer is "an LLM with a prompt." It is not wrong. It describes how almost every agent begins. But after thirty days of taking agents apart, the honest answer is longer: an AI agent is a system. It reasons and plans. It remembers. It acts through tools. It runs on infrastructure that knows who it is acting for, holds the right credentials, keeps customers apart, records what happened and checks that it still works.
This guide is the whole series in one place. It is written to be kept, not skimmed: a reference you can open when you are designing an agent, reviewing one, or deciding what to build next.
If one sentence survives the whole series, make it this:
Building an AI agent is easy to demonstrate. Building one that reliably operates in the real world requires an infrastructure layer.
Everything below is the explanation of that sentence: the first half (what an agent is and how it works) and the second half (what it takes to operate one for real people).

THINK 01 USER ─ 02 GOAL ─ 03 AGENT ─ 04 PLANNING ─ 05 MEMORY
ACT 06 TOOL USE ─ 07 MCP
TRUST 08 AUTHENTICATION ─ 09 CREDENTIALS ─ 10 MULTI-TENANCY
PROVE 11 OBSERVABILITY ─ 12 EVALUATION ─ 13 PRODUCTIONThe first five stations are about the agent learning to think. The next two are about it learning to act. The next three are about it earning the right to act for real people. The last three are about proving it works, then shipping.
Notice where the model appears. It does most of its work at stations 03 to 06. The other nine stations are mostly not model problems at all. That is the shape of the whole series, and of every production agent.
An AI agent is a system that pursues a goal by deciding its own next steps, taking actions through tools, observing the results, and continuing until the goal is met or it should stop. The model provides the decisions. The system around it provides everything else.
Key rule: if nothing in your system decides the next step based on what just happened, it is not an agent. That is fine. Many problems do not need one.
A chatbot responds. An agent acts. A chatbot's output is text for a human to read; an agent's output is often an action in another system, which is why everything about safety, identity and reliability gets harder.
Key rule: the moment your system's output changes something outside the conversation, you are building an agent, and the bar for correctness rises.
Every agent runs a loop: observe the current state, think about what to do, act, observe the result, repeat. The loop is simple. Controlling it is not: it needs a step limit, a time limit, and a stop condition other than "the model said it was done."
Key rule: never ship a loop without a maximum number of steps and a maximum wall-clock time.
Autonomy is not one property. It is a dial: how many decisions the agent makes without a human, how consequential they are, and how long it runs unattended. More autonomy is not automatically better; it is a cost you pay for convenience.
Key rule: set autonomy per action, not per agent. Reading can be autonomous while sending, paying and deleting require approval.
Reasoning is necessary but not sufficient. An agent's value is in what it does: the tools it calls and the state it changes. That shifts the engineering focus from prompts to actions, and from "is the answer good?" to "was the action right?"
Key rule: evaluate actions, not just answers.
A workflow follows a path you designed in advance. An agent chooses its path at runtime. Workflows are cheaper, faster and more predictable; agents handle variety a fixed path cannot. Many good systems are workflows with one or two agentic steps inside them.
Key rule: use a workflow when you can draw the path. Use an agent only for the parts you cannot.
An agent has recognisable parts: a model, instructions, tools, memory, a planning approach and a control loop, plus the guardrails around them. Naming the parts makes it possible to debug them one at a time.
Key rule: when an agent fails, find which part failed before you change the prompt.
Planning turns a goal into steps. It can be implicit (the model decides one step at a time) or explicit (the model writes a plan first, then executes it). Explicit plans are easier to inspect, review and correct, especially for long or consequential tasks.
Key rule: for any task longer than a few steps, make the plan visible, so a human or a check can catch a bad plan before it runs.
Memory comes in layers: the working context of the current call, the session state of the current task, and long-term memory retrieved when relevant. Stuffing everything into the context window is not memory; it is a growing bill and a dilution of attention.
Key rule: every memory write has an owner, and every memory read is filtered to that owner before the model sees it.
The model never runs a tool. It produces a structured request (a tool name and arguments that match a schema); your code validates it, runs it, and returns the result for the model to read. Tool calling is a contract between the model and your code.
Key rule: validate every tool call your code receives as if it came from an untrusted client, because in effect it did.
Agents fail in recognisable ways: wrong tool, right tool with wrong arguments, loops that do not terminate, confident answers built on failed tool calls, context that drifted, and actions taken on instructions injected through data. Most failures are not "the model is dumb"; they are missing guardrails.
Key rule: for every failure mode, there should be a mechanism outside the model that catches it.
Put together, an agent has a model layer, a planning layer, a memory layer, a tool layer and an execution layer, plus the guardrails and observability around them. Each layer has its own failure modes and its own tests.
Key rule: design the layers explicitly, even if each one is tiny at first.
Without tools, an agent can only talk. Tools are what connect reasoning to reality: reading data, writing records, sending messages, triggering systems. Choosing and designing the tool set is one of the highest-leverage decisions you make.
Key rule: give the agent the smallest set of tools that completes the job, not every tool you can.
A tool is a name, a description, an input schema and a handler. The model only ever sees the first three, so the description and schema are effectively part of the prompt. Clear names, precise descriptions, tight schemas and helpful error messages measurably change how well an agent uses a tool.
Key rule: write tool descriptions for the model, not for humans, and reject unknown properties in every schema.
Connecting one agent to one API is easy. Connecting many agents to many APIs, each with its own auth, schema style, errors and rate limits, becomes an N times M integration problem that grows faster than the product.
Key rule: standardise the interface between agents and tools before the integrations multiply.
The Model Context Protocol is an open standard for connecting AI applications to tools, data and prompts. An MCP server exposes capabilities; an MCP client inside the AI application discovers and uses them. One server works with any compliant client, which turns N times M integrations into N plus M.
Key rule: if you are writing a tool integration that more than one agent or client will use, write it as an MCP server.
MCP does not replace APIs. It sits on top of them. The API is how a service exposes its functionality to programs; MCP is how that functionality is described and offered to models, with discovery, schemas and a standard way to call it. Most MCP servers are thin, careful wrappers around existing APIs.
Key rule: put the MCP boundary where the model needs a tool, not where the API happens to have an endpoint. One good tool may combine several endpoints.
An MCP architecture has a host (the AI application), clients (one per server connection), and servers (which expose tools, resources and prompts). Servers can run locally over stdio or remotely over Streamable HTTP. Remote servers serve many users, which is where identity, credentials and isolation enter the picture.
Key rule: local servers are for one person's machine. Anything serving many users is a remote service and needs to be operated like one.
The moment an agent acts on someone's behalf, it needs to know who that someone is. Identity must come from a verified token or session, never from anything the client or the model says. For remote MCP servers, the specification bases authorization on OAuth 2.1, with servers acting as OAuth resource servers that accept only tokens issued for them.
Key rule: identity is a property of the authenticated request, never a field the model can supply.
Authentication asks who the user is. Credential management asks which third-party token acts for them, right now, at this provider. Those tokens are issued through OAuth, expire, get refreshed, get revoked by users, and carry scopes. They are the most sensitive data your agent platform holds.
Key rule: resolve credentials per user, per provider, per call. Never put them in environment variables, long-lived objects, logs or the model's context.
One platform, many customers, five things that must never touch: data, credentials, permissions, executions and configuration. In a classic SaaS app the tenant boundary is enforced once, in the query. In an agent the model chooses arguments at runtime, so tenancy must be re-derived from the request on every tool call. Caches, vector namespaces, background jobs, retrieved memory and reused tool sessions are where it leaks.
Key rule: tenant_id never appears in a tool schema. The server decides who is asking.
Stateful services hold session state in memory; stateless services get the context they need with each request or from explicit stores. Stateless tiers scale horizontally and deploy safely, which suits agent workers and gateways. Agents still have state; the point is to keep it in durable, explicit stores rather than in a process that can restart.
Key rule: bind identity and context to the request, keep run state in a durable store, and keep the compute tiers stateless where you can.
Reliability is not something the model provides. It comes from engineering: timeouts on every call, retries only where they are safe, validation of inputs and of tool results, fallbacks, clear error handling, idempotency for writes, and human approval for consequential actions.
Key rule: a timeout means you stopped waiting, not that the upstream stopped working. Only retry what is idempotent.
Observability answers what the agent did, which tool it called, with what parameters, what came back, how long it took, where it failed and what it cost. Logs, traces, metrics and execution history are the raw material; one trace per run, linking model turns and tool calls, is the core.
Key rule: you should be able to reconstruct any single run from last week, step by step, including cost.
A successful demo is one sample. Evaluation measures task success, tool selection accuracy, output quality, reliability, latency, cost and safety in a repeatable way, so that a change can be compared against a baseline instead of an impression.
Key rule: run every evaluation case more than once, and block releases when the pass rate regresses.
The agent is one box in a ten-layer stack: agent, models, tools, memory, authentication, credentials, multi-tenancy, execution, observability and evaluation. The top four make a demo; the bottom six make a product. Each one should be owned, bought or deliberately deferred.
Building an agent and operating an agent platform are different jobs. Between the agent and its tools sits an infrastructure layer that decides who can call what, with whose credentials, how often, and records what happened: MCP servers, tool access, authentication, credentials, tenancy, a gateway, rate limiting, execution and observability.
Every remote MCP server you self-host is a service you run. Hosted MCP infrastructure moves deployment, credential storage and upstream maintenance to a provider, while the protocol stays identical. Self-host your domain tools and anything with strict data constraints; consider hosting for the common integrations. Host the common, own the unique.
Five layers on the request path (application, agent, MCP gateway, MCP servers, tools and services) and five concerns that cut across every layer (authentication, credentials, tenancy, observability, evaluation). The gateway is where the concerns meet for tool calls. The model chooses tools and arguments; the stack decides everything else.
AUTH CREDS TENANCY OBSERV. EVALS
┌─────────────────────────────────────────────────────────────┐
│ AI APPLICATION users, sessions, runs, approvals UI │
├─────────────────────────────────────────────────────────────┤
│ AGENT loop · planning · memory · model routing │
│ step limits · stop conditions │
├─────────────────────────────────────────────────────────────┤
│ MCP GATEWAY verify → scope → validate → limit → │
│ inject credential → dispatch → trace │
├─────────────────────────────────────────────────────────────┤
│ MCP SERVERS your domain servers │ hosted servers │
├─────────────────────────────────────────────────────────────┤
│ TOOLS & SERVICES your systems │ third-party APIs │
└─────────────────────────────────────────────────────────────┘
Durable run store · Credential vault · Rate-limit store
Telemetry pipeline ──▶ Evaluation (CI suites + sampled runs)Three properties make this architecture production-grade rather than just complete:
Here is a compact agent loop in TypeScript that embodies the rules above. It uses the Anthropic TypeScript SDK for the model and the official MCP TypeScript SDK to reach tools through a gateway over Streamable HTTP. It has a step limit, a wall-clock limit, per-call timeouts, approval for anything not on a read-only allowlist, and tracing. It is deliberately small. Everything it leaves out (durable runs, evaluation, multi-tenant memory) is covered in the roadmap that follows.
import Anthropic from "@anthropic-ai/sdk";
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { trace, SpanStatusCode } from "@opentelemetry/api";
const anthropic = new Anthropic();
const tracer = trace.getTracer
What to notice:
ctx.accessToken.MAX_STEPS or MAX_WALL_MS, whichever comes first, and says so.is_error, so it can reason about them instead of crashing the run.The allowlist above names the four meta-tools of a discovery-style gateway such as MewCP's, where call_tool executes whichever underlying tool was chosen. With that surface, decide approval on the underlying tool inside call_tool's arguments rather than on the meta-tool name, so a read and a send are treated differently. With a gateway that exposes tools directly, list your read-only tool names instead.

You do not build all of this at once. You build it in the order the failures arrive.
Goal: prove the agent can do the task at all.
You are ready to move on when the agent completes most of your example tasks and you can explain its failures.
Goal: let other people use it without it acting as you.
You are ready to move on when you can answer "what did the agent do for this person on Tuesday?" in minutes, and a prompt change is checked by the suite before it ships.
Goal: serve more than one organisation without them ever touching.
tenant_id absent from every tool schemaYou are ready to move on when two tenants can run the same prompt at the same moment and the database query log proves each touched only its own rows.
Goal: operate reliably, at scale, with evidence.
This is the consolidated checklist for the whole series. Every item should be a yes, or a written, deliberate deferral.
Agent loop and planning
Models
Memory
Tools and MCP
Authentication
Credentials
Multi-tenancy
tenant_id never appears in a tool schemaExecution and reliability
Observability
Evaluation
Agent - A system that pursues a goal by choosing its own next steps and acting through tools. Agent loop - The observe, think, act, observe cycle an agent repeats until it stops. Approval gate - A point where a human must confirm an action before it executes. Credential vault - Encrypted storage for upstream tokens, resolved and injected per call. Enforcement matrix - A grid of layers by concerns, showing where each concern is enforced. Evaluation suite - A repeatable set of cases that measures whether an agent still works. Gateway - The single entry point for tool calls, where policy is enforced. Hosted MCP server - A remote MCP server operated by a provider rather than by you. Idempotency key - An identifier that lets an upstream deduplicate a retried write. MCP (Model Context Protocol) - An open standard for connecting AI applications to tools, data and prompts. MCP client - The component inside an AI application that connects to one MCP server. MCP server - A program that exposes tools, resources and prompts over MCP. Multi-tenancy - Serving many customers from one platform while keeping them isolated. Planning - Turning a goal into steps before or during execution. Stateless service - A service that gets its context per request or from explicit stores, rather than holding it in memory. Streamable HTTP - The MCP transport for remote servers. stdio - The MCP transport for local servers launched as subprocesses. Token passthrough - Forwarding a client's token to an upstream API; forbidden by MCP's authorization guidance. Tool - A name, description, input schema and handler that lets an agent act. Trace - A linked record of every step in one run. Trust boundary - A line across which inputs must be treated as untrusted.
We started this series to teach how agents actually work, not to sell anything, and most of this guide applies whatever tools you choose. It is still fair to say plainly what we build, because it sits on this map.
MewCP builds infrastructure for the MCP layer of the stack: a gateway in front of a catalogue of hosted MCP servers. Per its documentation, an agent connects to one endpoint and sees a small, fixed tool surface (search, get_schema, list_accounts, call_tool) however many apps are connected. Credentials are encrypted at rest in a vault, decrypted and injected into the upstream request only at the moment a tool is called, and never sent to the client, the agent or the model. OAuth tokens are refreshed automatically. For teams building their own multi-customer products, MewCP's Auth API ties each credential to an external user id they supply.
On the thirteen-station map, that covers part of stations 07 to 09 (MCP, authentication at the gateway, credentials) for third-party integrations. It is not your agent, your planning, your memory, your domain tools, your tenancy rules, your observability stack or your evaluation suite. Those stations are yours to walk.
Thirty days, thirteen stations, one path.
The first part of the path is the part everyone sees: an agent that thinks, plans and remembers. The second part is the part that makes it useful: tools, and a standard way to reach them. The last two parts are the ones that make it trustworthy: knowing who it acts for, holding their credentials safely, keeping customers apart, seeing what it did and proving it still works.
None of the last two parts makes a good demo. All of them make a good product. If you take one habit from this series, make it this: whenever an agent works in a demo, ask which of the thirteen stations it has actually reached. The answer is usually fewer than it looks, and the gap is exactly the work that turns a prompt into a production agent.
Thank you for walking it with us.