CaioElias
CaioElias4w ago

Formatting Agent Block Responses

I have a function that splits a paragraph into shorter sentences. When I used prompt blocks, I could easily use this function because I was able to store the prompt's response in a variable. However, I’m having trouble doing the same with an Agent block response. How can I store the Agent block's response in a variable or make the Agent reply in shorter, separated sentences instead of one long paragraph? I’ll be using this on WhatsApp, so shorter messages are better than large blocks of text.
No description
1 Reply
Tico | Voiceflow Assistant
Here’s what you need to know: 1. Why you can’t “grab” the reply the same way you did with a Prompt block
• The Agent step doesn’t expose its final text as {{ variable }} the way Prompt & Set steps do, so there’s nothing you can pipe straight into a Code/Function step after it.
• Because of that, you can’t run an external “split-my-paragraph” function after the Agent has already talked. 2. Two practical work-arounds A) Tell the LLM to format the message for you
• Open the Agent step → “Instructions”.
• Add a line such as:
“Always answer with short sentences (max 2 lines each) and put a double line-break between sentences. Do not return a single long paragraph.”
• Because WhatsApp collapses line-breaks into one bubble, the user will still see a compact message, but it will be easier to read than one large block. B) Let the LLM call your splitter function before it speaks
1. Add your existing JS splitter as a Function in the project library.
2. Inside the Agent step → “Tools” → “Functions” click Add Function and choose it.
3. In the “LLM description” for that function write something like:
“Use this function to break any reply longer than 200 characters into an array of shorter sentences. Always call it before replying to the user.”
4. Result:
• The LLM first calls your function, Voiceflow executes it, and the function returns an array (e.g. [\"Sentence 1\", \"Sentence 2\"]).
• Voiceflow will then output each item as a separate Text trace, so WhatsApp sends them as separate bubbles. 3. Key points & limits
• There’s currently no system variable like {{ agent_reply }} you can capture.
• If you need truly separate WhatsApp bubbles, approach B is the only deterministic way.
• Keep each Text trace < 160 characters if you want to avoid WhatsApp’s own SMS-style splitting. Docs for reference: https://docs.voiceflow.com (Agent step → Functions)

Did you find this page helpful?