pub struct ToolResultToState { /* private fields */ }server only.Expand description
Promotes a named tool’s result into a state event.
A tool whose job is to produce state — load_document, set_filters —
otherwise forces the agent to emit the result and then publish the state by
hand. This transformer does it: when tool_name returns, its JSON content
becomes a STATE_SNAPSHOT or a STATE_DELTA.
The result event is kept by default so the client still sees the tool
completed; replacing drops it instead. Content that is
not JSON of the expected shape is left alone — a malformed result must not
take down the run. For delta the expected shape is a JSON
Patch a consumer can read: an array of RFC 6902 operations whose path
and from are JSON Pointers. A patch that is well formed and does not
apply to the state is still promoted; a consumer reports that and keeps
the state it has.
let mut promote = ToolResultToState::snapshot("load_document").replacing();
promote.transform(Event::tool_call_start("c1", "load_document"));
let out = promote.transform(Event::tool_call_result("m1", "c1", r#"{"title":"Notes"}"#));
assert_eq!(out, vec![Event::state_snapshot(serde_json::json!({"title": "Notes"}))]);The call need not have started in this run. One the request’s history holds unanswered, one a restated conversation carries, and in a run that another driver began one the events already sent opened, are all calls whose result is promoted.