Building a visual agent canvas with live SSE tool states and a small intent router

One of the things I enjoy most about staying full-stack is seeing how backend architecture choices show up immediately in the user interface.
Over the past couple of months I have been splitting time between two ends of our stack: the visual workflow canvas + live streaming chat UI on the frontend, and a lightweight fine-tuned intent/complexity router sitting inside our inference gateway on the backend.
Making streaming tool execution feel legible in React
When an enterprise agent runs a 5-step workflow (sanitize PII, query the knowledge base with hybrid vector + keyword search and reranking, call two external tools, then draft a response), staring at a generic spinning dots loader for 15 seconds feels broken. Users assume the app froze and hit refresh.
Instead of only streaming raw text deltas over SSE, our backend emits typed lifecycle events on the same stream:
type AgentStreamEvent =
| { type: "node_started"; nodeId: string; label: string; ts: number }
| { type: "tool_call"; callId: string; tool: string; status: "running" }
| { type: "tool_result"; callId: string; durationMs: number; ok: boolean }
| { type: "approval_required"; gateId: string; summary: string }
| { type: "token"; delta: string }
| { type: "done"; traceId: string };
On the frontend, both the chat timeline and the visual workflow canvas subscribe to that exact event stream. As each node fires, the corresponding node on the canvas highlights live, tool cards flip from running to a collapsible duration badge, and if a human-in-the-loop approval gate triggers, an inline approve/reject card drops right into the conversation with RBAC checks enforced server-side.
A small React perf tip that saved us jank: never call setState on every single incoming token frame when streaming fast models (some quantized local models push 150+ tokens/sec). Buffer incoming token deltas in a ref and flush to React state inside requestAnimationFrame (~60Hz max). The text still feels instantaneous to the eye, and CPU usage drops sharply when a trace debugging drawer is open next to the canvas.

Routing cheap vs. frontier models with a tiny fine-tuned classifier
On the gateway side, sending every single query - including simple classification nodes, formatting steps, and straightforward FAQ lookups - to the largest flagship model burns budget fast.
Rather than relying on brittle regex heuristics, we built curated evaluation sets from real production traffic (scrubbed of PII) and fine-tuned a small, fast intent and complexity router model. Before forwarding a request, the gateway classifies complexity in a few milliseconds and routes simple turns to faster/cheaper models while reserving heavy reasoning models for genuinely multi-step or ambiguous prompts.
Paired with multi-provider failover, per-tenant TPM/RPM rate-limiting, circuit breakers when an upstream starts returning 5xx/429s, and prompt caching, the router noticeably cut inference spend without dragging down answer quality on the hard queries.
The neat loop connecting both halves: whenever a user inspects an end-to-end trace in the debugging view and flags a bad routed answer, that trace feeds right back into our evaluation set for the next router tuning pass.
Share this article
Reactions