Intercept user input
Use thepre:send event to intercept messages before they reach the agent. Transform user input, add context, or implement custom validation.
For detailed guidance, see Handling user input.
Intercept agent responses
Use thepre:receive event to intercept agent responses before the chat displays them. Modify, filter, or enhance responses.
Handle streaming responses
Use thepre:stream:delta event to filter or transform streaming content in real time.
Send messages programmatically
Use thesend method to send messages to the agent programmatically. Trigger conversations or simulate user input.
Persist custom state
UseupdateMessageStateUserDefined to persist custom data in message state across thread reloads.
Message lifecycle events
The chat interface emits events at key points in the message lifecycle. Observe and react to message flow:-
pre:send
Triggered before sending a message to the agent. -
send
Triggered after sending a message to the agent. -
pre:stream:delta
Triggered before each streaming chunk is processed. -
pre:receive
Triggered before receiving a complete response. -
receive
Triggered after receiving a complete response.

