Agent status
One typed status for a run (idle, working, blocked on a person, done, failed), from live events or stored state.
AgentStatus in @yolk-sdk/agent/protocol says what a run is doing. It uses the vocabulary of
the OSC 7501 Program Status Protocol:
the SDK reports state, and your app decides how to show it (badges, inbox rows, notifications).
_tag | Meaning |
|---|---|
Idle | At rest, waiting for the next instruction. Also the status after a person stops a run. |
Working | Running. activity says what: Busy, Generating, Tools, Compacting, Retrying. |
Blocked | Paused until a person settles every request. kind says what is needed, requests holds them. |
Done | Finished. The result is in the transcript. |
Failed | Failed and stopped. message, plus the AgentError when the stream sent one. |
Every variant is an Effect Schema class, so a status encodes to JSON with
Schema.toCodecJson(AgentStatus) and can be stored next to the run.
Blocked kinds
| Request | kind |
|---|---|
ToolApprovalRequest, InteractionRequest | permission |
QuestionRequest, InputRequest | question |
| (reserved for logins and credentials) | auth |
One pause can hold several requests (same-turn sibling calls). agentBlockedKind reports one kind
for the batch, auth over permission over question; hitlRequestBlockedKind gives each
request's own kind.
From live events
import { agentStatusFromEvents, nextAgentStatus } from '@yolk-sdk/agent/protocol'
let status = agentStatusFromEvents(replayedEvents)
status = nextAgentStatus(status, event)| Event | Status |
|---|---|
AgentStart, TurnStart | Working(Busy) |
LLMStreamStart | Working(Generating) |
ToolExecutionStarted / Completed, Accepted, Error | adds / removes a running tool |
CompactionStart / CompactionEnd | Working(Compacting) / Busy |
AgentRetry | Working(Retrying), until output resumes |
AgentAwaitingInput | Blocked |
AgentEnd | Done |
AgentError with code aborted and abortReason user (or none) | Idle |
any other AgentError, including system and max_turns aborts | Failed |
Other events leave the status unchanged. Work events mean the run is working whatever came
before, so a resumed durable stream leaves Blocked even when it does not replay AgentStart.
Dedupe replayed events by eventId before folding them. agentStatusRetry(status) returns the
pending AgentRetry while retrying.
The useAgentChat reducer and reduceAgentEvents also fence replays without eventId: a replayed
AgentAwaitingInput blocks only on the requests their chat or tool runs still show pending, and
leaves the status as it was when every request names a call (same id, name and arguments) already
answered, cancelled, denied or finished. A replayed start of a finished call leaves it too.
A host that keeps a chat projection and folds status itself gets the same fence from
stepAgentChatProjection in @yolk-sdk/agent/react. It applies the event as
applyAgentEventToChatProjection does and returns statusEvent: the event to fold, or
undefined when the status must not move (an event seen before, one from a superseded or stale
model step, a replayed start of a finished call, a pause whose every call is past its request).
A pause naming some such calls comes back with only its pending requests. Folding every event
instead would show Blocked with no card to answer. When the event's model step started before
the projection's first event (a mid-turn snapshot rebuild) and names its turn (executionTurn),
the step also returns missedStart, the LLMStreamStart the projection applied first: fold it
before statusEvent.
import { idleAgentStatus, nextAgentStatus } from '@yolk-sdk/agent/protocol'
import { makeAgentChatEventProjectionState, stepAgentChatProjection } from '@yolk-sdk/agent/react'
let projection = makeAgentChatEventProjectionState()
let status = idleAgentStatus
for (const event of events) {
const step = stepAgentChatProjection(projection, event)
projection = step.projection
if (step.missedStart !== undefined) status = nextAgentStatus(status, step.missedStart)
if (step.statusEvent !== undefined) status = nextAgentStatus(status, step.statusEvent)
}To use agentStatusFromEvents (or agentStatusTreeFromEvents), collect each step's missedStart
and then its statusEvent, leaving out undefined, and pass those instead of the raw events.
From stored state
Store the encoded status in the same commit as the rest of the run, and reconcile it when you read it back:
import { reconcileAgentStatus } from '@yolk-sdk/agent/protocol'
const status = reconcileAgentStatus(stored, { runActive: run.workflowRunId !== null })Working and Blocked only hold while the run is alive, so they become Idle when you tell it
the run is not active (lease cleared, platform run terminal). Done and Failed stay until you
replace them. Base runActive on your authoritative run record, never on the last event seen.
Subagents
AgentStatusTree is the run's root status plus one SubagentStatusEntry per subagent, in start
order. nextAgentStatusTree and agentStatusTreeFromEvents fold events into it:
SubagentStartedadds aWorkingentry;SubagentCompletedsetsDoneorFailed.- A subagent call that the host accepts as background work (its result passes
isSubagentAcceptedToolResult, as one built bymakeSubagentAcceptedToolResultdoes, or aToolExecutionAcceptedevent) is markedbackground: true. Its status comes from you after that: write it withwithSubagentStatus. - When the run stops (
AgentEnd,AgentError, a local stop, or a transport failure), live inline subagents becomeIdle. AgentStartdrops entries settled in earlier runs.
In client and React state
AgentClientState and AgentChatState carry status: AgentStatus and subagents. Failures and
retries live in the status (Failed, Working(Retrying)), not in separate fields. useAgentChat
returns status and subagents, and keeps isRunning (Working) and isWaiting (Blocked).
import { Match } from 'effect'
const label = Match.value(chat.status).pipe(
Match.tag('Idle', () => 'Idle'),
Match.tag('Working', () => 'Working'),
Match.tag('Blocked', current =>
Match.value(current.kind).pipe(
Match.when('permission', () => 'Needs approval'),
Match.when('question', () => 'Needs answer'),
Match.when('auth', () => 'Needs sign-in'),
Match.exhaustive
)
),
Match.tag('Done', () => 'Done'),
Match.tag('Failed', current => current.message),
Match.exhaustive
)Host-owned
- Whether a person has seen a
DoneorFailedrun (unread state). - Labels, wording, and which statuses notify, plus rate limits for notifications.
- Proof that a run is alive (
runActive). - Emitting OSC 7501 sequences, if you ship a terminal app.