Triggered before each streaming delta chunk is processed and rendered in the chat. This event is fired only during streaming responses when the agent sends partial content incrementally. Use this event to inspect, modify, or suppress streaming content before it appears in the chat UI.
This event is only triggered when you use streaming responses. Non-streaming responses do not fire this event.
Array of content items in the delta chunk. Contains only the incremental content for the current chunk, not the complete message. To suppress delta rendering, set this to an empty array ([]). The complete message is still rendered with pre:receive and receive events.
The following example modifies an streaming content:
instance.on('pre:stream:delta', (event, instance) => { console.log('Streaming delta received:', event); console.log('Message ID:', event.messageId); console.log('Thread ID:', event.threadId); // Modify streaming text before it's rendered event?.delta?.content?.forEach((contentItem) => { if (contentItem.response_type === 'text' && contentItem.text) { // Convert streaming text to uppercase contentItem.text = contentItem.text.toUpperCase(); // Filter out specific words or phrases contentItem.text = contentItem.text.replace(/confidential/gi, '[REDACTED]'); } }); // Log streaming progress const deltaLength = event?.delta?.content?.[0]?.text?.length || 0; console.log(`Delta chunk received: ${deltaLength} characters`); // Track streaming metrics trackStreamingMetrics({ messageId: event.messageId, threadId: event.threadId, runId: event.runId, deltaLength: deltaLength, timestamp: Date.now() });});
The following example suppress delta rendering:
instance.on('pre:stream:delta', (event, instance) => { // Suppress delta rendering by emptying the content array // Streaming still occurs, but text won't appear character by character // Only the final complete message will be rendered event.delta.content = []; console.log('Delta rendering suppressed - final message will render after streaming completes');});
The following example shows the translation pattern:
let shouldSuppressDeltas = true;instance.on('pre:stream:delta', (event, instance) => { // Suppress deltas during streaming if (shouldSuppressDeltas) { event.delta.content = []; }});instance.on('pre:receive', (event, instance) => { // Translate the complete message before rendering event?.message?.content?.forEach((contentItem) => { if (contentItem.response_type === 'text' && contentItem.text) { // Apply translation to complete message contentItem.text = translateText(contentItem.text); } });});