Tutorial 10: Visualize your agent’s actions with Mermaid charts
Overview
This tutorial shows how to quickly visualize your agent's actions in Enterprise h2oGPTe by turning a chat session into a Mermaid flowchart. This method helps both technical and non-technical users understand agent behavior, identify unexpected choices, and share results effectively.
After completing this tutorial, you'll be able to generate visual flowcharts like this one that shows an agent's decision-making process:
This flowchart shows the agent's workflow, decision points, and actions, making it easy to understand what happened during the interaction.
Objective
- Quickly understand and explain what your agent did, without reading raw JSON or code.
- Useful for demos, customer support, and troubleshooting when agents behave unexpectedly.
- Helps non-technical users and stakeholders visualize agent decisions and flows.
Prerequisites
- Ability to create and manage Collections and Chats. See Collections usage overview, Chats overview, and Agents overview.
- Mermaid CLI installed locally for manual rendering.
Step 1: Create a chat with an agent
- In the Enterprise h2oGPTe navigation menu, click Chats.
- Navigate to + New chat and start a chat with the Agent enabled.
- Enter your question in the Ask anything box.
- Click Submit. This will start a new chat session with the agent.
Step 2: Ask follow-up questions
- With agents still enabled, ask a follow-up question in the same chat session.
- You can ask your agent anything, the key is to keep agents active so their actions are recorded.
Step 3: Download the chat_conversation
JSON file
- To begin, click on the LLM Prompt icon.
- In the dialog that appears, click on the icon to copy the
chat_conversation
JSON.
Step 4: Create a flowcharting prompt template
- In the Enterprise h2oGPTe navigation menu, click Prompts to manage Prompt Templates.
- Click + New prompt template to create a new template with a system prompt for generating a Mermaid chart flowchart. See Create a prompt template for details.
- In the Template name box, enter a name for the prompt template.
- Paste the following system prompt into the System prompt input box:
🛠️ SYSTEM PROMPT: Mermaid Diagram Generator from Agent Chat History
You are an expert Mermaid Diagram code generator for visualizing agentic interactions. The user will paste a back-and-forth conversation between two agents — a Thinking AI Agent and a Code Executor AI Agent — in JSON-like format under a <conversation> tag.
Your job is to output a Mermaid Diagram flowchart, with the following constraints and instructions:
⸻
✅ Mermaid Diagram Rules:
1. Do not use quotation marks (") in node labels.
2. Do not use parentheses (( or )) in node labels.
3. Use <br /> for line breaks inside nodes.
4. Start each node label with an appropriate emoji to convey meaning visually.
5. Use appropriate node styles based on context:
```mermaid
classDef error fill:#ffe6e6,stroke:#ff4d4d,stroke-width:2px,color:#990000
classDef success fill:#e6ffe6,stroke:#00cc66,stroke-width:2px,color:#006600
classDef action fill:#f0f8ff,stroke:#3399ff,stroke-width:2px
classDef decision fill:#fff9e6,stroke:#ffcc66,stroke-width:2px
```
⸻
🧠 Your Objective:
Generate Mermaid flowchart code that explains:
• What steps were taken by the agents
• What tools or APIs were used
• What decisions or branches were encountered
• What errors occurred and how they were handled
• What the final outcome was
This diagram should be friendly to **business users** — avoid code-y words and highlight the meaning or goal of each step with emojis and plain language.
⸻
✨ Output Format:
```mermaid
flowchart TD
%% Your flowchart nodes and arrows here
%% Include styling at the end
classDef error fill:#ffe6e6,stroke:#ff4d4d,stroke-width:2px,color:#990000
classDef success fill:#e6ffe6,stroke:#00cc66,stroke-width:2px,color:#006600
classDef action fill:#f0f8ff,stroke:#3399ff,stroke-width:2px
classDef decision fill:#fff9e6,stroke:#ffcc66,stroke-width:2px
```
**You must end your response with ONLY the Mermaid code (no explanation, no markdown formatting).**
⸻
📥 Input Format Example:
```xml
[
[
"User question...",
"Thinking Agent proposes code..."
],
[
"Execution Agent runs code, gets error",
"Thinking Agent tries alternative approach"
]
]
```
- You can adjust the settings as needed, but we recommend keeping the system prompt as shown above for this tutorial.
- Click + Create to create the prompt template.
Step 5: Use the flowchart prompt template
- In the Enterprise h2oGPTe navigation menu, click Collections.
- Click + New collection. See Create a Collection for details on creating a collection.
- Click + Start your first Chat.
- In the Ask anything box, paste the
chat_conversation
JSON you copied in Step 3. - Click the Settings icon in the upper-right corner to customize the chat.
- In the Prompt template to use tab, select the flowchart prompt template you created in Step 4 from the dropdown menu.
- Click Submit. This will submit the JSON to the agent using the selected prompt template.
Step 6: Render and view your Mermaid chart
To render the Mermaid chart, you can use one of the following methods:
- Agent rendering
- Mermaid CLI
- Online Editor
- Ask the agent to render the Mermaid diagram directly in the chat.
- The success rate of this method may vary depending on the agent and prompt.
-
Install Mermaid CLI if you haven’t already:
npm install -g @mermaid-js/mermaid-cli
-
Create a file named
tutorial_10.mmd
. -
Paste the Mermaid output from the agent into the file and save it.
-
Generate a flowchart image by running:
mmdc -i test.mmd -o test.png
-
Open the generated
test.png
file to view the flowchart.
- Go to the Mermaid Live Editor.
- Copy the Mermaid code from the agent’s response.
- Paste the code into the editor on the left side of the page.
- View the rendered diagram on the right side.
- To download the diagram as an image, click the Download button in the editor.
- If the Mermaid output is inaccurate or incomplete, try refining the prompt template or re-running the process.
- For complex or custom agents, results may vary. Manual review is recommended.
- If a prompt consistently produces accurate diagrams, consider sharing it with your team.
- Submit and view feedback for this page
- Send feedback about Enterprise h2oGPTe to cloud-feedback@h2o.ai