Skip to main content

GraphEvent Objects

A graph event emitted for specific graph events such as start node or end node, and used by the callback to emit user-defined events. Arguments:
  • type (GraphEventType | str): The type of event, can be start_node, end_node, callback, or a custom str.
  • identifier (str): The identifier of the event, this is set typically by a callback handler and can be used to distinguish between different events. For example, a conversation/session ID could be used.
  • token (str | None): The token associated with the event, such as LLM streamed output.
  • params (dict[str, Any] | None): The parameters associated with the event, such as tool call parameters or event metadata.

encode

Encodes the event as a JSON string, important for compatability with FastAPI and starlette. Arguments:
  • charset (str): The character set to use for encoding the event.

CallbackProtocol Objects

Protocol defining the interface for callback handlers.

Callback Objects

The original callback handler class. Outputs a stream of structured text tokens. It is recommended to use the newer EventCallback handler instead.

aiter

Used by receiver to get the tokens from the stream queue. Creates a generator that yields tokens from the queue until the END token is received.

start_node

Starts a new node and emits the start token.

end_node

Emits the end token for the current node.

close

Close the stream and prevent further tokens from being added. This will send an END token and set the done flag to True.

EventCallback Objects

The event callback handler class. Outputs a stream of structured text tokens. It is recommended to use the newer EventCallback handler instead.

__call__

Builds a GraphEvent object and adds it to the queue.

acall

Builds a GraphEvent object and adds it to the queue.

aiter

Used by receiver to get the tokens from the stream queue. Creates a generator that yields tokens from the queue until the END token is received.

start_node

Starts a new node and emits the start token.

end_node

Emits the end token for the current node.

close

Close the stream and prevent further tokens from being added. This will send an END token and set the done flag to True.