---
id: object/codeunit/7763
type: object
title: Codeunit 7763 "AOAI Chat Messages"
summary: Codeunit 7763 "AOAI Chat Messages" in System Application (System.AI). 37 public procedures. Present since at least BC23, still in BC30, changed in BC24-25, BC27-28.
tier: official
language: en
tags:
  - codeunit
  - system application
versions:
  introduced: null
  last_changed: "28"
  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: f424d44c7ec107ba830b561094800dfc03898b7dd9123d5e053caee601abc58d
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/AI/src/Azure%20OpenAI/Chat%20Completion/AOAIChatMessages.Codeunit.al
    title: src/System Application/App/AI/src/Azure OpenAI/Chat Completion/AOAIChatMessages.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
object_type: codeunit
object_id: 7763
name: AOAI Chat Messages
namespace: System.AI
app: System Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "24"
  - "25"
  - "27"
  - "28"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 37
  events: 0
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 2
  called_by: 14
  implements: 0
---

# Codeunit 7763 "AOAI Chat Messages"

> Codeunit 7763 "AOAI Chat Messages" in System Application (System.AI). 37 public procedures. Present since at least BC23, still in BC30, changed in BC24-25, BC27-28.

System Application · System.AI · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/System%20Application/App/AI/src/Azure%20OpenAI/Chat%20Completion/AOAIChatMessages.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Access | Public |

## Procedures

- `SetPrimarySystemMessage(Message: SecretText)`: Sets the system message which is always at the top of the chat messages history provided to the model.
- `AddSystemMessage(NewMessage: Text)`: Adds a system message to the chat messages history.
- `AddUserMessage(NewMessage: Text)`: Adds a user message to the chat messages history.
- `AddUserMessage(NewMessage: Text; NewName: Text[2048])`: Adds a user message to the chat messages history.
- `AddUserMessage(AOAIUserMessage: Codeunit "AOAI User Message")`: Adds a user message with structured content parts to the chat messages history.
- `AddUserMessage(AOAIUserMessage: Codeunit "AOAI User Message"; NewName: Text[2048])`: Adds a user message with structured content parts to the chat messages history.
- `AddAssistantMessage(NewMessage: Text)`: Adds a assistant message to the chat messages history.
- `AddToolCalls(ToolCalls: JsonArray)` (internal): Adds a assistant message containing the tool calls returned from the model to the chat messages history.
- `AddToolMessage(ToolCallId: Text; FunctionName: Text; FunctionResult: Text)`: Adds a tool result to the chat messages history.
- `ModifyMessage(Id: Integer; NewMessage: Text; NewRole: Enum "AOAI Chat Roles"; NewName: Text[2048])`: Modifies a message in the chat messages history.
- `DeleteMessage(Id: Integer)`: Deletes a message from the chat messages history.
- `GetHistory(): List of [Text]`: Gets the history of chat messages.
- `GetHistoryNames(): List of [Text[2048]]`: Gets the history names of chat messages.
- `GetHistoryRoles(): List of [Enum "AOAI Chat Roles"]`: Gets the history roles of chat messages.
- `GetLastMessage(): Text`: Gets the last chat message.
- `GetLastRole(): Enum "AOAI Chat Roles"`: Gets the last chat message role.
- `GetLastName(): Text[2048]`: Gets the last chat message name.
- `GetLastToolCalls(): JsonArray`: Gets a copy of the last chat message tool calls array.
- `SetHistoryLength(NewLength: Integer)`: Set the length of history that is used by the model.
- `AssembleHistory(var SystemMessageTokenCount: Integer; var MessagesTokenCount: Integer): JsonArray` (internal): Prepares the history of messages to be sent to the deployment model.
- `GetHistoryTokenCount(): Integer`: Gets the number of tokens used by the primary system messages and all other messages.
- `AddTool(Function: Interface "AOAI Function")`: Adds a function to the payload.
- `DeleteFunctionTool(Name: Text): Boolean`: Deletes a Function from the list of Functions.
- `ClearTools()`: Remove all tools.
- `GetFunctionTool(Name: Text; var Function: Interface "AOAI Function"): Boolean`: Gets the function associated with the specified name.
- `GetFunctionTools(): List of [Text]`: Gets the list of names of Function Tools that have been added.
- `ToolsExists(): Boolean`: Checks if at least one Tools exists in the list.
- `SetAddToolsToPayload(AddToolsToPayload: Boolean)`: Sets the Tools to be added to the payload.
- `SetToolChoice(ToolChoice: Text)`: Sets the Tool choice, which allow model to determine how Tools should be called.
- `SetFunctionAsToolChoice(FunctionName: Text)`: Sets the function as the tool choice to be called.
- `SetFunctionAsToolChoice(Function: Interface "AOAI Function")`: Sets the function as the tool choice to be called.
- `GetToolChoice(): Text`: Gets the Tool choice parameter.
- `SetToolInvokePreference(AOAIToolInvokePreference: Enum "AOAI Tool Invoke Preference")`: Sets the tool invocation preference, controls how a tool calls response should be handled.
- `GetToolInvokePreference(): Enum "AOAI Tool Invoke Preference"`: Gets the tool invocation preference, controls how a tool calls response should be handled.
- `AddXPIADetectionTags(var Input: Text)`: Adds XPIA Detection tags to an Input text.
- `AssembleTools(): JsonArray` (internal): Prepares the Tools to be sent to the deployment model.
- `CheckCompatibilityWithModel(Deployment: SecretText)` (internal): Checks if the current chat messages history is compatible with the deployment model

