Creating ephemeral (stateless) agents in a TypeScript Golem project. Use when the user wants a stateless agent, a fresh instance per invocation, no shared state between calls, or a request-handler style agent.
An ephemeral agent is a Golem agent that gets a fresh instance for every invocation. Unlike the default durable agents, ephemeral agents:
golem agent oplog), but it is never used for replay — no automatic recovery on failureThis makes ephemeral agents ideal for pure request handlers, stateless transformers, adapters, and serverless-style functions where each call is independent.
Pass { mode: "ephemeral" } to the @agent() decorator:
import { BaseAgent, agent } from '@golemcloud/golem-ts-sdk';
@agent({ mode: "ephemeral" })
class RequestHandler extends BaseAgent {
async handle(input: string): Promise<string> {
return `processed: ${input}`;
}
}
Consider a durable agent vs an ephemeral one:
// DURABLE (default) — state accumulates across calls
@agent()
class DurableCounter extends BaseAgent {
private count: number = 0;
async increment(): Promise<number> {
this.count += 1;
return this.count;
}
}
// Call increment() three times → returns 1, 2, 3
// EPHEMERAL — state resets every call
@agent({ mode: "ephemeral" })
class EphemeralCounter extends BaseAgent {
private count: number = 0;
async increment(): Promise<number> {
this.count += 1;
return this.count;
}
}
// Call increment() three times → returns 1, 1, 1
Each invocation of an ephemeral agent:
Ephemeral agents are a natural fit for HTTP request handlers:
import { BaseAgent, agent, post, body } from '@golemcloud/golem-ts-sdk';
@agent({ mode: "ephemeral", mount: "/api/convert/{name}" })
class ConverterAgent extends BaseAgent {
private readonly name: string;
constructor(name: string) {
super();
this.name = name;
}
@post("/to-upper")
async toUpper(@body() input: string): Promise<string> {
return input.toUpperCase();
}
@post("/to-lower")
async toLower(@body() input: string): Promise<string> {
return input.toLowerCase();
}
}
| Use Case | Why Ephemeral? |
|---|---|
| Stateless HTTP API (REST adapter, proxy) | No state to persist between requests |
| Data transformation / format conversion | Pure function — input in, output out |
| Validation service | Each validation is independent |
| Webhook receiver that forwards events | No need to remember previous webhooks |
| Stateless computation (math, encoding) | No side effects worth persisting |
golem agent oplog — but it is never replayed