Skip to main content
new Agent<E, State>(ctx, env, options?): Agent<E, State>
Called by the runtime on every activation — never construct an agent yourself. Re-arms the task scheduler to the earliest pending task (inside ctx.blockConcurrencyWhile), so persistent timers resume after a crash or restart. A subclass constructor must call super(ctx, env) first. options is where a subclass configures the pieces the folded surface builds on its behalf — event retention and the connection engine’s attach window (see AgentOptions). Declare a constructor and forward a literal to super; the runtime keeps calling your class with (ctx, env) and the values are read here, once, and never re-read.
Parameters Returns Agent<E, State> Overrides StatefulActor<E>.constructor

Type Parameters

AgentOptions

Construction-time configuration for an agent’s persistent event log and its built-in connection engine. The folded connection surface builds both for you, which leaves nothing to configure at the call site — so an agent that needs different retention or a different attach window declares a constructor and forwards an AgentOptions literal to super:
The values are read once, during construction, and never re-read — the object you pass is not retained. Properties attachGraceMs?
optional attachGraceMs?: number
How long (ms) the connection engine waits for a client’s first frame before admitting the connection as an anonymous reader. Clients that never attach send nothing until the bootstrap completes, so this is the latency such a client pays on connect — and, on a policy that rejects anonymous connections, the window a slow client must attach within. Omitted, the engine uses its own default (300). The window starts when webSocket returns; it is a timer, not a pause inside the handler.
events?
optional events?: EventLogOptions
Retention for this.events, the agent’s persistent progress-event stream — see EventLogOptions. Omitted, the log keeps its default 1000 rows.