AiAgentDefinition defines an Agentforce agent's shared configuration across all its versions, including its agent category, conversation context variables, runtime user, and logging settings. It is available only when Agents is enabled in the org.
This component is not an individual agent version. Each version is a separate AiAgentDefinitionVersion component. The definition's inherited fullName is the agent's API name, such as MyAgent; version components add a number, such as MyAgent#1 or MyAgent#2. Also distinguish type, which controls the agent's configuration type, from agentType, which provides a separate classification.
Key Elements
| Element | What the Element Controls |
|---|---|
type |
The agent's configuration type. Allowed values are AgentforceOrchestrator, Bot, ExternalCopilot, and InternalCopilot. Always set it explicitly. Omitting it during creation produces a Bot, which Salesforce retrieves as a Bot component. It cannot change after creation. |
agentType |
Required when type is InternalCopilot or ExternalCopilot. For an InternalCopilot agent, it cannot change after creation. Although represented as a string, its documented values are AgentforceEmployeeAgent, Analytics, AppDevAgent, BankingServiceAgent, BuyerAgent, CustomAgent, EinsteinSDR, EinsteinServiceAgent, Employee, ExperienceBuilder, FieldServiceAgent, GoalBasedAgent, GuidedShoppingAgent, LightningAppBuilder, ProspectingAgent, SalesCanvasAgent, SalesDealAgent, SalesEinsteinCoach, ScaleAgent, ServicePlanner, Setup, ShopperAgent, and ThirdPartyA2AAgent. |
agentDSLEnabled |
Whether the agent is defined using Agent Script. Creating an agent with this set to true requires its AiAuthoringBundle in the deployment unless the bundle already exists in the destination org. |
botUser |
The username of the user the agent runs as, not a display name or record ID. The user must be an active standard user with access to the agent. Unsupported when agentType is Employee or AgentforceEmployeeAgent. |
contextVariables |
Defines typed data available during a conversation. Each entry requires dataType, developerName, and label. Allowed dataType values are Boolean, Currency, Date, DateTime, Id, Object, Number, and Text. |
developerName |
The context variable's required, org-unique name. It must start with a letter and contain only letters, numbers, and underscores. It cannot contain spaces, end with an underscore, or contain consecutive underscores. |
includeInPrompt |
Whether a context variable is injected into the prompt sent to the Agentforce model. This is separate from conversation logging. |
description |
The description within a context variable. The Agentforce planner service may use this text; it is not necessarily just an administrative note. |
contextVariableMappings |
Associates a context variable with source data. Each mapping requires fieldName, messageType, and SObjectType. |
messageType |
Identifies the message type to which a mapping applies. The documented values are Alexa, AppleBusinessChat, Custom, Email, EmbeddedMessaging, Facebook, GoogleChat, GoogleHome, InternalCopilot, Line, MsCopilot, Omega, Phone, PstnVoice, Rcs, SipVoice, Slack, Text, Voice, VoiceIntegrationPilot, WebChat, WeChat, WhatsApp, and WhatsAppVoice. See Documentation Inconsistencies for ExternalVoice. |
SObjectType |
Directly under a context variable, identifies the object type of the ID stored in that variable. Inside a mapping, identifies the object type of the ID used in that mapping and is required there. These are different scopes. |
logPrivateConversationData |
Whether private conversation data is logged. It does not control whether a particular context variable is included in a model prompt. |
richContentEnabled |
Whether the agent supports rich content in its responses. |
Behavior and Constraints
Agent classification and runtime user
ExternalCopilot identifies an external-facing agent, such as an Agentforce Service agent. InternalCopilot identifies an internal-facing agent, such as an Agentforce Employee agent. Neither value replaces the separate agentType classification.
The creation-time restrictions matter when correcting an existing agent: type is immutable, and agentType is also immutable for an InternalCopilot agent. Omitting type during creation cannot be corrected by changing that field later.
For agents that support botUser, both the username and the user's eligibility matter. A matching agent API name does not establish that the runtime user exists, is active, is a standard user, or has access to the agent.
Context variables, prompts, and logging
ConversationContextVariable and ConversationContextVariableMapping are nested structures within the definition. They are not the agent's separately named version components. A variable's required label identifies it in the Salesforce user interface; its developerName must be unique across the org.
Viewing, grouping, sorting, and filtering the developerName field requires either View DeveloperName or View Setup and Configuration permission. This field-access rule is not a statement about permission to use the agent.
Prompt inclusion and private-data logging are separate controls. includeInPrompt determines whether a variable enters the model prompt, while logPrivateConversationData controls private conversation logging. A variable's description may also be used by the planner service.
For source mappings, keep the two SObjectType settings distinct. The variable-level value describes the ID stored in the variable; the mapping-level value describes the ID used in that mapping. Setting one does not make it interchangeable with the other.
Deployment and Retrieval
AiAgentDefinition components use the .aiAgentDefinition suffix and reside in the aiAgents folder. For example, the definition for MyAgent is stored as aiAgents/MyAgent.aiAgentDefinition.
- Enable Agents in the destination org. The metadata type is available only when Agents is enabled.
-
Set
typebefore creating the agent. If omitted, Salesforce assignsBotand subsequently retrieves the agent as aBotcomponent rather than anAiAgentDefinitioncomponent. -
Include the Agent Script dependency when required. A new agent with
agentDSLEnabledset totrueneeds itsAiAuthoringBundlein the deployment unless that bundle already exists in the destination org. This is a creation dependency, not a version-naming rule. -
Resolve destination-specific user requirements. Where supported,
botUsermust contain an eligible destination-org username, independently of the agent's API name. -
Account for context-variable name collisions. A
developerNamethat is valid in the source org must still satisfy org-wide uniqueness in the destination.
The definition and its versions have separate component identities: MyAgent identifies the shared definition, while MyAgent#1 identifies a version component. For the agent retrieval and deployment workflow, see Use Metadata to Move an Agent to a New Org.
This type supports the * wildcard in package.xml. See Deploying and Retrieving Metadata with the Zip File for manifest usage.
Relationships
AiAgentDefinition extends Metadata and inherits fullName. Its nested conversation-variable structures belong to the definition rather than to independently named components.
The association with AiAgentDefinitionVersion is name-based: version names combine the agent API name, #, and a version number. This naming relationship is separate from the conditional AiAuthoringBundle deployment dependency for a new Agent Script agent. Bot is also relevant to component identity because an agent created without an explicit type is retrieved as that metadata type.
Documentation Inconsistencies
The exposed messageType enumeration includes ExternalVoice, but Salesforce's documented MessageType value list omits it. This discrepancy does not establish whether the platform accepts ExternalVoice.
Common Questions
Why is my agent retrieved as Bot instead of AiAgentDefinition?
If type was omitted when the agent was created, Salesforce assigned Bot. It then retrieves the agent as a Bot component. The type field cannot be changed after creation.
How are AiAgentDefinition versions named?
The shared definition uses the agent API name, such as MyAgent. Each separate AiAgentDefinitionVersion component adds # and a version number, such as MyAgent#1.
Do I need AiAuthoringBundle when deploying an Agent Script agent?
Yes, when creating a new agent with agentDSLEnabled set to true, unless its AiAuthoringBundle already exists in the destination org.
What value belongs in botUser?
Use the username of an active standard user with access to the agent, not a display name or record ID. botUser is unsupported when agentType is Employee or AgentforceEmployeeAgent.
Does includeInPrompt set to false turn off private conversation logging?
No. includeInPrompt controls a context variable's inclusion in the model prompt. logPrivateConversationData separately controls whether private conversation data is logged.