---
id: object/codeunit/4321
type: object
title: Codeunit 4321 "Agent"
summary: Codeunit 4321 "Agent" in System Application (System.Agents). 30 public procedures. Introduced in BC25, still in BC30, changed in BC27-29.
tier: official
language: en
tags:
  - codeunit
  - system application
versions:
  introduced: "25"
  last_changed: "29"
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 1ca8a83078991191ede7c92413ba04150f313dc9abeea3b571a343150e2d54d2
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/Agent/Setup/Agent.Codeunit.al
    title: src/System Application/App/Agent/Setup/Agent.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/11040
    - change/bcapps/8967
object_type: codeunit
object_id: 4321
name: Agent
namespace: System.Agents
app: System Application
extends: null
first_version: "25"
last_version: "30"
present_in:
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "27"
  - "28"
  - "29"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 30
  events: 0
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 1
  called_by: 23
  implements: 0
---

# Codeunit 4321 "Agent"

> Codeunit 4321 "Agent" in System Application (System.Agents). 30 public procedures. Introduced in BC25, still in BC30, changed in BC27-29.

System Application · System.Agents · BC25-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/Agent/Setup/Agent.Codeunit.al) · facts from BC29

## Procedures

- `Create(AgentMetadataProvider: Enum "Agent Metadata Provider"; var UserName: Code[50]; UserDisplayName: Text[80]; var TempAgentAccessControl: Record "Agent Access Control" temporary): Guid`: Creates a new agent. The agent will be in the disabled state, with the users that can interact with the agent setup.
- `Activate(AgentUserSecurityID: Guid)`: Activates the agent
- `Deactivate(AgentUserSecurityID: Guid)`: Deactivates the agent
- `Archive(AgentUserSecurityID: Guid)`: Archives the agent. Archiving removes the agent from active use and cannot be undone. The agent must be inactive (deactivated) before it can be archived.
- `IsArchivingSupported(AgentUserSecurityID: Guid): Boolean`: Checks if the agent type supports archiving.
- `IsArchived(AgentUserSecurityID: Guid): Boolean`: Checks if the agent is archived.
- `GetDisplayName(AgentUserSecurityID: Guid): Text[80]`: Get the display name of the agent.
- `GetUserName(AgentUserSecurityID: Guid): Code[50]`: Get the user name of the agent.
- `SetDisplayName(AgentUserSecurityID: Guid; DisplayName: Text[80])`: Sets the display name of the agent.
- `GetModelId(AgentUserSecurityID: Guid): Code[30]`: Gets the model ID of the agent.
- `GetModelName(AgentUserSecurityID: Guid): Text[70]`: Gets the model name of the agent.
- `SetModelId(AgentUserSecurityID: Guid; ModelId: Code[30])`: Sets the model ID of the agent.
- `SetModelIdToAuto(AgentUserSecurityID: Guid)`: Sets the agent model to auto mode, meaning the agent will use the default agent model.
- `SetInstructions(AgentUserSecurityID: Guid; Instructions: SecretText)`: Set the instructions which agent will use to complete the tasks.
- `IsActive(AgentUserSecurityID: Guid): Boolean`: Checks if the agent is active.
- `PopulateDefaultProfile(ProfileID: Text[30]; ProfileAppID: Guid; var TempAllProfile: Record "All Profile" temporary)`: Populates the temporary profile record with the specified information.
- `SetProfile(AgentUserSecurityID: Guid; ProfileID: Text; ProfileAppID: Guid)`: Assigns the profile to the agent.
- `UpdateLocalizationSettings(AgentUserSecurityID: Guid; LanguageID: Integer; LocaleID: Integer; TimeZone: Text[180])`: Updates the Language, Regional Settings and Time Zone for the agent.
- `GetUserSettings(AgentUserSecurityID: Guid; var UserSettingsRec: Record "User Settings")`: Gets the user settings for the agent. Few properties are retrieved, like: Profile, Language, Regional Settings and Time Zone.
- `UpdateAccessControl(AgentUserSecurityID: Guid; var TempAccessControlBuffer: Record "Access Control Buffer" temporary)`: Assigns one or multiple permission sets to the agent. The assignment overrides any existing permission sets.
- `GetAccessControl(AgentUserSecurityID: Guid; var TempAccessControlBuffer: Record "Access Control Buffer" temporary)`: Gets the permission sets assigned to the agent.
- `GetAgentAccessControl(AgentUserSecurityID: Guid; var TempAgentAccessControl: Record "Agent Access Control" temporary)`: Gets the users that can manage or give tasks to the agent.
- `UpdateAgentAccessControl(AgentUserSecurityID: Guid; var TempAgentAccessControl: Record "Agent Access Control" temporary)`: Sets the users that can manage or give tasks to the agent. Existing set of users will be replaced with a new set.
- `SetProfile(AgentUserSecurityID: Guid; var AllProfile: Record "All Profile")`: Assigns the profile to the agent.
- `ProfileLookup(var UserSettingsRec: Record "User Settings"): Boolean`: Allows the user to select the new profile for given User Settings for an agent.
- `UpdateLocalizationSettings(AgentUserSecurityID: Guid; var NewUserSettings: Record "User Settings")`: Updates the Language, Regional Settings and Time Zone for the agent.
- `GetUserAccess(AgentUserSecurityID: Guid; var TempAgentAccessControl: Record "Agent Access Control" temporary)`: Gets the users that can manage or give tasks to the agent.
- `AssignPermissionSet(AgentUserSecurityID: Guid; var TempAccessControlBuffer: Record "Access Control Buffer" temporary)`: Assigns the permission set to the agent.
- `UpdateAccess(AgentUserSecurityID: Guid; var TempAgentAccessControl: Record "Agent Access Control" temporary)`: Sets the users that can manage or give tasks to the agent. Existing set of users will be replaced with a new set.
- `OpenSetupPageId(AgentMetadataProvider: Enum "Agent Metadata Provider"; AgentUserSecurityID: Guid)`: Opens the setup page for the specified agent.

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 4301 "Agent Impl."](../codeunit/4301.md) (27 calls: `Activate → Activate`, `Archive → Archive`, `AssignPermissionSet → AssignPermissionSets`, …)

