Skip to content

LLM Agent for <perspective-viewer> - #3209

Merged
texodus merged 1 commit into
masterfrom
agent-component
Aug 7, 2026
Merged

LLM Agent for <perspective-viewer>#3209
texodus merged 1 commit into
masterfrom
agent-component

Conversation

@texodus

@texodus texodus commented Aug 7, 2026

Copy link
Copy Markdown
Member

This PR adds a first-party LLM agent to <perspective-viewer>: a chat sidebar tab and a JavaScript API that let a model drive the viewer through its own public API: reading the schema, writing the ViewerConfig, choosing a plugin, authoring ExprTK expressions and managing panels.

Screenshot 2026-08-06 at 11 47 26 PM

The feature is opt-in at runtime. The Chat tab stays hidden and no network request is ever made until the host calls agentConfig().

import { providers } from "@perspective-dev/viewer";
import docs from "@perspective-dev/viewer/dist/docs/perspective-docs.json" with { type: "json" };

viewer.agentConfig({ ...providers.anthropic, apiKey: "sk-ant-...", docs });
await viewer.agentPrompt("Show me Sales by Region as a bar chart");

Added

Element API agentConfig(config), agentPrompt(text) (resolves with the final answer once tool calls have been applied), and agentReset(). Tool activity fires perspective-agent-tool CustomEvents.

Chat sidebar tab Streams tokens (with automatic fallback), streams reasoning-model reasoning_content into a collapsible display-only block that follows its own tail, renders assistant markdown, and shows tool calls.

OpenAI compatible A "provider" is a plain spreadable Object; src/ts/providers.ts ships presets for anthropic, gemini, openai, openrouter, lmstudio and ollama, and anything OpenAI-compatible works without one. engine accepts an in-page engine (WebLLM's MLCEngine), so the agent can run entirely on-device or be proxied to a private model.

Documentation bundle — the build emits dist/docs/perspective-docs.json (~300 KB) containing a BM25-searchable corpus built from docs/md plus authored plugin-config reference files, and generated JSON schemas for ViewerConfigUpdate / ViewerConfigInitial. Passing it as docs powers the search_docs tool and upgrades the config tools' parameter schemas from permissive objects to the real generated ones. Hosts can append their own
{title, text} entries to teach the agent additional context about the data itself, or override/audit the documentation bundle entirely.

Docs and New Examples

  • docs/md/how_to/javascript/agent.md — new guide covering connection, in-page engines, the docs bundle, teaching the agent about your data.
  • Substantial updates to viewer.md, events.md, save_restore.md, expressions.md, advanced.md, schema.md, FAQ.md and a new windows.md - these are both user-facing improvements and the agent's retrieval corpus, so gaps in them are gaps in the agent.
  • examples/blocks/src/agent/ — a runnable demo with a provider modal (OpenAI-compatible, Anthropic, Gemini, WebLLM), dataset-specific corpus entries, and notes on the WebLLM caveats (Hermes-only tool calling).

Signed-off-by: Andrew Stein <steinlink@gmail.com>
@texodus texodus added the enhancement Feature requests or improvements label Aug 7, 2026
@texodus
texodus merged commit 74ed445 into master Aug 7, 2026
17 checks passed
@texodus
texodus deleted the agent-component branch August 7, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature requests or improvements

Development

Successfully merging this pull request may close these issues.

1 participant