Skip to content
AgentField
Deploy

Serverless Deployment

Deploy agents as serverless functions with handle_serverless(), Lambda adapters, and scale-to-zero.

Serverless deployment — same Agent, serverless runtime

Deploy agents as Lambda functions, Cloud Functions, or edge handlers while keeping the same agent logic.

Not every agent needs a long-running server. For event-driven workloads, batch processing, or cost-sensitive deployments, AgentField agents can run as serverless functions. Python's handle_serverless(event), TypeScript's handler(), and Go's Handler() wrap your agent so it works with AWS Lambda, Google Cloud Functions, Azure Functions, Vercel, and any platform that speaks HTTP.

from agentfield import Agent, AIConfig
from pydantic import BaseModel

app = Agent(
    node_id="invoice-processor",
    ai_config=AIConfig(model="openai/gpt-4o-mini"),
)

class InvoiceInput(BaseModel):
    document_url: str
    vendor: str

class InvoiceOutput(BaseModel):
    total: float
    line_items: list[dict]
    due_date: str
    confidence: float

@app.reasoner()
async def process_invoice(document_url: str, vendor: str) -> dict:
    result = await app.ai(
        system="Extract structured invoice data.",
        user=f"Vendor: {vendor}, Document: {document_url}",
        schema=InvoiceOutput,
    )
    return result

# Lambda handler — pass the event directly
def handler(event, context):
    return app.handle_serverless(event)
import { Agent } from "@agentfield/sdk";
import { z } from "zod";

const agent = new Agent({ nodeId: "invoice-processor" });

const InvoiceInput = z.object({
  documentUrl: z.string().url(),
  vendor: z.string(),
});

const InvoiceOutput = z.object({
  total: z.number(),
  lineItems: z.array(z.record(z.any())),
  dueDate: z.string(),
  confidence: z.number(),
});

agent.reasoner("processInvoice", async (ctx) => {
  const input = InvoiceInput.parse(ctx.input);
  return await ctx.ai(`Vendor: ${input.vendor}, Doc: ${input.documentUrl}`, {
    system: "Extract structured invoice data.",
    schema: InvoiceOutput,
  });
});

// Serverless handler — works with Lambda, Cloud Functions, Vercel, etc.
export default agent.handler();
package main

import (
    "context"
    "log"
    "net/http"

    "github.com/Agent-Field/agentfield/sdk/go/agent"
)

type InvoiceInput struct {
    DocumentURL string `json:"document_url"`
    Vendor      string `json:"vendor"`
}

type InvoiceOutput struct {
    Total      float64          `json:"total"`
    LineItems  []map[string]any `json:"line_items"`
    DueDate    string           `json:"due_date"`
    Confidence float64          `json:"confidence"`
}

func main() {
    a, err := agent.New(agent.Config{
        NodeID:         "invoice-processor",
        Version:        "1.0.0",
        DeploymentType: "serverless",
    })
    if err != nil {
        log.Fatal(err)
    }

    a.RegisterReasoner("processInvoice", func(ctx context.Context, input map[string]any) (any, error) {
        // Process invoice...
        return InvoiceOutput{
            Total:      1250.00,
            DueDate:    "2026-04-15",
            Confidence: 0.95,
        }, nil
    })

    // Expose as an http.Handler when your serverless platform accepts HTTP handlers directly.
    http.ListenAndServe(":8001", a.Handler())
}

What just happened

The same agent definition was exposed as a serverless handler without rewriting the business logic. You keep the same reasoners and schemas, then swap only the runtime boundary.

{
  "deployment_shape": "serverless",
  "entrypoint": "handle_serverless / handler",
  "cold_start_behavior": "runtime-dependent",
  "scale_model": "scale_to_zero"
}