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 currentDataModel; 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()andhealth.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
Reflects current DataModel state. Re-evaluated on every access.
|
Widget catalogue. Re-evaluated on every access.
|
Static type enumerations available in Studio.
|
Resolved static prose fragments from AgAiStrings.
|
{ page: () => Promise |
Optional description of the overall data model.
|
Tables available in the data model.
|
Relationships between tables in the data model.
|
Widget type identifier.
|
Human-readable display name.
|
What the widget does and when to use it.
|
Optional guidance on how to configure the widget.
|
Optional summary of the widget's configuration options.
|
Recommended minimum and default sizing.
|
Aggregation functions available across the data model.
|
Filter operators available across the data model.
|
Data types recognised by Studio.
|
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.