Event Types
SSEEvent union, so the patterns below work for all of them.
ProgressEvent
A human-readable progress update.message is always set; the agent-loop fields are present on events emitted from inside an agent.
CompleteEvent
data is the response type of the method you called — for example, a generateGraphStream() stream completes with a GenerateGraphResponse.
ErrorEvent
PreviewEvent
An incremental preview of the agent’s work-in-progress result. The payload is spread at the top level, and its shape depends on the agent — Mutation previews carryconfig.
ReasoningEvent
A reasoning message emitted by an agent as it works — useful for surfacing the agent’s thinking in a UI.Async Iterator Pattern
generateGraphStream() returns an async iterator:
Preview Events
Some agents emitpreview events carrying partial results before the stream completes. Render them to show work-in-progress.
Cancellation
Pass anAbortSignal to cancel mid-operation:
Progress Callback Alternative
If you want progress updates without the streaming API, use theonProgress callback with generateGraph():
React Pattern
Store the abort controller in a ref for proper cleanup:- Cancel previous requests — Abort any in-flight request before starting a new one
- Store in ref — The abort controller persists across renders
- Cleanup on unmount — Cancel pending requests when the component unmounts
- Handle AbortError — Don’t treat user cancellation as an error
ProgressEvent carries a message, not a numeric percentage — show the latest message as a status line alongside an indeterminate progress indicator.
Type Guards
The SDK exportsisProgressEvent(), isCompleteEvent(), isErrorEvent(), isPreviewEvent(), and isReasoningEvent() for narrowing SSE events, and isGraphyApiError() for narrowing caught errors. All examples on this page use these type guards. See the Type Reference for full signatures.
Error Handling in Streams
Errors can come from two sources:- Error events — The API returns an error during processing
- Exceptions — Network failure, timeout, or abort

