Skip to content

Event types

View as Markdown

A run reports its progress as weft.Event values: agt.Stream yields them from Events(), and a weft.Tap sees the same values in the same order. This page lists the eleven event types, every field with its JSON name, and the rules that order a stream. Signatures stay on pkg.go.dev; how to consume a stream is in Stream a run’s events.

In the order a run emits them:

EventWire typeSeqEmitted when
RunStartrun_start—First event of every run
StepStartstep_start—The model is being called for a step
ReasoningDeltareasoning_delta—An increment of provider reasoning
TextDeltatext_delta—An increment of assistant text
ToolArgsDeltatool_args_delta—The model is still writing a tool call
ToolStarttool_start✓A tool call began
Nestednested✓One event of a subagent’s child run
ToolFinishtool_finish✓A tool call completed, successfully or not
StepFinishstep_finish—The step’s model call and its tools are done
Steeredsteered✓The run’s steering source delivered messages
RunFinishrun_finish—Last event of a successful run

Every event except RunStart also carries RunID (run_id). A failed run has no RunFinish: its error is the last element Events() yields.

weft.Event is a sealed interface: the eleven types above implement it, and no type outside the package can. New event types may be added in later releases, additively, so a switch over events stays exhaustive and lintable. The type is an alias of core.Event (facade.go).

PropertyRule
DiscriminatorOn the wire every event is one JSON object with a type field (table above); field names are snake_case
RunIDOn every event except RunStart, whose id is the run’s own. Concurrent runs on one agent interleave, and Seq is unique only within a run, so RunID attributes an event to its run. Added in 0.2.0: older recordings decode with an empty RunID
SnapshotsAn event’s fields, including the Args byte slices and RunFinish.Pending, do not alias the run’s transcript. You may keep an event or write into it without changing the run (0.2.0)
CompatibilityAdditive only: a field is added, never renamed or removed. An unknown type is an error when decoding, never a silent drop (ADR 0004)

The loop guarantees these orders; tests pin them (ADR 0004, rules 3 and 4).

RuleWhat holds
First and lastRunStart is first in every run; RunFinish is last in a successful run
One counterToolStart, ToolFinish, Nested and Steered take Seq from one per-run counter, assigned and emitted under one lock: the order you observe is the order of Seq
No Seq neededRunStart, StepStart, the three deltas, StepFinish and RunFinish come from the loop’s one goroutine, ordered by construction
Call orderToolStart events arrive in call order under any parallelism; pair a ToolFinish with its ToolStart by CallID
Start before finishEvery ToolFinish follows its call’s ToolStart. A call cancelled before it got a slot emits neither
Parked callsA call parked at the approval boundary has a ToolStart and no ToolFinish; it is listed on RunFinish.Pending
Resumed callsCalls resumed with weft.Approve emit ToolStart and ToolFinish in the resuming run, before its first StepStart. Denied and resolved calls emit no tool events: their result joins the transcript directly
Truncated stepA step that finished max_tokens with tool calls emits no tool events: none of the calls ran
Arguments firstEvery ToolArgsDelta precedes the ToolStart of the call it belongs to
Step endStepFinish follows the step’s ToolFinish events and precedes the stop-condition check
SteeringSteered sits between a step’s StepFinish and the next StepStart
Children inside the callA child run’s RunStart to RunFinish arrive, wrapped in Nested, inside the parent’s ToolStart…ToolFinish for the delegating call; none arrive after that ToolFinish
CancellationOnce the run’s context is cancelled, nothing more is delivered, to Events() or to taps. The partial transcript on RunError.Result is the record

A run with two tool calls in one step, the second a subagent, emits the stream below. The first tool, echo, is marked weft.Sequential(), a barrier, so it runs alone and finishes before the subagent starts; without it the two calls run in parallel and their events interleave in an order that can change from run to run (Seq still numbers whatever order occurred). The parent agent has weft.Instructions("Be terse.") and the child has none, which gives the two instructions_hash values. Each line is json.Marshal of one event; latency_ms and ttft_ms are measured and vary:

