Build the product boundary
StateWeave keeps state in memory while anAgent instance lives. Durable storage, authorization, and reconnect behavior belong to your application.
Save after success
Agent serializes calls inside one process, not across replicas.
Browser-owned state
A browser may ownAgentState, but the server must treat uploaded state as untrusted:
- enforce a byte limit before parsing;
- construct
Agentto validate identities and causal ordering; - authorize any application-level session envelope;
- never let browser state choose server tools or provider credentials;
- return the new state only after a successful run.
Stream engine events
streamEvents() exposes causal progress. It does not stream provider tokens from the public Agent loop.
context, model, tool, retrying, and final. Events may include the exact compiled prompt, selected state, visualization graph, raw model output, action, tool name, or protocol error.
stream() and streamText() are convenience iterables that yield the accepted final answer as one value:
Inspect without exposing everything
getGraph() maps causal nodes into consumer-safe graph nodes and edges. Large display text is truncated; AgentState is unchanged.
Handle aborted and failed runs
streamEvents() consumer aborts its run. A failed run’s diagnostic graph can explain what happened, but do not persist it as the canonical session unless your product deliberately models failed attempts.
Persist traces only when needed
traceDir writes successful run results as JSON. In hosted products, prefer an access-controlled event store with explicit retention instead of a shared local directory.