> ## Documentation Index
> Fetch the complete documentation index at: https://developer.watson-orchestrate.ibm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Customize message flow

The chat interface serves as the entry point for all user requests and agent responses. Intercept messages at key points in the lifecycle to transform user input before it reaches the agent, modify agent responses before display, or implement custom rendering behavior.

The chat interface manages message routing between users and agents but does not control response generation. The agent configuration determines response generation, including prompts, instructions, and the selected large language model (LLM).

LLMs are inherently non-deterministic. The system can generate slight variations in responses even when users provide similar or identical inputs. Expect differences in wording, structure, or level of detail as a normal characteristic of LLM-based systems. These variations do not affect the accuracy, reliability, or intent of the information provided.

Embedded chat integrations provide additional flexibility for customization. Developers can modify how the chat experience handles messages by intercepting and adjusting requests or responses at defined integration points. As a result, variations in embedded chat can stem from integration-level processing rather than changes to the agent itself.

##### Intercept user input

Use the [`pre:send`](events/preSend) 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](events/handling-user-input).

##### Intercept agent responses

Use the [`pre:receive`](events/preReceive) event to intercept agent responses before the chat displays them. Modify, filter, or enhance responses.

##### Handle streaming responses

Use the [`pre:stream:delta`](events/preStreamDelta) event to filter or transform streaming content in real time.

##### Send messages programmatically

Use the [`send`](methods/send) method to send messages to the agent programmatically. Trigger conversations or simulate user input.

##### Persist custom state

Use [`updateMessageStateUserDefined`](methods/updateMessageStateUserDefined) 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`](events/preSend)\
  Triggered before sending a message to the agent.

* [`send`](events/send)\
  Triggered after sending a message to the agent.

* [`pre:stream:delta`](events/preStreamDelta)\
  Triggered before each streaming chunk is processed.

* [`pre:receive`](events/preReceive)\
  Triggered before receiving a complete response.

* [`receive`](events/receive)\
  Triggered after receiving a complete response.
