Session
A first-class conversation session.
Created by agent.session(). Holds conversation history and state
that persist across multiple turns. Turns execute sequentially.
Example
Section titled “Example”const session = agent.session()const r1 = await session.run("Hello").resultconst r2 = await session.run("Follow up").resultawait session.close()Properties
Section titled “Properties”history
Section titled “history”
readonlyhistory:Message[]
Flat chronological conversation history, auto-accumulates across turns.
readonlyid:string
Unique session identifier.
readonlystate:Record<string,unknown>
Session state — read-only for client code. Middleware writes via ctx.state.
Methods
Section titled “Methods”[asyncDispose]()
Section titled “[asyncDispose]()”[asyncDispose]():
Promise<void>
Alias for close() — enables await using session = agent.session().
Returns
Section titled “Returns”Promise<void>
close()
Section titled “close()”close():
Promise<void>
Close the session, triggering session-level middleware cleanup. Idempotent — safe to call multiple times.
Returns
Section titled “Returns”Promise<void>
run(
input,opts?):AgentRun
Execute a single conversational turn.
Returns an AgentRun with dual interface: async iterable for streaming,
.result Promise for the final RunResult.
Parameters
Section titled “Parameters”string
User message text
Optional run options (e.g., output schema)
Returns
Section titled “Returns”Throws
Section titled “Throws”If the session has been closed
Throws
Section titled “Throws”If a turn is already in progress