Flashing Output in AI Agent
I am testing my AI Agent, which generates code, and I noticed that the output background flashes between black and white while the code is being generated. It doesn't do this when it's generating standard text, only when providing code.
2 Replies
Why it happens
When the assistant streams a message that is tagged as a Markdown code-block (), the web-chat first prints the raw text, then runs the syntax-highlighter. The highlighter swaps in a dark code theme after it recognises the language, so on every incremental update you momentarily see the default (white) background before it is restyled – that’s the “flash”. It does not occur on normal text because those lines are never passed through the highlighter. Fix / work-arounds
1. Turn the highlighter off for a response
‑ add
text your code here 2. Lock the code-block colours with CSS
If you still want highlighting, pin the background colour so it never flips. Add a small stylesheet in your
https://docs.voiceflow.com (section Custom web chat styling → Custom CSS styling).
When the assistant streams a message that is tagged as a Markdown code-block (), the web-chat first prints the raw text, then runs the syntax-highlighter. The highlighter swaps in a dark code theme after it recognises the language, so on every incremental update you momentarily see the default (white) background before it is restyled – that’s the “flash”. It does not occur on normal text because those lines are never passed through the highlighter. Fix / work-arounds
1. Turn the highlighter off for a response
‑ add
text
(or any unknown language) after the opening back-ticks. The library will skip colourising and the flash stops:text your code here 2. Lock the code-block colours with CSS
If you still want highlighting, pin the background colour so it never flips. Add a small stylesheet in your
chat.load()
snippet:
(You can host the CSS instead and pass the URL via assistant.stylesheet
.)
Either option prevents the alternating black/white flash while the agent is streaming code.
Docs for reference:https://docs.voiceflow.com (section Custom web chat styling → Custom CSS styling).
oh, that's interesting. We haven't seen a ton of code generation usecases. thanks for reporting this @Richcantoo