Shipping it: deploy, monitor, iterate
Module 07 · est. 45 min · You’ll build: your agent deployed to real infrastructure, running on a trigger without you — on the boring stack that runs my fleet (GitHub Actions, Cloudflare Workers/Pages Functions, cron), or on Anthropic’s Managed Agents if you’d rather not host anything.
TL;DR: Deploying an agent is not the hard part anyone makes it out to be. Scheduled agents run on GitHub Actions cron (free, a dozen lines of YAML) or a Cloudflare Worker cron trigger. Event-triggered agents run as Cloudflare Workers or Pages Functions (a webhook endpoint at the edge). If you want Anthropic to host the loop and the schedule as well, Managed Agents scheduled deployments do that, in beta, billed for session runtime on top of tokens. Secrets live in the platform’s secret store. Monitoring is a log line piped to Slack. Stream anything that writes long output. There’s no Kubernetes, no server to patch, no Python runtime to babysit. The “infra” is deliberately boring because boring is what runs for a year without you touching it.
[Operator’s read] My entire agent fleet runs on free or near-free tiers of GitHub Actions and Cloudflare. No servers. I have never SSH’d into a box to keep an agent alive. If your deploy story involves provisioning infrastructure, you’ve overcomplicated it. The whole point of these platforms is that the trigger and the runtime are someone else’s problem.
The deploy decision: which host for which shape
Match your Module 03 shape to its host. This is the whole architecture decision and it takes ten seconds:
| Shape | Host | Why |
|---|---|---|
| Scheduled | GitHub Actions cron, or a Managed Agents deployment | Free cron that runs your repo; or no repo or server at all |
| Polling | GitHub Actions cron (frequent), or a Cloudflare cron Worker | Same as scheduled, just a tighter interval |
| Event-triggered | Cloudflare Worker / Pages Function | An HTTP endpoint at the edge, fires on the webhook |
| Conversational | Claude Code / Cowork locally | A human’s present; it runs where they are |
Most of your first agents are scheduled, so we’ll nail that path first and completely.
Path A — Scheduled & polling: GitHub Actions
This is where most of my fleet lives. The morning brief, the weekly recap, the AI-trends digest, the quarterly bonding scheduler — all GitHub Actions cron jobs. Here’s the entire deploy.
Step 1 — Your repo is your deploy unit. Push the agent repo (the Module 02 starter, hardened through Modules 04-06) to GitHub. That’s the deploy. No build step, no artifact.
Step 2 — Put your secrets in GitHub. Repo → Settings → Secrets and variables → Actions → New repository secret. Add ANTHROPIC_API_KEY and any others (SLACK_WEBHOOK_URL, etc.). These never touch your code. (Module 06’s least-privilege rule applies — scope these keys.)
Step 3 — The workflow file. Drop this at .github/workflows/agent.yml:
name: morning-brief
on:
schedule:
- cron: '0 11 * * *' # 11:00 UTC = 6am Central in summer, 5am in winter. Cron is ALWAYS UTC.
workflow_dispatch: # manual "Run workflow" button — for testing. Always include.
jobs:
run:
runs-on: ubuntu-latest
timeout-minutes: 10 # hard ceiling — a stuck run can't bill forever
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with: { node-version: 22 }
- run: npm ci
- name: Run evals first (don't ship a broken agent)
run: npx tsx evals/run.ts
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Run the agent
run: npx tsx src/run.ts
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
DRY_RUN: 'true' # flip to 'false' only once you trust itThat’s a deployed, scheduled agent. Note three things I bake into every one:
workflow_dispatchlets you hit “Run workflow” in the Actions tab to test on demand. Never wait until 6am to find a bug.timeout-minutesis the infra-level seatbelt that complements Module 06’sMAX_TURNS. Two layers, because a stuck run is a billing event.- Evals run before the agent. If your Module 04 evals fail, the agent doesn’t run. Your test suite is now a deploy gate. This one line is why I can change a prompt and not lie awake. (The evals call the model, so they need the key too, and each test case costs a few cents. If that adds up, run them only when the prompt or tools change.)
Step 4 — Test it. Go to the Actions tab, hit “Run workflow,” watch the logs. Fix until green. Then let the schedule take over. You’re done. It now runs every morning whether you exist or not.
The timezone gotcha, stated plainly: cron is UTC. Always. Central is UTC-6 in winter and UTC-5 in summer, so 6am Central is 0 12 * * * in winter and 0 11 * * * in summer, and DST will shift a fixed UTC schedule by an hour twice a year. For most agents an hour’s drift is fine. If it isn’t, run at a UTC time and let the agent check the local time and decide whether to act, or use Path C, which takes a real timezone.
The Cloudflare alternative. If your stack already lives on Cloudflare, a Worker can run on a schedule too: add triggers = { crons = ["0 11 * * *"] } to wrangler.toml and export a scheduled handler next to your fetch handler. It’s still UTC. One change to the starter: Workers don’t read files from disk, so ship the prompt inside the bundle (a string constant, or a Text module rule in wrangler.toml) instead of using readFileSync.
Path B — Event-triggered: Cloudflare Workers / Pages Functions
When a webhook should fire your agent, you need an endpoint that’s always on. Cloudflare Workers (or Pages Functions, same engine) give you a URL at the edge with no server to run.
Step 1 — The function. A Pages Function lives at functions/webhook.ts in your repo (the file path becomes the URL). This is the event-triggered shape from Module 03, now deployed:
// functions/webhook.ts → becomes https://yoursite.pages.dev/webhook
export async function onRequestPost(context: {
request: Request;
env: { ANTHROPIC_API_KEY: string; WEBHOOK_SECRET: string };
waitUntil: (p: Promise<any>) => void;
}) {
const body = await context.request.text();
// 1. Verify it's real (Module 06). Reject forgeries.
if (!verifySignature(context.request, body, context.env.WEBHOOK_SECRET)) {
return new Response('unauthorized', { status: 401 });
}
const event = JSON.parse(body);
// 2. Acknowledge fast, run the agent async (Module 06 latency pattern).
context.waitUntil(runAgentOn(event, context.env.ANTHROPIC_API_KEY));
return new Response('ok', { status: 200 });
}Step 2 — Deploy it. If you already host a site on Cloudflare Pages (I host alejandrorioja.com, an Astro site, on Pages), the function deploys with your normal git push — Pages picks up the functions/ directory automatically. For a standalone Worker: npx wrangler deploy.
Step 3 — Secrets. npx wrangler secret put ANTHROPIC_API_KEY (or set them in the Cloudflare dashboard for Pages). Same least-privilege discipline.
Step 4 — Point the webhook at it. In whatever system emits the event (Stripe, a form tool, GitHub), set the webhook URL to your deployed endpoint. Send a test event. Watch it fire.
That’s an event-triggered agent in production. The edge keeps it warm; you don’t run anything.
Path C — Let Anthropic host it: Managed Agents scheduled deployments
Paths A and B host your loop. On Claude Managed Agents (Module 01’s third way), Anthropic runs the loop and gives each run a sandbox to work in, and a scheduled deployment fires it on a cron schedule. There’s no repo to run and no workflow file.
You set it up in three pieces, each created once: an agent (model, system prompt, tools, MCP servers; versioned, so you can roll back a prompt change), an environment (the sandbox config, including which hosts it can reach), and the deployment:
const deployment = await client.beta.deployments.create({
name: 'Morning brief',
agent: AGENT_ID, // created once, in the Console or with client.beta.agents.create
environment_id: ENVIRONMENT_ID,
initial_events: [
{ type: 'user.message', content: [{ type: 'text', text: 'Run your job now.' }] },
],
schedule: { type: 'cron', expression: '0 6 * * *', timezone: 'America/Chicago' },
});
console.log(deployment.id, deployment.schedule?.upcoming_runs_at); // check the next fire timesWhat you get compared to Path A: a real timezone (6am Chicago time all year), a run record for every firing including the ones that failed to start, a manual run for testing (client.beta.deployments.run), pause and unpause, and an optional per-run spend cap. Credentials go in a vault (Module 06), so the sandbox never holds the raw key.
What it costs you: it’s in beta, it bills session runtime on top of tokens, session history is kept on Anthropic’s side until you delete it, and execution can run up to 9 minutes after the listed time. One thing to plan for: if a tool is set to ask for approval before it runs, nobody is attached to a scheduled run to answer, so the run waits. Either set permissions so unattended runs don’t need approval, or answer from a webhook handler.
When I’d pick it: the agent needs a workspace (files, a shell, code execution) or runs long, and you don’t want to host one. When I wouldn’t: the agent is already a 70-line script in a repo, which GitHub Actions runs for free.
Stream anything long
The starter makes a normal request and waits for the full answer. That’s right for a digest. When an agent writes long output (a full report, a long draft, a page rewrite) you’ll want a higher max_tokens, and a non-streaming request that large can hit the SDK’s HTTP timeout before the answer arrives. Stream it instead and collect the final message:
const stream = client.messages.stream({
model: 'claude-opus-5-5',
max_tokens: 64000,
system: systemPrompt,
tools,
messages,
});
stream.on('text', (delta) => process.stdout.write(delta)); // optional: watch it write
const res = await stream.finalMessage(); // the same Message the loop already handlesfinalMessage() returns exactly what messages.create did, so the stop_reason switch from Module 02 doesn’t change. For a conversational agent, streaming is also the biggest latency win (Module 06): the human sees words in a second instead of a spinner for twenty.
Observability: see what it did
Module 06 gave you a one-line log per run with tokens, cache reads, turns, stop reason and cost. In production, put that line where you’ll see it:
- A Slack channel per fleet, one message per run. Cheapest, and you’ll actually read it.
- The Anthropic Console’s usage and cost pages for the account-level view: which key, which model, which day. Compare it against your own logs once a month; if they disagree, a run isn’t logging.
- On Managed Agents, the Console’s session viewer shows every session’s full event history with no setup.
- OpenTelemetry, if you already run an observability backend: the SDK can emit traces for each call. Don’t set one up just for this; a log line in Slack does the job until you have dozens of agents.
The two numbers to watch week over week are cost per run and cache_read_input_tokens. A jump in the first or a drop to zero in the second means something changed in the prompt, the tools or the input, and the logs tell you which run it started on.
MCP servers in production
Module 04 covered MCP servers as tools. In production the rule is reuse: as your tools get real (Airtable, Slack, your calendar, a booking system), stop hand-writing every integration in every agent’s tools.ts. Connect each service once as an MCP server — config in Claude Code and Cowork, the MCP connector on the API, or attached to the agent on Managed Agents — and point every agent that needs it at the same server. MCP servers are the USB ports; your agents are the devices. Each agent still gets only the tools it needs, with a token scoped to match.
Iterate: the loop after launch
Shipping isn’t the end; it’s the start of the iterate loop. The discipline that keeps agents healthy:
1. Watch the first runs like a hawk. The first week, read every output. This is when you discover the inputs you didn’t anticipate. Each surprise becomes a new eval (Module 04) and usually a new prompt rule (Module 05).
2. Every real failure becomes a test. The agent does something dumb? Don’t just fix the prompt — add the failing case to evals/run.ts first, watch it go red, then fix until green. Now it can never regress. Over months, your eval suite becomes the agent’s accumulated wisdom.
3. Keep a kill switch. One environment variable (AGENT_ENABLED=false) that makes the agent no-op. When something’s wrong at 2am, you want to disable it in one click without deleting the schedule or redeploying. (On Managed Agents, pausing the deployment is the kill switch.)
if (process.env.AGENT_ENABLED === 'false') {
console.log('Agent disabled via kill switch. Exiting.');
process.exit(0);
}4. Promote trust gradually. New agents run in DRY_RUN (print what they’d do) for days. Then human-gated (draft, you approve). Then, for low-stakes ones, autonomous. Don’t go from “wrote it” to “auto-sending to customers” in one step. Earn the autonomy.
5. Pin the model, then upgrade on purpose. Your code names an exact model ID, so a new model doesn’t change your agent until you change that line. When one ships, switch it on a branch, run the evals, compare cost per run in the logs, and only then merge. Model upgrades are prompt changes in disguise: a newer model can follow your prompt more literally than the old one did (Module 05).
6. Review the fleet weekly. Costs drifting? Error or refusal rates up? An agent that hasn’t run because cron silently broke? A five-minute weekly scan catches rot before it’s a problem. (Mine is — naturally — partly automated by the weekly recap agent.)
The whole deploy, in one breath
Push repo to GitHub. Secrets in the platform’s secret store. Scheduled agent → Actions cron with workflow_dispatch, a timeout, and evals-as-gate, or a Managed Agents deployment if you don’t want to host it. Event agent → Cloudflare Pages Function with signature verify and async ack. Kill switch and DRY_RUN env vars for safety. Stream long outputs. One log line per run to Slack. That’s production. No servers, no ops team, no 3am pages — because the boring infrastructure is doing exactly what boring infrastructure is supposed to: nothing you have to think about.
Hands-on lab
Deploy your agent for real.
Step 1 — Push & secret. Get your hardened agent repo on GitHub. Put your API key and any webhook URLs in repo Actions secrets. Confirm nothing sensitive is committed in code.
Step 2 — Deploy by shape. If scheduled/polling: add the agent.yml workflow with cron, workflow_dispatch, timeout-minutes, and the evals-before-agent step — or, if you chose Managed Agents, create the agent, environment and deployment and check upcoming_runs_at. If event-triggered: deploy a Cloudflare Pages Function with signature verification and the async-ack pattern, and point a test webhook at it.
Step 3 — Trigger it manually. Use workflow_dispatch (Actions), a manual deployment run (Managed Agents), or send a test event (Cloudflare). Watch the logs. It must run green start to finish, with DRY_RUN still on.
Step 4 — Add the safety rails. Wire in the AGENT_ENABLED kill switch and confirm the one-line structured log (Module 06), cache reads included, shows up in your Slack channel.
Step 5 — Let it run live, gated. Flip DRY_RUN=false only when you’ve watched enough dry runs to trust it. For customer-facing agents, keep the human gate. Let the trigger fire on its own for the first time. The moment you get a Slack message from an agent you deployed and then walked away from — that’s the whole course paying off.
Deliverable: one agent, deployed, running on a trigger without you, with evals as a deploy gate, a kill switch, and live monitoring. You are now running a production agent. Next module: thirty more of them — every agent I run, opened up, so you can steal the patterns whole.