Agent

The single public class, backed by Causal Weave v3.

Constructor

tools: [] disables tools. Omitting tools creates the default workspace tools.

run()

TaskInput is a string or { input, objective? }. A stateful agent serializes concurrent calls. Successful runs update its state.
Passing options.state runs against that snapshot without mutating the agent-owned session.

streamEvents()

Emits metadata first, then model token/metadata events as available, zero or more progress events, and one final. Closing early aborts the run. Errors are thrown by the iterator.

stream() and streamText()

Both yield the accepted final answer as one string. They do not yield partial protocol text; use streamEvents() for provider token events.

getState()

A structured clone of committed state. undefined before the first success unless initial state was supplied.

getGraph()

A visualization view. Not the lossless persistence format.

reset()

No argument clears state. A snapshot validates and replaces it. A generation guard stops an older in-flight run from overwriting a later reset.

Result

Metadata reports run identity, engine, tools, limits, semantic config, timing, step count, and token totals.

AgentRunError

These describe the failed run. They do not replace the last successful commit. Invalid configuration and an impossible prompt budget fail before a provider call; a runtime failure after work has started exposes diagnostic state through this error. Next: Types and exports.