Intelligence · class

AgentSession

One agent: a floor that always runs, and one slot holding what comes next.

Explained in Agents and behaviour.

class AgentSession<W = unknown>
import { AgentSession } from '@driftengine/ai';

In depth

The current slot is never empty. When an intent finishes, the buffer drains into it; when the buffer is empty, the policy floor supplies. An agent with no provider configured behaves exactly as one whose provider is slow — less cleverly, and without ever standing still.

tick is the whole surface a consumer needs inside its fixed step. It returns the intent to execute and never returns null.

Constructor

new

constructor(options: AgentSessionOptions<W>)
ParameterTypeDescription
optionsAgentSessionOptions<W>

Properties

NameTypeDescription
agentIdreadonlystring

Accessors

NameTypeDescription
stategetAgentState
currentgetIntent | nullNever null once tick has run once.
bufferedgetIntent | null
usagegetReadonly<AiUsage>
degradedgetbooleanTrue once a budget is exhausted: still moving, no longer asking.
degradedReasongetstringThe budget's own sentence, or empty while nothing is exhausted.
discardedIntentsgetnumberBuffered intents discarded because their guard had gone false.
leadMsgetnumberThe lead the watermark uses: the provider's measured p90, or -1 before it knows.

Methods

observe

observe(observation: Observation): void

Something happened that the agent may care about.

ParameterTypeDescription
observationObservation
More

Never acted on here — an observation taken mid-tick would mutate the simulation halfway through a step. It waits for the next tick.

tick

tick(tickNumber: number, nowMs: number): Intent

Advance one fixed step and return the intent to execute.

ParameterTypeDescription
tickNumbernumber
nowMsnumber
More

Never returns null. That is the track's whole claim and it is asserted directly.

complete

complete(nowMs: number): void

The consumer says the current intent is over, ahead of its expected extent.

ParameterTypeDescription
nowMsnumber

dispose

dispose(reason?: string): void
ParameterTypeDescription
reason?string