Implementing AI capabilities in custom widgets allows you to extend the functionality of ArcGIS Experience Builder by enabling AI-driven interactions and visualizations. This guide explains how to implement AI capabilities in a custom ArcGIS Experience Builder widget.

AI capabilities overview

You can implement one or more of the following capabilities:

CapabilityUse it to
AI actionsAllow AI to perform tasks using a widget at runtime.
AI rendererAllow AI to display widget-specific content in the chat.
Human inputCollect input from the user during an AI action.

Add AI capabilities to a widget

To add AI capabilities to a custom widget:

  1. Choose the AI capabilities to implement.
  2. Declare the supported capability in the widget's manifest.json file.
  3. Implement the corresponding AI action, renderer, or human input.
  4. Update the widget to reflect changes made by AI when appropriate.
  5. 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

Add the aiActions property to the widget's manifest.json file.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "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:

  • undoName to identify a function that reverses the action.
  • label to provide a display label for the action.
  • useContext to indicate context required by the action.

If you do not provide a label, Experience Builder uses the action name.

To localize an action label, use the following translation key pattern:

Use dark colors for code blocksCopy
1
_ai_action_<actionName>_label

Implement an AI action

In the module referenced by aiActions.uri, 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 AIActionResult that describes the outcome of the operation.

The complete action signature is (widgetId, param, options?). The optional options can contain additional execution data and the human-input response when a previously paused action resumes.

For example:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 = schema

Attach 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 getActions(widgetId) when the actions available to AI depend on the current widget configuration. Return an array of AIAction objects and include the action function in each object.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 getSchema(widgetId) when an action's inputs depend on the current widget configuration. The function can return a schema that reflects the current widget instance.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
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 getSchema 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 undoName in the manifest.

For example:

Use dark colors for code blocksCopy
1
2
3
4
5
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:

Use dark colors for code blocksCopy
1
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

Add the aiRenderer property to the widget's manifest.json file.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
{
  "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 aiRenderer.uri, export an object that implements AIRenderer.

Use a schema to define the information AI must provide to the renderer.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
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 aiRenderer

The 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.aiRendererParams.

In the runtime widget:

  1. Check whether aiRendererParams is available.
  2. Create the data or state needed by the widget from those parameters.
  3. 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 humanInput property to the widget's manifest.json file.

Use dark colors for code blocksCopy
1
2
3
4
5
6
{
  "humanInput": {
    "uri": "runtime/human-input",
    "description": "Let the user choose a layer before continuing."
  }
}

Implement human input

In the module referenced by humanInput.uri, export a default object that implements HumanInput. Define the response shape with a schema.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
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 humanInput

In the runtime widget, use props.humanInputParams to render the control and call props.onResume with a human-readable resultDescription and the structured response. The resumed action receives the response through options.humanInput.payload.

Use dark colors for code blocksCopy
1
2
3
4
5
props.onResume?.({
  resultDescription: `Selected layer: ${layer.title}`,
  layerId: layer.id,
  layerTitle: layer.title
})

Always provide a meaningful resultDescription, including when the user cancels the interaction.

Organize AI capabilities

For example:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
widget-name/
  manifest.json
  src/
    runtime/
      widget.tsx
      ai-actions/
        map-ai-actions.ts
      ai-renderer.ts

Implementation 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 undoName matches an exported undo function.
  • Actions return clear results and update the widget interface when they change its state.
  • AI renderers handle aiRendererParams and present content suited to the chat experience.
  • Human input handles humanInputParams and calls onResume with a meaningful resultDescription, including on cancellation.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.