Deploying Agents to Production

Published: February 3, 2026

Tags: deployment, production, infrastructure, devops

Author: ClawParts Team

Introduction

Your agent works perfectly on your laptop. It has access to your local files, your environment variables are set, and you can watch the logs scroll by. But laptops aren't always on, they don't have static IPs, and they can't scale. To make your agent truly useful, you need to deploy it to production.

Production deployment is where many agent projects fail. The transition from local development to production infrastructure introduces new failure modes: network timeouts, permission errors, missing dependencies, and configuration mismatches. The agent that worked perfectly locally fails mysteriously in production.

This guide covers practical deployment strategies for AI agents, from simple serverless functions to container orchestration.

Infrastructure Choices

Before deploying, choose the right infrastructure for your workload.

Cloudflare Workers (Edge Deployment)

Cloudflare Workers run at the edge — close to users worldwide. They're ideal for agents that:

- Respond to HTTP requests

- Need global low latency

- Have variable traffic

- Don't need persistent local state

Pros:

- Deploy globally in seconds

- Scale automatically

- Pay only for usage

- No server management

Cons:

- Limited execution time (30s-5min depending on plan)

- No persistent local filesystem

- Limited memory (128MB-1GB)

Best for: API endpoints, webhooks, lightweight agents

// worker.js

export default {

async fetch(request, env, ctx) {

// Agent logic here

const result = await agent.process(request);

return new Response(JSON.stringify(result), {

headers: { 'Content-Type': 'application/json' }

});

}

};

VPS/VM (Traditional)

Virtual private servers provide full control. They're ideal for agents that:

- Run continuously (not just on requests)

- Need persistent local storage

- Have long-running tasks

- Require specific software

Pros:

- Full control over environment

- Persistent storage

- Long-running processes

- Predictable costs

Cons:

- Manual scaling

- Server management overhead

- Single point of failure

Best for: Always-on agents, complex workloads, development

Deploy to VPS

scp -r ./agent user@server:/opt/agent

ssh user@server "cd /opt/agent && npm install && pm2 start index.js"

Container Orchestration

Docker containers provide consistency across environments. Orchestration platforms (Kubernetes, ECS, Fly.io) manage them at scale.

Pros:

- Consistent environment (dev = staging = production)

- Easy scaling

- Health checks and auto-restart

- Rolling deployments

Cons:

- Complex to set up

- Overkill for simple agents

- Cost can be higher

Best for: Multi-agent systems, enterprise deployments, complex dependencies

Dockerfile

FROM node:18-alpine

WORKDIR /app

COPY package*.json ./

RUN npm ci --only=production

COPY . .

USER node

CMD ["node", "index.js"]

Serverless Functions

AWS Lambda, Google Cloud Functions, and Azure Functions provide event-driven execution.

Pros:

- True pay-per-use (zero cost when idle)

- Automatic scaling

- No server management

- Integrated with cloud services

Cons:

- Cold start latency

- Execution time limits

- Vendor lock-in

- Debugging can be harder

Best for: Event-driven agents, sporadic workloads, cloud-native stacks

// AWS Lambda handler

exports.handler = async (event, context) => {

const result = await agent.process(event);

return {

statusCode: 200,

body: JSON.stringify(result)

};

};

Configuration Management

Production configuration differs from development. Manage it properly.

Environment-Specific Configs

// config.js

const configs = {

development: {

model: 'gpt-4o-mini',

heartbeatInterval: 60000, // 1 minute for testing

logLevel: 'debug',

database: 'sqlite://./dev.db'

},

staging: {

model: 'gpt-4o',

heartbeatInterval: 300000, // 5 minutes

logLevel: 'info',

database: process.env.STAGING_DATABASE_URL

},

production: {

model: 'gpt-4o',

heartbeatInterval: 900000, // 15 minutes

logLevel: 'warn',

database: process.env.PRODUCTION_DATABASE_URL

}

};

const config = configs[process.env.NODE_ENV || 'development'];

module.exports = config;

Feature Flags

Control features without redeploying:

const features = {

newParser: process.env.ENABLE_NEW_PARSER === 'true',

cacheEnabled: process.env.ENABLE_CACHE !== 'false',

verboseLogging: process.env.VERBOSE_LOGS === 'true'

};

// Usage

if (features.newParser) {

result = await newParser.parse(input);

} else {

result = await oldParser.parse(input);

}

Secrets Management

Don't commit secrets. Use environment variables or secret managers:

// BAD — committed to git

const API_KEY = 'sk-abc123...';

// GOOD — from environment

const API_KEY = process.env.OPENAI_API_KEY;

if (!API_KEY) {

throw new Error('OPENAI_API_KEY not set');

}

For production, use secret managers:

// AWS Secrets Manager

const AWS = require('aws-sdk');

const secrets = new AWS.SecretsManager();

const { apiKey } = await secrets.getSecretValue({

SecretId: 'production/agent-api-key'

}).promise();

Monitoring and Alerting

Production agents need monitoring. You can't watch logs 24/7.

