One turn, end to end
For a call such as:Agent performs the following sequence.
1. Append the goal
The goal is linked to the previous frontier. On the first turn, the runtime also creates the system contract.2. Compile working context
The compiler begins with mandatory state:- latest system and goal;
- every frontier head;
- current resource heads;
- ten recent non-superseded nodes;
- up to two levels of operational parents.
3. Call the model
The provider receives:input.prompt: the compiled causal view;input.system: the action protocol and tool descriptions;- an abort signal;
- provider parameters from the adapter.
4. Record the inference
Before executing an action, the runtime appends aninference node. Its parents are exactly the IDs emitted by the compiler in step 2.
5. Execute or retry
For a tool action, StateWeave:- validates the tool name and Zod schema;
- records
tool_call; - executes the tool;
- records
tool_result; - extracts resource or verification evidence when the result exposes it;
- compiles the next causal view.
protocol_error and the loop continues. Tool failures remain evidence for the next inference.
When completion evidence is enabled, unsupported coding-task finals are rejected until the graph contains the required inspection, mutation, restart, or verification evidence.
6. Commit transactionally
A successful final appendsanswer, produces AgentRunResult, and replaces the agent’s committed state.
A failed or aborted run throws AgentRunError. Its diagnostic state, graph, trace, and metrics remain available on the error, but the stateful agent keeps the previous successful state.
Concurrent stateful calls are serialized in invocation order. Passing options.state runs against that explicit snapshot without mutating the agent-owned session.
Commit rule
Successful runs advance session state. Failed and aborted runs do not.
Limits are behavior
See AgentState for the data model and Agent reference for exact runtime options.