Introduction
This workflow is designed to:- Generate a long response in a structured JSON format using the OpenAI: Generate text action.
- Split the response into smaller, more digestible parts using the Get Data from JSON action.
- Present the split content as individual, sequential messages for a better user experience.
Workflow Structure
An agentic workflow for splitting long messages includes:- OpenAI: Generate text node: Produces a structured JSON response where each key represents a smaller part of the overall message.
- Get Data from JSON action: Extracts each section of the JSON response and maps it to individual variables.
- Send Messages nodes: Sequentially displays each part of the message to avoid overwhelming the user with one long block of text.
Step-by-Step Implementation
Configure the OpenAI: Generate Text Node
- Add an OpenAI: Generate text node to your workflow.
-
In the Custom Instructions/Prompt section, instruct the AI to format its response as JSON with clearly defined parts. For example:
-
Save the AI-generated JSON response to a custom variable, such as
{{ai_json}}.
Use the Get Data from JSON Action to Extract Sections
Example JSON:Mapped variables:
- Add the Get Data from JSON action immediately after the OpenAI: Generate text node.
- In the JSON Data field, reference the variable where the JSON response is stored (e.g.,
{{ai_json}}). - Map each JSON key to custom variables:
.part1→MessagePart1.part2→MessagePart2.part3→MessagePart3
- Add as many mappings as needed to cover all the parts of the JSON response.
Example JSON:{{MessagePart1}}→ “Step 1: Understand the basics of nutrition.”{{MessagePart2}}→ “Step 2: Include more vegetables in your meals.”{{MessagePart3}}→ “Step 3: Stay consistent with healthy eating habits.”
Display the Extracted Sections as Split Messages
- Add Send Messages nodes to display the extracted sections sequentially.
- Insert each mapped variable into separate messages:
- First message:
{{MessagePart1}} - Typing delay
- Second message:
{{MessagePart2}} - Typing delay
- Third message:
{{MessagePart3}}
- First message:
Best Practices
Validate JSON Structure
Ensure the AI consistently generates valid JSON by providing clear and explicit prompts.
Set Typing Delays
Add slight typing delays between messages to make the interaction feel natural.
Handle Varying Lengths
If the number of parts varies, create fallback logic or extra mappings to handle additional or missing sections.
Test Thoroughly
Run tests with varied inputs to ensure the splitting logic works consistently.
Example Workflow
User Input: “Can you explain the steps to improve focus and productivity?” AI JSON Output:- Message 1: Step 1: Set clear and achievable goals.
- Message 2: Step 2: Minimize distractions by creating a focused workspace.
- Message 3: Step 3: Use techniques like the Pomodoro method to stay productive.
- Message 4: Step 4: Take breaks to avoid burnout and maintain focus.
