Events

Read the normalized events Agentdock emits while a run is active.

Await agent.stream() to get two values: stream, which gives you events as they happen, and result, which resolves to the final run result. Each event has a type, run and session IDs, a timestamp, and sequence numbers.

Event types

EventWhat it means
run.startedThe run began.
message.startedA user, assistant, or tool message began.
message.part.deltaA message content part arrived.
message.completedA message finished.
tool.calledThe agent requested a tool.
tool.progressA tool reported progress.
tool.completedA tool returned a result.
tool.failedA tool failed.
interrupt.requiredThe run is waiting for approval.
interrupt.resolvedAn approval decision was applied.
usage.updatedToken usage or cost information arrived.
run.completedThe run finished.
run.failedThe run failed.
run.cancelledThe run was cancelled.

Read text as it arrives

const { stream, result } = await agent.stream(prompt, context, { sessionId });

for await (const event of stream) {
  if (event.type === "message.part.delta" && event.part.type === "text") {
    showText(event.part.text);
  }
}

const finalResult = await result;

Message parts can also contain reasoning, media, files, citations, tool calls, tool results, and custom JSON. Use the type field to handle each part.

Check event versions

Events include protocolVersion. Compare it with AGENT_EVENT_PROTOCOL_VERSION before processing if your app may receive events from a different Agentdock version. The @agentdock-ai/contracts package also exports reduceAgentEvent() to build a UI state from the stream.

On this page