{"type":"run_start","id":"r1","model":{"provider":"wefttest","name":"script"},"agent":"parent","instructions_hash":"28c7339ead79c720e67160d2f681384ad23a59bf8514c3c2e01d09a4d701441f"}
{"type":"step_start","run_id":"r1","index":0}
{"type":"tool_start","run_id":"r1","seq":1,"call_id":"c1","name":"echo","args":{"q":"x"}}
{"type":"tool_finish","run_id":"r1","seq":2,"call_id":"c1","name":"echo","content":"x","is_error":false}
{"type":"tool_start","run_id":"r1","seq":3,"call_id":"c2","name":"research","args":{"prompt":"go"}}
{"type":"nested","run_id":"r1","seq":4,"call_id":"c2","event":{"type":"run_start","id":"r1/0/c2","model":{"provider":"wefttest","name":"script"},"agent":"child","instructions_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}}
{"type":"nested","run_id":"r1","seq":5,"call_id":"c2","event":{"type":"step_start","run_id":"r1/0/c2","index":0}}
{"type":"nested","run_id":"r1","seq":6,"call_id":"c2","event":{"type":"text_delta","run_id":"r1/0/c2","text":"child done"}}
{"type":"nested","run_id":"r1","seq":7,"call_id":"c2","event":{"type":"step_finish","run_id":"r1/0/c2","index":0,"reason":"stop","usage":{"input_tokens":10,"output_tokens":5},"latency_ms":1,"ttft_ms":1}}
{"type":"nested","run_id":"r1","seq":8,"call_id":"c2","event":{"type":"run_finish","run_id":"r1/0/c2","usage":{"input_tokens":10,"output_tokens":5},"steps":1,"stopped_by":"final_answer"}}
{"type":"tool_finish","run_id":"r1","seq":9,"call_id":"c2","name":"research","content":"child done","is_error":false}
{"type":"step_finish","run_id":"r1","index":0,"reason":"tool_calls","usage":{"input_tokens":10,"output_tokens":5},"latency_ms":1}
{"type":"step_start","run_id":"r1","index":1}
{"type":"text_delta","run_id":"r1","text":"done"}
{"type":"step_finish","run_id":"r1","index":1,"reason":"stop","usage":{"input_tokens":10,"output_tokens":5},"latency_ms":1,"ttft_ms":1}
{"type":"run_finish","run_id":"r1","usage":{"input_tokens":30,"output_tokens":15},"steps":2,"stopped_by":"final_answer"}

The child’s events keep their own run_id (r1/0/c2: parent run, step, call) while the Nested envelope carries the parent’s run_id and seq. The parent’s step_finish reports its own model call’s usage; run_finish totals the run, the child’s usage included. The first step_finish has no ttft_ms: a scripted bare tool call yields no text or argument delta to time.

RunStart is always the first event of a run. It carries the run’s id and, when reported, the model’s identity and the agent’s name.

FieldTypeWireMeaning
IDstringidThe run’s id, the same as Run.ID() and RunResult.ID; set it with weft.RunID. A subagent’s child run is <parent>/<step>/<call>, or <parent>/resume/<call> for a call run under Approve
ModelModelInfomodel{provider, name} when the model implements Info() ModelInfo; the zero value otherwise
Agentstringagent, omitted when emptyThe agent’s weft.Name
InstructionsHashstringinstructions_hash, omitted when emptyLowercase hex sha256 of the run’s raw configured instructions: the agent’s Instructions or the run’s override, before PrepareStep and before PromptSnippets are composed in

The loop always sets InstructionsHash; a run with no instructions carries the hash of the empty string (e3b0c442… in the stream above). It is a hash, not content, so it survives weft.StripContent; an event built by hand may leave it empty. It was added in 0.10.0 and is mirrored as weft.instructions.hash on the run_start record and the invoke_agent span. The example ExampleRunStart_instructionsHash compares it with the sha256 of the configured prompt.

StepStart reports that the model is being called for a step.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
IndexintindexThe step’s index, from 0

ReasoningDelta is an increment of provider reasoning, in the order the model produced it relative to TextDelta. Signatures are not streamed: they are on the transcript’s ReasoningPart.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
TextstringtextThe reasoning text increment

TextDelta is an increment of assistant text.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
TextstringtextThe text increment

ToolArgsDelta reports an increment of a tool call’s arguments while the model is still writing the call. It is progress only: the call has not been made, and ToolStart still arrives when it executes. The OpenAI and Anthropic adapters stream argument fragments; Google’s calls arrive whole, so its runs emit none.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
NamestringnameThe best-known tool name so far; deltas of several calls interleave, told apart by name where the provider supplies one
ArgsstringargsA fragment of the arguments’ JSON, not a complete value

ToolStart reports that a tool invocation began. Events from tools running in parallel interleave: pair them by CallID and order them by Seq.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
Seqint64seqThe run’s event counter at emission
CallIDstringcall_idThe model’s id for the call; the matching ToolFinish carries the same
NamestringnameThe tool’s name
Argsjson.RawMessageargsThe call’s arguments as JSON. A nil Args marshals as null and decodes as json.RawMessage("null"); in a live run it is never nil

A parked call has a ToolStart and no ToolFinish.

Nested wraps one event of a child run started by a weft.Subagent tool. The envelope belongs to the parent run; the wrapped event belongs to the child.

FieldTypeWireMeaning
RunIDstringrun_idThe parent run’s id
Seqint64seqFrom the parent’s counter, so the parent stream stays totally ordered with the child’s events in place
CallIDstringcall_idThe parent’s tool call that owns the child run
EventEventeventAny child event, with its own RunID and Seq; a grandchild’s event is a Nested inside a Nested

Nested.UnmarshalJSON decodes the envelope and then the inner event through UnmarshalEvent, recursively; an unknown inner type fails as at the top level, wrapped as nested event: …. Usage a child reports after its call’s ToolFinish is dropped with its late events.

ToolFinish reports that a tool invocation completed, successfully or not.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
Seqint64seqThe run’s event counter at emission
CallIDstringcall_idThe call’s id, as on its ToolStart
NamestringnameThe tool’s name
ContentstringcontentThe tool’s output, or the failure text when IsError is set: the same value the model sees on the matching ToolResultPart
IsErrorboolis_errorThe call failed, for example: a handler error or a returned *weft.ToolError, a weft.ModelRetry (RETRY: result), a panic, a timeout, bad arguments or an unknown tool (tool errors are data)

StepFinish reports that a step is complete: the model call finished and, when it requested tools, they have run.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
IndexintindexThe step’s index, as on its StepStart
ReasonStopReasonreasonstop, tool_calls or max_tokens
UsageUsageusageThis step’s model call alone. Subagent usage rolls into RunResult.Usage and RunFinish.Usage, not here
Rawstringraw, omitted when emptyThe provider’s own stop reason when Reason was approximated; empty when the mapping was exact
LatencyMSint64latency_ms, omitted when 0From the start of the model chain’s Stream to the stream’s ModelFinish
TTFTMSint64ttft_ms, omitted when 0From the same start to the first TextDelta or ToolArgsDelta; reasoning does not count

LatencyMS and TTFTMS were added in 0.10.0. Both are whole milliseconds rounded up, so a measured interval is never 0, and 0 means not measured: a recording made before the fields existed, an event built by hand, or, for TTFTMS, a call that yielded no text and no argument delta. The timing spans the whole model chain, so a retry’s backoff and a fallback’s failed tries are inside it. Nothing in the loop reads them. Usage fields on the wire are input_tokens, output_tokens and, when non-zero, cached_input_tokens, cache_write_tokens and reasoning_tokens.

Steered reports messages the run’s steering source (weft.Steering) delivered at a step’s drain point: after the tool batch, or at a final step whose steer redirected the run into one more step.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
Seqint64seqThe run’s event counter at emission
StepintstepThe step whose drain point delivered the messages
Messages[]MessagemessagesThe delivered messages, role user, as a snapshot; the transcript holds its own copy

RunFinish is always the final event of a successful run, a parked one included.

FieldTypeWireMeaning
RunIDstringrun_idThe run this event belongs to
UsageUsageusageThe run’s total, subagent runs included
StepsintstepsThe number of steps the run took
Pending[]ToolCallPartpending, omitted when emptyMirrors RunResult.Pending: the calls the run ended on without executing, awaiting Approve, Deny or Resolve. Each had its ToolStart and no ToolFinish
StoppedBystringstopped_by, omitted when emptyWhat ended the run, in the manifest’s stop_when vocabulary (below)

StoppedBy values:

ValueThe run ended because
final_answerA step had no tool calls
parkedCalls are pending at the approval boundary
has_tool_call:<tool>weft.HasToolCall fired; several names are joined with commas (has_tool_call:a,b)
step_count_is:Nweft.StepCountIs(N) fired
output_submittedThe structured-output tool received a valid call (weft.Output)
a condition’s String()A custom StopCondition that implements fmt.Stringer fired
customA custom condition without a String() method fired

The value is configuration, never content. The run’s invoke_agent span carries the same value as weft.run.stopped_by; a failed run has no RunFinish, so on a failed run only the span names what stopped it (How does a run stop?).

A recorded stream decodes back into typed events with weft.UnmarshalEvent, one JSON object at a time. The package example ExampleUnmarshalEvent decodes a tool_start line and prints its name, call id, Seq and arguments:

input: {"type":"tool_start","seq":5,"call_id":"c1","name":"echo","args":{"m":"x"}}
output: echo c1 5 {"m":"x"}

Every event type has a MarshalJSON method that writes the type field first; json.Marshal on any event gives the wire form shown on this page.

weft.UnmarshalEvent decodes one wire event, dispatching on its type. It returns the concrete type as a value (weft.ToolStart, not *weft.ToolStart), so a type switch or assertion names the value types.

InputResult
A known typeThe event, with every field the object carries; absent fields are zero
No type, or "type":""Error event has no "type" field
An unknown typeError unknown event type "<type>", never a skipped event
A nested object with a bad inner eventError nested event: <inner error>
Bytes that are not a JSON objectThe encoding/json error