-
Notifications
You must be signed in to change notification settings - Fork 117
ProGuide Create an AI Assistant Function
Language: C#
Subject: Framework
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: Esri, http://www.esri.com
Date: 04/09/2025
ArcGIS Pro: 3.5
Visual Studio: 2022
This ProGuide explains the step by step process on how to create an AI Assistant Function to extend ArcGIS Pro's AI Assistant
- Prerequisites
- Step 1
- Step 2
- Step 3
- Step 4
- Step 5
- Step 6
- Step 7
- Step 8
- Step 9
- Step 10
- Step 11
- Step 12
Ensure you have the ArcGIS Pro AI Assistant Beta 3.5 installed along with the proapp-sdk-ai-assitant.vsix.
Create a new addin project. Call it CreateLayoutAIFunction
. Store it in the folder of your choice.
From the right-click visual studio project context menu, select "Add->New Item...". Click on the (newly installed) "ArcGIS Pro AI Assistant function (Beta)" item template to create a new AI Assistant Function. Call your AI Assistant Function "CreateDefaultLayout".
The template will have generated a new AI Assistant extension class called CreateDefaultLayoutClass
containing an AI assistant function called CreateDefaultLayout
. We will inspect the code.
internal class CreateDefaultLayoutClass
{
[AIAssistantFunction, Description("CreateDefaultLayout description")]
public static AIFunctionResult CreateDefaultLayout(
[Description("CreateDefaultLayout optionalTextString parameter description")]
string optionalTextString = "")
{
//TODO: CreateDefaultLayout implementation goes here
System.Diagnostics.Debug.WriteLine(
$"Project Name: {Project.Current.Name}. Executing CreateDefaultLayout with parameter {optionalTextString}: {DateTime.Now}");
return new AIFunctionResult("CreateDefaultLayout was executed");
}
}
Some important points of interest: AI assistant functions are declared as public static
. They return type of ArcGIS.Desktop.Internal.Core.Assistant.AIFunctionResult
*. They are decorated with the [AIAssistantFunction, ...]
attribute. This is what identifies a "generic" function as being an "AI Assistant Function". The "default" AI Assistant Function auto-generated by the template also includes an optional function parameter string optionalTextString
. Note that it too has a [Description("...")]
attribute, same as its parent function (whose description is included within the AIAssistantFunction attribute).
We will inspect the Config.daml. Notice that the item template also added registration "code", or "xml", into the Config.daml:
<categories>
<updateCategory refID="esri_core_ai_assistant_extension_category">
<insertComponent id="CreateLayoutAIFunction_CreateLayout" className="CreateDefaultLayoutClass">
<content searchDescription="CreateDefaultLayoutClass description">
<aiAssistantFunction name="CreateDefaultLayout" searchDescription="CreateDefaultLayout description">
<!--<dependencies>-->
<!--Add a dependency AI Assistant Function to your function-->
<!--<dependency refID="esri_mapping_assistant_extension|GetAllLayers"/>-->
<!--</dependencies>-->
</aiAssistantFunction>
</content>
</insertComponent>
</updateCategory>
</categories>
Some important points of interest: AI assistant extension classes and their child AI assistant functions must be registered in the esri_core_ai_assistant_extension_category
category. The registration includes an <insertComponent .../>
element for the class and one <aiAssistantFunction .../>
element per child AI assistant functions. In this case the template generates just a single function: "CreateDefaultLayout" so there is one <aiAssistantFunction .../>
child element in this case. The class name attribute of the insertComponent element must match the class name of the extension function - "CreateDefaultLayoutClass" in this case. The name attribute on the aiAssistantFunction element must match the name of the AI assistant function - "CreateDefaultLayout" in this case. We will be changing the various "description" attributes in the following steps.
We are going to add the code to our function to generate a default layout (via the AI Assistant). First, change the signature of the AI Assistant function as follows:
[AIAssistantFunction, Description("Create a default layout using the current map")]
public static async Task<AIFunctionResult> CreateDefaultLayout(
[Description("The optional name of the layout")]
string layoutName = "Default Layout")
{
Note these changes:
- The function description attribute has been changed to "Create a default layout using the current map". This is important. This description will be used by the LLM to determine the purpose of our function.
- The parameter description has been changed to "The optional name of the layout" which will also be used by the LLM to determine the purpose of the parameter - i.e. to allow a user to specify the name of the layout. Note also that, if no name is provided, it defaults to "Default Layout".
- We changed the return type from
AIFunctionResult
toTask<AIFunctionResult>
reflecting that this particular method will be asynchronous. This is always usually going to be the case as most of the Pro SDK public api requires use of aQueuedTask
.
Add the layout generation code to the body of the method. This is "standard" layout creation code using LayoutFactory
and ElementFactory
same as would any other addin code needed for layout generation. Note also the use of QueuedTask
.
[AIAssistantFunction, Description("Create a default layout using the current map")]
public static async Task<AIFunctionResult> CreateDefaultLayout(
[Description("The optional name of the layout")]
string layoutName = "Default Layout")
{
//Get the active map view.
var map = MapView.Active.Map;
var layout = await QueuedTask.Run(() =>
{
var layout = LayoutFactory.Instance.CreateLayout(8.5, 11, LinearUnit.Inches);
layout.SetName(layoutName);
//Add a map frame
var mf_env = EnvelopeBuilderEx.CreateEnvelope(0.77, 1.3, 7.7, 9.7);
var mf = ElementFactory.Instance.CreateMapFrameElement(
layout, mf_env, map, "Default Map", false);
//Add a title
var title_sym = SymbolFactory.Instance.ConstructTextSymbol(
ColorFactory.Instance.BlackRGB, 36, "AvenirNext LT Pro Medium", "Italic");
var title_text = new Coordinate2D(0.77, 9.7);
ElementFactory.Instance.CreateTextGraphicElement(
layout, TextType.PointText, title_text.ToMapPoint(), title_sym,
layoutName, "Title Text1", false);
//Add a north arrow
var na_frame = EnvelopeBuilderEx.CreateEnvelope(7.1, 1.3, 7.7, 1.9);
var north_arrow_info = new NorthArrowInfo()
{
MapFrameName = mf.Name
};
ElementFactory.Instance.CreateMapSurroundElement(
layout, na_frame, north_arrow_info, "", false,
new ElementInfo() { Anchor = Anchor.BottomRightCorner});
//Add a scale bar
var sb_frame = EnvelopeBuilderEx.CreateEnvelope(3.09, 0.914, 5.4, 1.41);
var sbar_info = new ScaleBarInfo()
{
MapFrameName = mf.Name
};
ElementFactory.Instance.CreateMapSurroundElement(
layout, sb_frame, sbar_info, "", false,
new ElementInfo() { Anchor = Anchor.BottomMidPoint});
return layout;
});
//GUI thread
await FrameworkApplication.Current.Dispatcher.InvokeAsync(async () =>
{
await ProApp.Panes.CreateLayoutPaneAsync(layout);
});
return new AIFunctionResult("Layout created and opened");
}
We are going to update the <aiAssistantFunction .../>
element. Change the searchDescription
to "Create a default layout from the current map". This is the same description as was used for the function description in the code behind. Note that the searchDescription and Description don't always necessarily have to be the same (i.e. "identical") - even though they are in this case. The searchDescription in the Config.daml is used in a semantic search "upfront" by the AI Assistant to determine the purpose of your function whereas the Description in the code-behind is used by the LLM when it infers your method's usage and relevance in relation to a given user's chat entry. Next we will add the condition "esri_mapping_mapPane" to the <aiAssistantFunction .../>
element to enable/disable it if there is/is not a map available. Here is the updated Config.daml.
<updateCategory refID="esri_core_ai_assistant_extension_category">
<insertComponent ...>
<content ...>
<aiAssistantFunction name="CreateDefaultLayout"
searchDescription="Create a default layout from the current map"
condition="esri_mapping_mapPane">
...
</aiAssistantFunction>
Compile and fix any errors.
Run the addin in the debugger. Open any Pro project and make sure that it has an active map (otherwise your function method will be disabled). Open the AI Assistant dockpane. You will find it on the Help tab.
Start a "Pro AI Assistant action session". This will switch the AI Assistant from executing Pro Help (the default) in response to your chat entries to executing Pro actions (as implemented by AI assistant functions). You can initiate an action session either via the burger button "AI-Assisted Pro Actions" option or by clicking the "Actions - Help me perform an action" button.
Type into the chat "Please create a default layout using the current map". Hit enter. You should see a new layout pane generated (via your ai assistant function). Feel free to experiment with different phrasing and specifying a title string, or not.
Home | API Reference | Requirements | Download | Samples
- Overview of the ArcGIS Pro SDK
- What's New for Developers at 3.5
- Installing ArcGIS Pro SDK for .NET
- Release notes
- Resources
- Pro SDK Videos
- ProSnippets
- ArcGIS Pro API
- ProGuide: ArcGIS Pro Extensions NuGet
Migration
- ProConcepts: Framework
- ProConcepts: Asynchronous Programming in ArcGIS Pro
- ProConcepts: Advanced topics
- ProGuide: How to Increment Addin Version Number
- ProGuide: Custom settings
- ProGuide: Command line switches for ArcGISPro.exe
- ProGuide: Reusing ArcGIS Pro Commands
- ProGuide: Licensing
- ProGuide: Digital signatures
- ProGuide: Command Search
- ProGuide: Keyboard shortcuts
- ProSnippets: Framework
- ProSnippets: DAML
Add-ins
- ProConcepts: Localization
- ProGuide: Installation and Upgrade
- ProGuide: Your first add-in
- ProGuide: ArcGIS AllSource Project Template
- ProGuide: Content and Image Resources
- ProGuide: Embedding Toolboxes
- ProGuide: Diagnosing ArcGIS Pro Add-ins
- ProGuide: Regression Testing
Configurations
Customization
- ProGuide: The Ribbon, Tabs and Groups
- ProGuide: Buttons
- ProGuide: Label Controls
- ProGuide: Checkboxes
- ProGuide: Edit Boxes
- ProGuide: Combo Boxes
- ProGuide: Context Menus
- ProGuide: Palettes and Split Buttons
- ProGuide: Galleries
- ProGuide: Dockpanes
- ProGuide: Code Your Own States and Conditions
- ProGuide: Command Filter
Styling
- ProConcepts: Project Content and Items
- ProConcepts: Custom Items
- ProGuide: Custom Items
- ProGuide: Custom browse dialog filters
- ProSnippets: Content
- ProSnippets: Browse Dialog Filters
- ArcGIS Pro TypeID Reference
- ProConcepts: Editing
- ProConcepts: COGO
- ProConcepts: Annotation Editing
- ProConcepts: Dimension Editing
- ProGuide: Editing Tool
- ProGuide: Sketch Tool With Halo
- ProGuide: Construction Tools with Options
- ProGuide: Annotation Construction Tools
- ProGuide: Annotation Editing Tools
- ProGuide: Knowledge Graph Construction Tools
- ProGuide: Templates
- ProSnippets: Editing
3D Analyst Data
Plugin Datasources
Topology
Linear Referencing
Object Model Diagram
- ProConcepts: Geometry
- ProConcepts: Multipatches
- ProGuide: Building Multipatches
- ProSnippets: Geometry
- ProSnippets: Geometry Engine
Relational Operations
- ProConcepts: Knowledge Graph
- ProGuide: Knowledge Graph Construction Tools
- ProSnippets: Knowledge Graph
Reports
Presentations
- ProConcepts: Map Authoring
- ProConcepts: Annotation
- ProConcepts: Dimensions
- ProGuide: Tray buttons
- ProGuide: Custom Dictionary Style
- ProGuide: Geocoding
- ProSnippets: Map Authoring
- ProSnippets: Annotation
- ProSnippets: Charts
- ProSnippets: Labeling
- ProSnippets: Renderers
- ProSnippets: Symbology
- ProSnippets: Text Symbols
3D Analyst
CIM
Graphics
Scene
Stream
Voxel
- ProConcepts: Map Exploration
- ProGuide: Map Pane Impersonation
- ProGuide: TableControl
- ProSnippets: Map Exploration
- ProSnippets: Custom Pane with Contents
Map Tools
- ProGuide: Feature Selection
- ProGuide: Identify
- ProGuide: MapView Interaction
- ProGuide: Embeddable Controls
- ProGuide: Custom Pop-ups
- ProGuide: Dynamic Pop-up Menu
Network Diagrams
- ProConcepts: Workflow Manager
- ProSnippets: Workflow Manager
- ProConcepts: Workflow Manager Classic (deprecated)
- ArcGIS Pro API Reference Guide
- ArcGIS Pro SDK (pro.arcgis.com)
- arcgis-pro-sdk-community-samples
- ArcGISPro Registry Keys
- ArcGIS Pro DAML ID Reference
- ArcGIS Pro Icon Reference
- ArcGIS Pro TypeID Reference
- ProConcepts: Distributing Add-Ins Online
- ProConcepts: Migrating to ArcGIS Pro
- FAQ
- Archived ArcGIS Pro API Reference Guides
- Dev Summit Tech Sessions