Implementing AI capabilities in custom widgets allows you to extend the functionality of ArcGIS Experience Builder
AI capabilities overview
You can implement one or more of the following capabilities:
| Capability | Use it to |
|---|---|
| AI actions | Allow AI to perform tasks using a widget at runtime. |
| AI renderer | Allow AI to display widget-specific content in the chat. |
| Human input | Collect input from the user during an AI action. |
Add AI capabilities to a widget
To add AI capabilities to a custom widget:
- Choose the AI capabilities to implement.
- Declare the supported capability in the widget's
manifest.jsonfile. - Implement the corresponding AI action, renderer, or human input.
- Update the widget to reflect changes made by AI when appropriate.
- Test the behavior in the runtime experience.
Design actions around complete user tasks, as described in Expose capabilities, not UI interactions.
Add runtime AI actions
In this section, you will learn how to:
- Declare AI actions in the widget's
manifest.jsonfile. - Implement the corresponding AI action module.
- Support dynamic actions and schemas when they depend on the widget configuration.
- Add undo behavior for AI actions.
- Provide dynamic descriptions for AI actions.
Declare AI actions
Add the ai property to the widget's manifest.json file.
{
"aiActions": {
"uri": "runtime/ai-actions/map-ai-actions",
"description": "Provide map actions for the map widget.",
"actions": [
{
"name": "zoomToDataSources",
"undoName": "undoZoomToDataSources",
"useContext": ["DATA_SOURCE"],
"description": "Zoom map to specified data sources."
},
{
"name": "getMapExtent",
"description": "Get current map extent and return it as a data source."
}
]
}
}The uri value identifies the module that implements the actions and is relative to the widget's src directory.
Each value specified by name must match a named function exported by the module.
You can optionally specify:
undoto identify a function that reverses the action.Name labelto provide a display label for the action.useto indicate context required by the action.Context
If you do not provide a label, Experience Builder uses the action name.
To localize an action label, use the following translation key pattern:
_ai_action_<actionName>_labelImplement an AI action
In the module referenced by ai, export a function for each action defined in the manifest.
Define the parameters that AI can provide using a zod schema from jimu-ai. The action returns an AI that describes the outcome of the operation.
The complete action signature is (widget. The optional options can contain additional execution data and the human-input response when a previously paused action resumes.
For example:
import { type AIActionResult, OutputType } from 'jimu-core'
import { zod as z } from 'jimu-ai'
const schema = z.object({
dataSourceIds: z.array(z.string()).min(1)
})
export async function zoomToDataSources(
widgetId: string,
param: z.infer<typeof schema>
): Promise<AIActionResult> {
// Perform the widget operation.
return {
status: 'completed',
output: {
type: OutputType.MESSAGE,
payload: `Zoomed widget ${widgetId} to ${param.dataSourceIds.length} data sources.`
},
description: 'Zoomed map to target data sources.'
}
}
zoomToDataSources.schema = schemaAttach the schema to the action function so AI can determine the inputs that the action supports. When an action changes the widget's state, update the widget interface to reflect the result.
Support dynamic actions and schemas
Use get when the actions available to AI depend on the current widget configuration. Return an array of AI objects and include the action function in each object.
import { AIActionType, type AIAction } from 'jimu-core'
export function getActions(widgetId: string): AIAction[] {
if (!canZoom(widgetId)) return []
return [{
id: 'zoomToDataSources',
widgetId,
type: AIActionType.AI_ACTION,
name: 'zoomToDataSources',
description: 'Zoom the map to specified data sources.',
fn: zoomToDataSources
}]
}Use get when an action's inputs depend on the current widget configuration. The function can return a schema that reflects the current widget instance.
function getZoomSchema(widgetId: string) {
const maxDataSources = getConfiguredDataSourceCount(widgetId) || 1
return z.object({
dataSourceIds: z.array(z.string()).min(1).max(maxDataSources)
})
}
zoomToDataSources.getSchema = async (widgetId: string) => getZoomSchema(widgetId)Use a static schema when the action always accepts the same inputs. Use get instead when the valid inputs change with the widget configuration.
Add undo behavior
If an action can be reversed, provide an undo function and reference it with undo in the manifest.
For example:
export async function undoZoomToDataSources(
undoPayload: unknown
): Promise<void> {
// Restore the previous state.
}Use undo behavior when reversing the action provides a meaningful user experience.
Provide dynamic descriptions
You can provide descriptions that reflect the current widget instance.
An action can expose a description based on the widget ID and widget label:
actionFn.description(widgetId, widgetLabel)The action module can also provide a group-level description for its actions. Use clear descriptions to help AI determine when an action is appropriate.
Add an AI renderer
In this section, you will learn how to:
- Declare an AI renderer in the widget's manifest.
- Define the inputs for the AI renderer using a schema.
- Handle the parameters passed to the AI renderer in the runtime widget.
Declare an AI renderer
Add the ai property to the widget's manifest.json file.
{
"aiRenderer": {
"uri": "runtime/ai-renderer",
"description": "Render chart analysis from feature records.",
"supportInput": false
}
}The uri value identifies the module that defines the renderer.
Define renderer inputs
In the module referenced by ai, export an object that implements AI.
Use a schema to define the information AI must provide to the renderer.
import { zod as z } from 'jimu-ai'
import type { AIRenderer } from 'jimu-core'
const schema = z.object({
dataSourceId: z.string(),
title: z.string().nullable()
}).strict()
const aiRenderer: AIRenderer = {
schema
}
export default aiRendererThe schema defines the inputs AI can use when selecting and displaying the renderer.
Handle AI renderer parameters
When AI selects the renderer, the widget receives parameters through props.ai.
In the runtime widget:
- Check whether
aiis available.Renderer Params - Create the data or state needed by the widget from those parameters.
- Render the appropriate content for the chat experience.
Consider simplifying the widget when it is displayed as an AI renderer. For example, disable interactions that are unnecessary in the chat experience. Use human input when AI needs the user to provide an interactive response; do not use an AI renderer for this purpose.
Add human input
To collect a response and resume a paused AI action, declare a human input module, define its response schema, and handle the interaction in the runtime widget.
Declare human input
Add the human property to the widget's manifest.json file.
{
"humanInput": {
"uri": "runtime/human-input",
"description": "Let the user choose a layer before continuing."
}
}Implement human input
In the module referenced by human, export a default object that implements Human. Define the response shape with a schema.
import { zod as z } from 'jimu-ai'
import type { HumanInput } from 'jimu-core'
const humanInput: HumanInput = {
schema: z.object({
layerId: z.string(),
layerTitle: z.string()
}).strict()
}
export default humanInputIn the runtime widget, use props.human to render the control and call props.on with a human-readable result and the structured response. The resumed action receives the response through options.human.
props.onResume?.({
resultDescription: `Selected layer: ${layer.title}`,
layerId: layer.id,
layerTitle: layer.title
})Always provide a meaningful result, including when the user cancels the interaction.
Organize AI capabilities
For example:
widget-name/
manifest.json
src/
runtime/
widget.tsx
ai-actions/
map-ai-actions.ts
ai-renderer.tsImplementation best practices
When adding AI capabilities to a widget:
- Define strict schemas for supported inputs and reject ambiguous or unsupported values.
- Update the widget interface when an AI action changes widget state.
Validation checklist
Before publishing a widget with AI capabilities, verify that:
- The manifest declares each supported capability, and its module URI is valid.
- Each action has a matching exported function, a schema, and a clear description; each
undomatches an exported undo function.Name - Actions return clear results and update the widget interface when they change its state.
- AI renderers handle
aiand present content suited to the chat experience.Renderer Params - Human input handles
humanand callsInput Params onwith a meaningfulResume result, including on cancellation.Description