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

React Embedded AnalyticsContext

Version 2.1.1

getAiContext() returns a structured snapshot of the current Studio state - the data schema, the widget catalogue, the type vocabulary, and dashboard health. It is the raw material for grounding a model: the built-in agents build their instructions from it, and you use the same data when writing Custom Agents or your own Tools.

const ctx = studioApi.getAiContext();

const { tables, relationships } = ctx.schema();
const widgets = ctx.catalogue();
const { aggregations, filterOperators } = ctx.vocabulary;
const pageHealth = await ctx.health.page();

What It Provides Copy Link

  • schema() - data sources, fields (with types, roles, and descriptions), and relationships. Reflects the current DataModel; re-evaluated on every call.
  • catalogue() - the available widget types with descriptions, usage guidance, and default sizing. Re-evaluated on every call.
  • vocabulary - the static enumerations Studio understands: aggregations, filter operators, data types, and field roles.
  • fragments - resolved prose fragments, such as the @table[id] / @field[id] reference syntax for prompts.
  • health - health.page() and health.widget(id) return layout, filter, and configuration issues for the active page or a single widget.

schema() and catalogue() are functions, not fixed values, because the dashboard changes as the user works - call them again to get the current state.

Grounding a Model Copy Link

Feed the parts a request needs into your instructions or prompt. For a data question, the schema and vocabulary are usually enough:

function buildInstructions(api: AgStudioApi): string {
    const { tables } = api.getAiContext().schema();
    const { aggregations } = api.getAiContext().vocabulary;

    return `Answer questions about the loaded data.
Tables: ${tables.map((t) => t.name).join(', ')}.
Available aggregations: ${aggregations.join(', ')}.`;
}

In a Custom Agent, the instructions factory receives the api, so you build instructions the same way. In your own Tools, call getAiContext() to describe the data to the model or to validate arguments before applying a command.

Interface Reference Copy Link

schemaCopy Link
Function
Reflects current DataModel state. Re-evaluated on every access.
catalogueCopy Link
Function
Widget catalogue. Re-evaluated on every access.
vocabularyCopy Link
VocabularyMeta
Static type enumerations available in Studio.
fragmentsCopy Link
FragmentsMeta
Resolved static prose fragments from AgAiStrings.
healthCopy Link
{ page: () => Promise<AgHealthReport>; widget: (widgetId: string) => Promise<AgHealthReport> }
{ page: () => Promise; widget: (widgetId: string) => Promise }
descriptionCopy Link
string
Optional description of the overall data model.
tablesCopy Link
readonly TableMeta[]
Tables available in the data model.
relationshipsCopy Link
readonly RelationshipMeta[]
Relationships between tables in the data model.
string
Widget type identifier.
string
Human-readable display name.
descriptionCopy Link
string
What the widget does and when to use it.
string
Optional guidance on how to configure the widget.
configurationCopy Link
string
Optional summary of the widget's configuration options.
sizingCopy Link
WidgetSizing
Recommended minimum and default sizing.
aggregationsCopy Link
readonly string[]
Aggregation functions available across the data model.
filterOperatorsCopy Link
readonly string[]
Filter operators available across the data model.
dataTypesCopy Link
readonly string[]
Data types recognised by Studio.
fieldRolesCopy Link
readonly string[]
Roles a field can take in a widget.

Next Steps Copy Link

  • Custom Agents - Build agent instructions from context.
  • Toolkit - Use context when building your own tools.