Skip to content

Run store

A tiny store that turns agent events into the snapshot every component reads. Create one per run and emit events into it from anywhere: a stream reader, a websocket handler, a trace exporter.

On this page

Create a run

TSX
import { useAgentRun, useAgentSnapshot } from "@/lib/knowns/run";

const run = useAgentRun({ maxSpans: 500 });     // or createAgentRun() outside React
const snapshot = useAgentSnapshot(run);         // { actors, spans, links, approvals }

Events

actor
{ actor }
Add an actor, or merge fields into the one with the same id.
actor.remove
{ id }
Remove an actor with its spans, links and approvals.
span.start
{ id, from, to, summary?, input?, at? }
A call begins. Shows as a streak, a running bar and a running card.
span.end
{ id, outcome?, output?, error?, at? }
The call returns. outcome defaults to "success".
link
{ from, to }
Draw a permanent link before any call uses it.
approval.request
{ id, actor, title, detail?, at? }
An actor needs a human decision.
approval.resolve
{ id, decision }
"approved" or "denied". ApprovalPrompt emits this for you.
reset
{}
Start over.

Pass an array to emit to apply several events with a single re-render. Events without at use the current time.

Feeding it from a stream

TypeScript
// Map whatever your agent framework sends to Knowns UI events.
for await (const chunk of agentStream) {
  if (chunk.kind === "tool-call") {
    run.emit({ type: "span.start", id: chunk.callId, from: chunk.agent, to: chunk.tool, input: chunk.args });
  }
  if (chunk.kind === "tool-result") {
    run.emit({ type: "span.end", id: chunk.callId, outcome: chunk.error ? "failure" : "success",
               output: chunk.result, error: chunk.error });
  }
}

Without a store

Every component also takes plain data props (actors, spans, links, approvals) if you already keep that state somewhere else.

Need help?

Stuck on Run store, or found something off? We read every message.