AG Studio: Build dashboards using native components in web apps. Join us for a webinar on 28th July at 2pm UTC+1 Register

Vue Embedded AnalyticsAI Toolkit

The AI Toolkit exposes Studio's built-in AI commands as standalone, framework-agnostic units so you can plug them into your own LLM harness.

Each command ships a JSON Schema describing its inputs and an apply() function that validates input, mutates state (or runs a query), and returns a success or failure result.

Retrieving a Built-In Command Copy Link

Pass an AgBuiltInAiCommandRef to api.defineAiCommand:

const command = api.defineAiCommand({ type: 'AgExecuteQueryCommand' });

const schema = command.toJSONSchema();   // hand to your harness as a tool definition
const result = await command.apply(args); // { success: true, value } | { success: false, error }

Commands carrying configuration take a params field. AgConfigureWidgetCommand narrows its schema by widget type:

const configureBar = api.defineAiCommand({
    type: 'AgConfigureWidgetCommand',
    params: { widgetType: 'bar-chart-grouped' },
});

Name, description, status text, and any other harness related requirements must be implemented by you. It also allows you to add actions when executing, such as extra validation you wish to add, or changing the return value.For example:

import { tool } from 'your-ai-harness';

const executeQueryCommand = api.defineAiCommand({ type: 'AgExecuteQueryCommand' });

const executeQueryTool = tool({
  name: 'execute_query',
  description: 'Query the full dataset available',
  schema: executeQueryCommand.toJSONSchema(),
  execute: async (params) => {
    const result = await executeQueryCommand.apply(params);

    if (!result.success) {
        return result;
    }

    // Trim results to 50 so as to avoid overwhelming the context
    return result.value.slice(0, 50)
  },
});

Built-In Commands Copy Link

Ref typeWhat it does
AgExecuteQueryCommandRun a query against the data source. Supports aggregation (group-by with measures) and projection (raw row selection).
AgAddPageFilterCommandAppend a filter to the page-level filter list.
AgRemovePageFilterCommandRemove a page-level filter, matching by its current state.
AgAddWidgetFilterCommandAdd a filter scoped to a single widget.
AgRemoveWidgetFilterCommandRemove a widget-level filter, matching by its current state.
AgAddWidgetCommandAdd a widget to the canvas.
AgPositionWidgetCommandMove or resize a widget. Omitted position fields preserve current values.
AgRemoveWidgetCommandPermanently remove a widget from the page.
AgConfigureWidgetCommandConfigure a widget's data mapping, title, and formatting. Schema narrows by params.widgetType.

Each button below sends a hardcoded prompt to OpenAI along with the matching command's JSON Schema as a single forced tool. The LLM returns tool arguments, which we hand straight to command.apply(). The console shows the message, schema, returned args, and command result for every command applied.

JSON Schema Support Copy Link

AG Studio generates JSON Schema Draft 2020-12. However some LLM providers and harnesses do not support all the features available in this version. In these cases you may need to modify the schema accordingly.

Here are some common gotcha's when trying to accomodate different harnesses:

  • Optional parameters: Some LLMs do not allow optional fields in the JSON Schema and require every parameter is in the required array. To accomodate this you can create a union with null or some sentinel value and then decode the result.
  • Nesting depth: Some LLMs only support a limited nesting depth in Schemas. We use $defs and $ref to mitigate this however you may still need to break up the schema smaller as needed.
  • Root schema: Some of our commands produce a union of options as the root of the schema. However some LLM providers only support an object at the root. In these cases you should wrap the schema and then unwrap the returned params before applying.