The AI Dashboard Assistant is a feature in the Schoolytics web app. End users ask in natural language (e.g. "third-grade math growth over the last year, grouped by school") and the assistant generates a live Cube-backed dashboard, streaming text and chart renders as it iterates.
Agent architecture
It's a multi-turn agent loop, not a single-shot prompt-to-SQL. The assistant has a schema-aware toolset covering query generation (producing Cube query specs the client renders directly), on-demand schema retrieval, scoped data lookups for profile views, and Markdown report generation for longer-form outputs.
Tool calls and results stream over SSE as structured JSON events. The client validates the tool shape before rendering, and the dashboard updates live as the agent iterates.
Access scoped to the user
All tool calls execute under the requesting user's session scope, the agent cannot query data the user cannot. Access controls live at the data layer, not in the prompt, so prompt injection can't expand what the agent sees.
Two-phase schema injection
Putting the full schema in every turn burns tokens fast. The pattern here is:
- First few turns: ship the full context: query spec, data rows, annotations, and current view so the agent has concrete grounding.
- Later turns: schema is retrieved on demand via the retrieval tools.
Trades a larger upfront context cost for cheap long conversations. An analyst can refine a dashboard over many turns without the token bill exploding.
Production-grade polish
- Token-flush batching: incoming stream tokens are coalesced via
requestAnimationFramebefore they reach React state, so high-rate token streams don't cause per-token re-renders. - Feedback signal: thumbs up/down per assistant message is persisted and keyed to the session/thread, usable for offline eval and drift tracking.
- Suggested prompts: pre-computed per view to steer users toward queries the agent handles well.
Stack
- OpenAI Assistants API, running in a separate LLM microservice
- Cube.js as the semantic layer and query target
- Server-sent events for streaming text, tool calls, and tool results
- React client with a side-panel chat UI and live dashboard render