## Called by

- [Codeunit 4325 "Agent Setup Impl."](../codeunit/4325.md) (8 calls: `CreateAgent → Create`, `CreateAgent → UpdateLocalizationSettings`, `GetSetupRecord → GetUserAccess`, …)
- [Codeunit 4350 "Custom Agent Setup"](../codeunit/4350.md) (4 calls: `CreateAgent → Activate`, `CreateAgent → Deactivate`, `GetDefaultProfile → PopulateDefaultProfile`, …)
- [Codeunit 4356 "Custom Agent Import"](../codeunit/4356.md) (4 calls: `CreateAgent → SetProfile`, `CreateAgent → UpdateLocalizationSettings`, `ReplaceExistingAgent → SetDisplayName`, …)
- [Codeunit 4400 "SOA Setup"](../codeunit/4400.md) (4 calls: `GetDefaultAgentAccessControl → GetUserAccess`, `GetDefaultProfile → PopulateDefaultProfile`, `LogTelemetry → GetUserSettings`, …)
- [Page 4350 "Custom Agent Setup"](../page/4350.md) (4 calls: `ApplyUserSettingsValues → SetProfile`, `InitModelDisplay → GetModelId`, `InitModelDisplay → GetModelName`, …)
- [Codeunit 3307 "Payables Agent Setup"](../codeunit/3307.md) (2 calls: `ApplyAgentInstructions → SetInstructions`, `GetDefaultProfile → PopulateDefaultProfile`)
- [Codeunit 4357 "Custom Agent"](../codeunit/4357.md) (2 calls: `GetCustomAgentById → GetUserName`, `GetCustomAgents → GetUserName`)
- [Codeunit 3313 "PA Annotation"](../codeunit/3313.md) (1 call: `GetAgentAnnotations → IsActive`)
- [Codeunit 3314 "PA Agent Task Execution"](../codeunit/3314.md) (1 call: `GetAgentTaskPageContext → GetUserSettings`)
- [Codeunit 4310 "Agent Task Builder Impl."](../codeunit/4310.md) (1 call: `VerifyMandatoryFieldsSet → IsActive`)
- [Codeunit 4352 "Custom Agent Instructions"](../codeunit/4352.md) (1 call: `UpdateInstructionsOnSetupRecord → SetInstructions`)
- [Codeunit 4359 "Custom Agent Profile Mgt"](../codeunit/4359.md) (1 call: `TryGetAgentProfile → GetUserSettings`)
- [Codeunit 4399 "SOA Annotation"](../codeunit/4399.md) (1 call: `GetAgentTaskMessageAnnotations → GetDisplayName`)
- [Codeunit 4584 "SOA Recovery"](../codeunit/4584.md) (1 call: `RunSOARecovery → IsActive`)
- [Codeunit 4586 "SOA Dispatcher"](../codeunit/4586.md) (1 call: `CanRunTask → IsActive`)
- [Codeunit 6978 "Upgrade Expense Agent Setup"](../codeunit/6978.md) (1 call: `ClearStaleCopyCompanyStateIfNeeded → GetUserSettings`)
- [Codeunit 6998 "EA Metadata Provider"](../codeunit/6998.md) (1 call: `GetDefaultProfile → PopulateDefaultProfile`)
- [Page 4315 "Agent Card"](../page/4315.md) (1 call: `OpenSetupPage → OpenSetupPageId`)
- [Page 6942 "Expense Agent Setup API"](../page/6942.md) (1 call: `TryGetAgentUserSettings → GetUserSettings`)
- [Page 6991 "Expense Agent Setup Wizard"](../page/6991.md) (1 call: `FindCompanyAgentUserSecurityID → GetUserSettings`)
- [Page extension 3305 "AgentTaskList"](../pageextension/3305.md) (1 call: `CreatePATask → IsActive`)
- [Page extension 4353 "Agent Card"](../pageextension/4353.md) (1 call: `GetCustomAgentFields → GetModelName`)
- [Table 4310 "Agent Setup Buffer"](../table/4310.md) (1 call: `GetUserSettings → GetUserSettings`)

## Recent changes

- 2026-09-07 [#11040 [Agent Archiving] Payables and Expense agent implementation for IAgentArchiving](../../changes/bcapps/11040.md) (main, BC30, feature)
- 2026-07-28 [#8967 Ability to archive agents](../../changes/bcapps/8967.md) (main, BC30, feature)

## Across versions

- Present in: BC25-30
- Changed (declaration) in: BC27-29

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "Agent")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