## 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 7764 "AOAI Chat Messages Impl"](../codeunit/7764.md) (20 calls: `AddAssistantMessage → AddAssistantMessage`, `AddSystemMessage → AddSystemMessage`, `AddToolCalls → AddToolCalls`, …)
- [Codeunit 7778 "AOAI Tools Impl"](../codeunit/7778.md) (13 calls: `AddTool → AddTool`, `AssembleTools → PrepareTools`, `ClearTools → ClearTools`, …)

## Called by

- [Codeunit 324 "No. Series Copilot Impl."](../codeunit/324.md) (10 calls: `GenerateAndReviewToolCompletionWithRetry → DeleteMessage`, `GenerateAndReviewToolCompletionWithRetry → GetHistory`, `GenerateNoSeries → AddTool`, …)
- [Codeunit 4402 "SOA Output Message Setup"](../codeunit/4402.md) (10 calls: `AddSignatureToMessageBody → AddTool`, `AddSignatureToMessageBody → AddUserMessage`, `AddSignatureToMessageBody → SetPrimarySystemMessage`, …)
- [Codeunit 4399 "SOA Annotation"](../codeunit/4399.md) (6 calls: `CheckIfMessageRelevant → AddAssistantMessage`, `CheckIfMessageRelevant → AddTool`, `CheckIfMessageRelevant → AddUserMessage`, …)
- [Codeunit 7772 "Azure OpenAI Impl"](../codeunit/7772.md) (5 calls: `ProcessChatCompletionResponse → AddAssistantMessage`, `ProcessChatCompletionResponse → AddToolCalls`, `ProcessChatCompletionResponse → GetToolInvokePreference`, …)
- [Codeunit 2012 "Entity Text Impl."](../codeunit/2012.md) (4 calls: `GenerateCompletion → AddTool`, `GenerateCompletion → AddUserMessage`, `GenerateCompletion → SetPrimarySystemMessage`, …)
- [Codeunit 6331 "Sustainability Chat Completion"](../codeunit/6331.md) (4 calls: `GenerateChatCompletion → AddTool`, `GenerateChatCompletion → AddUserMessage`, `GenerateChatCompletion → SetPrimarySystemMessage`, …)
- [Codeunit 7275 "Sales Lines Suggestions Impl."](../codeunit/7275.md) (4 calls: `AICall → AddTool`, `AICall → AddUserMessage`, `AICall → SetPrimarySystemMessage`, …)
- [Codeunit 7330 "Item Subst. Suggestion Impl."](../codeunit/7330.md) (4 calls: `AICall → AddTool`, `AICall → AddUserMessage`, `AICall → SetPrimarySystemMessage`, …)
- [Codeunit 4417 "SOA Item Selector"](../codeunit/4417.md) (3 calls: `TrySelectBestMatchingItems → AddTool`, `TrySelectBestMatchingItems → AddUserMessage`, `TrySelectBestMatchingItems → SetPrimarySystemMessage`)
- [Codeunit 4596 "SOA Broader Item Search"](../codeunit/4596.md) (3 calls: `AICall → AddTool`, `AICall → AddUserMessage`, `AICall → SetPrimarySystemMessage`)
- [Codeunit 7251 "Bank Acc. Rec. Trans. to Acc."](../codeunit/7251.md) (3 calls: `GetCompletionResponse → AddSystemMessage`, `GetCompletionResponse → AddUserMessage`, `GetCompletionResponse → AddXPIADetectionTags`)
- [Codeunit 4421 "SOA Attachment MLLM"](../codeunit/4421.md) (2 calls: `TryExtractAttachmentContent → AddUserMessage`, `TryExtractAttachmentContent → SetPrimarySystemMessage`)
- [Codeunit 7770 "AOAI Operation Response"](../codeunit/7770.md) (2 calls: `AppendFunctionResponsesToChatMessages → GetLastRole`, `AppendFunctionResponsesToChatMessages → GetLastToolCalls`)
- [Codeunit 7758 "AOAI Function Response"](../codeunit/7758.md) (1 call: `AppendResultToChatMessages → AddToolMessage`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC24-25, BC27-28

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: "AOAI Chat Messages")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