Health Checks

Implement health check endpoints:

// health.js

async function healthCheck() {

const checks = await Promise.all([

checkDatabase(),

checkApiKeys(),

checkDiskSpace(),

checkMemory()

]);

const healthy = checks.every(c => c.healthy);

return {

status: healthy ? 200 : 503,

body: {

status: healthy ? 'healthy' : 'unhealthy',

checks: checks.reduce((acc, check) => ({

...acc,

[check.name]: check

}), {}),

timestamp: new Date().toISOString()

}

};

}

// Express route

app.get('/health', async (req, res) => {

const health = await healthCheck();

res.status(health.status).json(health.body);

});

Error Tracking

Use structured logging and error tracking:

// logger.js

class ProductionLogger {

error(error, context = {}) {

const logEntry = {

level: 'error',

message: error.message,

stack: error.stack,

context,

timestamp: new Date().toISOString(),

session: this.sessionKey,

environment: process.env.NODE_ENV

};

// Send to error tracking service

if (process.env.NODE_ENV === 'production') {

sentry.captureException(error, { extra: context });

}

console.error(JSON.stringify(logEntry));

}

info(message, meta = {}) {

console.log(JSON.stringify({

level: 'info',

message,

...meta,

timestamp: new Date().toISOString()

}));

}

}

Performance Monitoring

Track what matters:

class PerformanceMonitor {

record(metric, value, tags = {}) {

// Send to metrics service

datadog.gauge(agent.${metric}, value, tags);

// Log for debugging

console.log(JSON.stringify({

type: 'metric',

metric,

value,

tags,

timestamp: Date.now()

}));

}

async timeOperation(name, operation) {

const start = Date.now();

try {

const result = await operation();

this.record(${name}.duration, Date.now() - start, { status: 'success' });

return result;

} catch (error) {

this.record(${name}.duration, Date.now() - start, { status: 'error' });

throw error;

}

}

}

Cost Monitoring

Track API costs:

class CostMonitor {

constructor() {

this.dailyCost = 0;

this.budget = 50; // $50/day budget

}

track(model, inputTokens, outputTokens) {

const rates = {

'gpt-4o': { input: 0.0025, output: 0.01 },

'gpt-4o-mini': { input: 0.00015, output: 0.0006 }

};

const rate = rates[model];

const cost = (inputTokens / 1000 * rate.input) +

(outputTokens / 1000 * rate.output);

this.dailyCost += cost;

// Alert at 80% of budget

if (this.dailyCost > this.budget * 0.8) {

console.warn(Cost alert: $${this.dailyCost.toFixed(2)} / $${this.budget});

}

return cost;

}

}

Rollback Strategies

When deployments fail, roll back quickly.

Versioning Deployments

Tag every deployment:

Version tagging

git tag -a "v1.2.3" -m "Deploy: Add notification system"

git push origin v1.2.3

Blue/Green Deployment

Keep two environments:

Blue (current) ←→ Green (new)

Deploy to green, test, then switch traffic:

Deploy to green

wrangler deploy --env green

Test green

curl https://green.clawparts.com/health

Switch traffic

dns switch clawparts.com → green

If problems, switch back

dns switch clawparts.com → blue

Feature Flags for Safety

Deploy features disabled, enable gradually:

const features = {

newHeartbeat: process.env.ENABLE_NEW_HEARTBEAT === 'true',

cacheLayer: process.env.ENABLE_CACHE === 'true'

};

// Deploy with features off

// Monitor

// Gradually enable: ENABLE_NEW_HEARTBEAT=true for 10% of traffic

Quick Rollback

Have rollback ready:

Rollback script

#!/bin/bash

VERSION=$1

echo "Rolling back to $VERSION..."

git checkout $VERSION

wrangler deploy --force

echo "Rollback complete"

Deployment Checklist

Before deploying:

- [ ] Environment variables set

- [ ] Secrets in secret manager (not code)

- [ ] Health check endpoint working

- [ ] Error tracking configured

- [ ] Logs going to centralized system

- [ ] Rollback plan documented

- [ ] Database migrations ready (if applicable)

- [ ] SSL/TLS configured

- [ ] Rate limiting enabled

- [ ] Cost alerts configured

Conclusion

Deploying agents to production requires attention to infrastructure, configuration, monitoring, and safety.

Key principles:

1. Choose right infrastructure — match to your workload

2. Manage configuration — environment-specific, feature flags

3. Monitor everything — health, errors, performance, costs

4. Plan for failure — rollback strategies, feature flags

Start simple. A single Cloudflare Worker or VPS is enough for many agents. Add complexity only when needed.

The agents that run reliably in production aren't those with the most sophisticated infrastructure — they're those with thoughtful deployment practices and comprehensive monitoring.

---

Related Articles:

- Testing and Debugging Agent Systems

- Security Best Practices for AI Agents

- Rate Limiting and Cost Optimization for Agents

Word Count: 1,245 words

Was this helpful?

Score: 0

No account required. One vote per person (tracked by cookie).

← Back to Blog