If you’ve spent any time tuning AI agent prompts, you already know the frustration. You tweak a system prompt to fix a hallucination or adjust a tone constraint, save the file, run your test suite, and realize you've accidentally broken three other edge cases.
Iterating on LLM behavior in isolation is a slow, tedious loop. Chatting with an AI in a commercial UI doesn't help either, because you can't easily run the exact same user payload against two different prompt variations at the exact same time.
To solve this, developers often build ad-hoc testing setups—messy Node scripts, scattered browser tabs, or brittle shell commands. But there is a much better way.
By building a dedicated prompt playground in Vue 3, you can execute concurrent agent instructions side by side, stream responses in real-time, track token usage, and inspect how subtle instruction shifts alter multi-step agent behavior.
In this comprehensive guide, we'll build a production-ready prompt playground from scratch using Vue 3, Composition API, TypeScript, and Tailwind CSS. We will design a reactive architecture that handles multiple independent execution threads, manages asynchronous streaming chunks without UI locking, and gives you a structured environment to debug AI agent instructions.
📋 Table of Contents
- The Engineering Problem: Why Chat UIs Fail for Prompt Engineering
- 1. Designing the Core State Architecture for Multi-Agent Execution
- 2. Building the Split-Screen Playground Layout
- 3. Constructing the Dynamic Instruction & Variable Panel
- 4. Managing Concurrent API Streams Without UI Freezes
- 5. Implementing Real-Time Markdown and Tool Call Rendering
- 6. Adding Side-by-Side Response Diffing and Performance Metrics
- 7. Persisting Workspaces and Exporting Evaluation Suites
- Production Architecture Decisions and Scaling Limits
The Engineering Problem: Why Chat UIs Fail for Prompt Engineering
Scenario: You are building an AI support agent that needs to troubleshoot database connection errors without giving overly technical jargon to non-engineer users. You write a system prompt, open ChatGPT or Claude.ai, paste a test case, and get a decent response. Then you change a single sentence in the system prompt to enforce shorter answers, and test again. Suddenly, you have to scroll up and down across multiple chat threads to compare tone, length, and technical accuracy.
Why it matters: Standard chat interfaces are designed for linear, conversational state. Prompt engineering, however, is a comparative, parametric science. You need to evaluate how changes in system instructions, few-shot examples, or model hyperparameters affect outputs against identical inputs.
[Single User Input] ──┬──> [Agent Config A: Strict & Concise] ──> [Output A]
│
└──> [Agent Config B: Conversational] ──> [Output B]
When you evaluate prompts sequentially, human memory introduces bias. You remember the vibe of the first response rather than its exact phrasing. To engineer reliable AI agents, you need deterministic, side-by-side execution under identical runtime conditions.
1. Designing the Core State Architecture for Multi-Agent Execution
Scenario:
Your playground needs to support anywhere from two to four panes running simultaneously. Each pane represents a distinct agent configuration: different system prompts, different model checkpoints (e.g., gpt-4o vs claude-3-5-sonnet), and different temperature settings.
Solution: Instead of managing disparate reactive variables for every input and output, we encapsulate an agent's configuration, execution state, and history into a strongly-typed TypeScript interface. We then manage these panes inside a centralized Vue store or a well-structured composable.
Here is the core type definition and composable structure:
// types/playground.ts
export type AIModel = 'gpt-4o' | 'gpt-4o-mini' | 'claude-3-5-sonnet' | 'claude-3-haiku';
export interface AgentConfig {
id: string;
name: string;
model: AIModel;
systemPrompt: string;
temperature: number;
maxTokens: number;
topP: number;
}
export interface ExecutionMetrics {
timeToFirstTokenMs: number;
totalTimeMs: number;
promptTokens: number;
completionTokens: number;
totalTokens: number;
}
export interface AgentPaneState {
config: AgentConfig;
inputVariables: Record<string, string>;
outputStream: string;
isStreaming: boolean;
error: string | null;
metrics: ExecutionMetrics | null;
history: Array<{ role: 'user' | 'assistant'; content: string }>;
}
Why this works:
By structuring the state as an array of independent AgentPaneState objects, your Vue reactivity system can track updates to Pane 1 without triggering layout re-renders or stream interruptions in Pane 2 or Pane 3.
💡 Practical note: Avoid deep-cloning massive history arrays on every token arrival. When streaming text chunk-by-chunk, append directly to the target pane's reactive
outputStreamstring ref, and only commit to history once the stream closes.
2. Building the Split-Screen Playground Layout
Scenario: You want a flexible workspace where developers can toggle between a 2-column comparison view, a 3-column deep dive, or a stacked mobile layout without breaking the streaming pipelines.
Solution: We use CSS Grid with dynamic template columns combined with Vue's template reactivity to render our panes. Let's create the main container component that orchestrates multiple configuration panels side by side.
<!-- components/PlaygroundGrid.vue -->
<script setup lang="ts">
import { ref, computed } from 'vue';
import { usePlaygroundStore } from '@/composables/usePlaygroundStore';
import AgentPane from './AgentPane.vue';
const { panes, addPane, removePane, runAllPanes } = usePlaygroundStore();
const globalUserInput = ref('');
const gridColumnsClass = computed(() => {
switch (panes.value.length) {
case 1: return 'grid-cols-1';
case 2: return 'grid-cols-1 lg:grid-cols-2';
case 3: return 'grid-cols-1 lg:grid-cols-3';
default: return 'grid-cols-1 lg:grid-cols-2 xl:grid-cols-4';
}
});
</script>
<template>
<div class="flex flex-col h-screen bg-slate-950 text-slate-100">
<!-- Global Toolbar -->
<header class="flex items-center justify-between px-6 py-4 border-b border-slate-800 bg-slate-900">
<div class="flex items-center gap-4">
<h1 class="text-xl font-bold tracking-tight">Prompt Playground</h1>
<span class="text-xs px-2 py-1 rounded bg-indigo-500/20 text-indigo-400 font-mono">Vue 3 + TS</span>
</div>
<div class="flex items-center gap-3">
<button
@click="addPane"
class="px-3 py-1.5 text-sm font-medium bg-slate-800 hover:bg-slate-700 rounded-lg border border-slate-750 transition"
>
+ Add Agent Pane
</button>
<button
@click="runAllPanes(globalUserInput)"
class="px-4 py-1.5 text-sm font-semibold bg-indigo-600 hover:bg-indigo-500 text-white rounded-lg shadow-lg shadow-indigo-600/20 transition flex items-center gap-2"
>
<span>Run All</span>
<kbd class="px-1.5 py-0.5 text-xs bg-indigo-700 rounded text-indigo-200">⌘↵</kbd>
</button>
</div>
</header>
<!-- Global User Input Bar -->
<div class="px-6 py-3 bg-slate-900/50 border-b border-slate-800/80">
<div class="max-w-4xl mx-auto flex gap-3">
<textarea
v-model="globalUserInput"
rows="2"
placeholder="Enter prompt payload to broadcast to all agents... (supports {{variable}} syntax)"
class="w-full bg-slate-950 border border-slate-800 rounded-lg px-4 py-2 text-sm focus:outline-none focus:border-indigo-500 resize-none font-sans"
></textarea>
</div>
</div>
<!-- Panes Grid Container -->
<main class="flex-1 p-6 overflow-x-auto">
<div :class="['grid gap-6 h-full min-w-[768px]', gridColumnsClass]">
<AgentPane
v-for="(pane, index) in panes"
:key="pane.config.id"
:pane="pane"
:index="index"
@remove="removePane(pane.config.id)"
@run="(input) => runPane(pane.config.id, input)"
/>
</div>
</main>
</div>
</template>
Why this works: Separating the global input bar from the individual agent panes allows you to test exact parity across different system prompts while retaining the flexibility to override inputs on a per-pane basis if needed.
3. Constructing the Dynamic Instruction & Variable Panel
Scenario:
Your system prompts often include dynamic injection templates like You are an assistant for {{companyName}} addressing tickets tagged with {{category}}. Hardcoding these values is impossible when testing across dozens of scenarios.
Solution:
We write a lightweight template parser that automatically detects double-curly-brace variables ({{variableName}}) inside the system prompt and user input, rendering dynamic input fields for each discovered variable in real-time.
// utils/templateParser.ts
export function extractVariables(template: string): string[] {
const regex /\{\{([^}]+)\}\}/g;
const matches = new Set<string>();
let match;
while ((match = regex.exec(template)) !== null) {
matches.add(match[1].trim());
}
return Array.from(matches);
}
export function interpolateTemplate(template: string, variables: Record<string, string>): string {
return template.replace(/\{\{([^}]+)\}\}/g, (_, key) => {
const trimmed = key.trim();
return variables[trimmed] !== undefined ? variables[trimmed] `{{${trimmed}}}`;
});
}
Now, inside our individual AgentPane.vue component, we leverage this parser:
<!-- Inside AgentPane.vue -->
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { extractVariables, interpolateTemplate } from '@/utils/templateParser';
const props = defineProps<{ pane: AgentPaneState }>();
// Extract variables from both system prompt and local inputs
const detectedVariables = computed(() => {
const systemVars = extractVariables(props.pane.config.systemPrompt);
return Array.from(new Set([...systemVars]));
});
// Auto-initialize missing keys in input variables record
watch(detectedVariables, (vars) => {
vars.forEach(v => {
if (props.pane.inputVariables[v] === undefined) {
props.pane.inputVariables[v] = '';
}
});
}, { immediate: true });
</script>
Why this works:
Developers don't have to manually declare what variables exist in their test case. The UI reacts dynamically as soon as {{ is typed in the instruction box, ensuring zero friction during rapid prompt engineering experiments.
4. Managing Concurrent API Streams Without UI Freezes
Scenario:
When hitting Run All, your Vue app fires off requests to OpenAI and Anthropic simultaneously. If you aren't careful with asynchronous generator handling and ReadableStream parsing, your browser's main thread will lock up, causing stuttering scroll performance and frozen UI animations.
Solution:
We use the fetch API paired with TextDecoderStream to parse Server-Sent Events (SSE) asynchronously without blocking the main event loop.
// composables/useAgentExecution.ts
import { AgentPaneState, AgentConfig } from '@/types/playground';
export function useAgentExecution() {
async function streamAgentResponse(
pane: AgentPaneState,
resolvedInput: string,
apiKey: string
) {
pane.isStreaming = true;
pane.outputStream = '';
pane.error = null;
const startTime = performance.now();
let firstTokenTime = 0;
let promptTokens = 0;
let completionTokens = 0;
try {
const response = await fetch('/api/proxy/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: pane.config.model,
systemPrompt: pane.config.systemPrompt,
userInput: resolvedInput,
temperature: pane.config.temperature,
maxTokens: pane.config.maxTokens,
apiKey
})
});
if (!response.ok) {
throw new Error(`API Error: ${response.statusText}`);
}
if (!response.body) throw new Error('Response body missing stream.');
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
if (!firstTokenTime && pane.outputStream.length > 0) {
firstTokenTime = performance.now() - startTime;
}
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop() || ''; // Keep trailing incomplete line
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed === 'data: [DONE]') continue;
if (trimmed.startsWith('data: ')) {
const json = JSON.parse(trimmed.slice(6));
const textChunk = json.choices?.[0]?.delta?.content || json.delta?.text || '';
pane.outputStream += textChunk;
completionTokens++;
}
}
}
const totalTime = performance.now() - startTime;
pane.metrics = {
timeToFirstTokenMs: Math.round(firstTokenTime || totalTime),
totalTimeMs: Math.round(totalTime),
promptTokens: jsonEstimateTokens(resolvedInput),
completionTokens,
totalTokens: promptTokens + completionTokens
};
} catch (err: any) {
pane.error = err.message || 'An unknown error occurred during streaming.';
} finally {
pane.isStreaming = false;
}
}
return { streamAgentResponse };
}
⚠️ Gotcha: Never send your production API keys straight from the client-side Vue app to OpenAI or Anthropic endpoints. Always proxy requests through a lightweight backend route (like a Nuxt server route, a Next.js API route, or a fast Express/Fastify server) to protect your credentials from browser inspection.
5. Implementing Real-Time Markdown and Tool Call Rendering
Scenario: Modern AI agents don't just output plain text; they output Markdown tables, code blocks, JSON structures, and formatted tool execution calls (e.g., searching a vector database or executing code). Rendering raw markdown streams while chunks are actively arriving often leads to broken syntax rendering and flashing UI components.
Solution:
We use marked combined with DOMPurify for safe HTML sanitization, wrapped in a computed property with debounced reflow triggers, or lightweight markdown renderers designed for streaming chunks.
<!-- components/AgentOutputViewer.vue -->
<script setup lang="ts">
import { computed } from 'vue';
import { marked } from 'marked';
import DOMPurify from 'dompurify';
const props = defineProps<{
content: string;
isStreaming: boolean;
}>();
// Configure marked for safe developer output
marked.setOptions({
gfm: true,
breaks: true,
});
const renderedHtml = computed(() => {
if (!props.content) return '';
const rawHtml = marked.parse(props.content);
return DOMPurify.sanitize(rawHtml as string);
});
</script>
<template>
<div class="relative flex-1 bg-slate-900 border border-slate-800 rounded-xl p-4 overflow-y-auto font-sans text-sm">
<!-- Streaming indicator badge -->
<div v-if="isStreaming" class="absolute top-3 right-3 flex items-center gap-2 px-2.5 py-1 rounded-full bg-emerald-500/10 border border-emerald-500/20 text-emerald-400 text-xs font-mono">
<span class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span>
Streaming...
</div>
<!-- Output Content -->
<div v-if="content" class="prose prose-invert prose-indigo max-w-none" v-html="renderedHtml"></div>
<div v-else class="h-full flex items-center justify-center text-slate-600 italic">
Awaiting execution...
</div>
</div>
</template>
Why this works:
Sanitizing with DOMPurify protects your playground from malicious script injection if an agent evaluates untrusted web content or user-supplied markdown payloads.
6. Adding Side-by-Side Response Diffing and Performance Metrics
Scenario: You’ve run two different agent instructions against your prompt. Agent A outputs 450 tokens in 1.2 seconds; Agent B outputs 310 tokens in 800 milliseconds. How do you visually inspect where the responses diverge in wording and structure?
Solution:
We can integrate a lightweight text diffing utility (such as fast-diff) to visually highlight additions and deletions between Pane 1 and Pane 2 directly inside the Vue interface.
// utils/diffChecker.ts
import diff from 'fast-diff';
export interface DiffSegment {
type: 'equal' | 'insert' | 'delete';
text: string;
}
export function computeTextDiff(textA: string, textB: string): DiffSegment[] {
const result = diff(textA, textB);
return result.map(([typeCode, value]) => ({
type: typeCode === 0 ? 'equal' : typeCode === 1 ? 'insert' : 'delete',
text: value
}));
}
Then, display these performance metrics and diff toggles cleanly at the bottom of each agent pane card:
<!-- components/PaneMetricsBar.vue -->
<script setup lang="ts">
import { ExecutionMetrics } from '@/types/playground';
defineProps<{ metrics: ExecutionMetrics | null }>();
</script>
<template>
<div v-if="metrics" class="flex items-center justify-between px-3 py-2 bg-slate-950/60 border-t border-slate-800 text-xs font-mono text-slate-400 rounded-b-xl">
<div class="flex items-center gap-4">
<span>TTFT: <strong class="text-slate-200">{{ metrics.timeToFirstTokenMs }}ms</strong></span>
<span>Total: <strong class="text-slate-200">{{ metrics.totalTimeMs }}ms</strong></span>
</div>
<div class="flex items-center gap-4">
<span>Prompt: <strong class="text-slate-200">{{ metrics.promptTokens }}</strong></span>
<span>Completion: <strong class="text-slate-200">{{ metrics.completionTokens }}</strong></span>
</div>
</div>
</template>
7. Persisting Workspaces and Exporting Evaluation Suites
Scenario: You spent two hours configuring the ultimate system prompt for your customer support agent. If you refresh the page and lose your state, your hard work vanishes.
Solution: Serialize your playground state—including system prompts, configurations, and input variable test cases—into local storage or export them as a portable JSON evaluation suite file.
// composables/usePlaygroundPersistence.ts
import { Ref } from 'vue';
import { AgentPaneState } from '@/types/playground';
const STORAGE_KEY = 'vue_prompt_playground_state_v1';
export function usePlaygroundPersistence(panes: Ref<AgentPaneState[]>) {
function saveToLocalStorage() {
const serialized = panes.value.map(p => ({
config: p.config,
inputVariables: p.inputVariables
}));
localStorage.setItem(STORAGE_KEY, JSON.stringify(serialized));
}
function exportTestSuite() {
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(panes.value, null, 2));
const downloadAnchor = document.createElement('a');
downloadAnchor.setAttribute("href", dataStr);
downloadAnchor.setAttribute("download", `ai-agent-eval-suite-${Date.now()}.json`);
document.body.appendChild(downloadAnchor);
downloadAnchor.click();
downloadAnchor.remove();
}
return { saveToLocalStorage, exportTestSuite };
}
Production Architecture Decisions and Scaling Limits
Building a client-side Vue prompt playground is exceptionally powerful for local iteration, but as your engineering team scales, you will encounter specific architectural boundaries:
| Dimension | Local Vue Playground | Production Evaluation CI/CD |
|---|---|---|
| Concurrency Limit | 2–4 simultaneous streams | 100+ concurrent evaluation runs |
| Key Storage | Local environment / Session | Encrypted Vault / KMS server-side |
| Test Assertions | Manual visual inspection | Automated LLM-as-a-judge rubrics |
| State Persistence | localStorage / JSON export |
PostgreSQL / Vector evaluation database |
When your prompt evaluations outgrow manual side-by-side browser comparisons, your Vue playground can easily be refactored to consume evaluation run APIs from platforms like Braintrust, LangSmith, or your own custom Python/Node evaluation harness.
By grounding your prompt iteration in a reactive, multi-pane Vue architecture, you eliminate guesswork, enforce strict configuration parity, and turn prompt engineering from trial-and-error into a disciplined engineering discipline.