run() or stream() uses a fresh server session. Use
createSession() for explicit multi-turn state.
Example
Constructors
Constructor
Parameters
options?
AgentOptions
Facade, runtime, and connection options.
Returns
Agent
Throws
When options conflict, a model id is malformed, or runtime config is unsupported.Example
Methods
client()
Returns
Promise<AgentClient>
The current low-level client.
Throws
When the Agent is closed or client creation fails.Example
close()
shutdown(), and injected clients are never closed.
Concurrent calls share one teardown promise.
Returns
Promise<void>
A promise that settles after all owned resources are handled.
Throws
When teardown fails; multiple failures are combined in anAggregateError.
Example
createSession()
Parameters
options?
AgentSessionOptions
Flat session-create overrides. Turn cancellation is not accepted here.
Returns
Promise<Session>
A caller-managed Session also owned by this Agent.
Throws
When the Agent is closed or creation fails.Example
fork()
cwd or
directory is therefore rejected.
Parameters
sessionId
string
Source session id.
options?
Optional source message boundary.messageId?
string
Returns
Promise<Session>
The configured fork Session.
Throws
On a cwd override, ownership conflict, or fork/configuration failure.Example
resume()
Parameters
sessionId
string
Existing session id on this Agent’s server.
Returns
Promise<Session>
A live Session owned by this Agent.
Throws
On unsupported resume fields, ownership conflict, or missing session.Example
run()
isError:true; setup and transport
failures reject.
Parameters
prompt
PromptInput
One prompt or an asynchronous sequence of turns.
options?
RunOptions
Flat per-run overrides.
Returns
Promise<RunResult>
The final turn result with required text and isError.
Throws
When the Agent is closed or setup/transport fails.Example
stream()
next(),
sessionId(), or control call. Early loop exit invokes return(); call
close() explicitly when abandoning a handle outside a loop.
Parameters
prompt
PromptInput
One prompt or an asynchronous sequence of turns.
options?
AgentStreamOptions
Stream and per-run overrides.
Returns
AgentStream
A synchronous async-iterator handle with session controls.