Build the product boundary

StateWeave keeps state in memory while an Agent instance lives. Durable storage, authorization, and reconnect behavior belong to your application.

Save after success

Use optimistic concurrency or one session worker when several requests can update the same state. A stateful Agent serializes calls inside one process, not across replicas.

Browser-owned state

A browser may own AgentState, but the server must treat uploaded state as untrusted:
  1. enforce a byte limit before parsing;
  2. construct Agent to validate identities and causal ordering;
  3. authorize any application-level session envelope;
  4. never let browser state choose server tools or provider credentials;
  5. return the new state only after a successful run.
Browser storage is readable by anyone with access to that browser profile. Do not store sensitive evidence there without an explicit product security model.

Stream engine events

streamEvents() exposes causal progress. It does not stream provider tokens from the public Agent loop.
Progress phases are 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.
Traces are more sensitive than the graph view. Each step can contain the exact provider prompt and raw model output. Restrict trace access and retention accordingly.

Handle aborted and failed runs

Closing a 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.