> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Assistant Chat History

> An AI agent's past conversations, grouped by day, with a New Chat row and delete.

`CometChatAIAssistantChatHistory` lists the past conversations a user has had with an AI
agent. Each row is the first message of one conversation, grouped under "Today",
"Yesterday" or a date. The navigation bar carries an inline "Chat History" title, and a
**New Chat** row sits under it as a bar the list scrolls beneath. Tapping a row hands you that
conversation's first message, so you can reopen it; swipe or long-press a row to delete it.

![CometChatAIAssistantChatHistory showing past AI chats grouped by date](https://mintcdn.com/cometchat-22654f5b/pWDsskjSUHgot30F/images/ui-kit/ios/v6/docs-overview-ai-assistant-chat-history.png?fit=max\&auto=format\&n=pWDsskjSUHgot30F\&q=85\&s=9c20b040f924fee5b79e32abcb8f77c2)

***

## Where It Fits

```
AI agent chat ── header's chat-history button
                          │ present
                          ▼
         ┌───────────────────────────────────────────┐
         │ CometChatAIAssistantChatHistory  ← here    │
         └───────────────────────────────────────────┘
              │ onItemClick(message)      │ onNewChatClick
              ▼                           ▼
   the chat, opened at that message   a fresh chat with the agent
```

The message header already shows the chat-history and new-chat buttons for an AI agent
(`onChatHistoryClick` / `onNewChatClick` on `CometChatMessageHeader`); this screen is what
the first one opens.

***

## Quick Start

Present it with the agent, and reopen a conversation from a row.

> [tab] SwiftUI
>
> ```swift theme={null}
> struct AgentHistorySheet: View {
>     @Environment(\.dismiss) private var dismiss
>
>     var body: some View {
>         NavigationStack {
>             CometChatAIAssistantChatHistory(
>                 user: agent,
>                 onCloseClick: { dismiss() },
>                 onNewChatClick: { startNewChat() },
>                 onItemClick: { message in openConversation(message) })
>         }
>     }
> }
> ```
>
> Put it in a `NavigationStack`: it uses the system navigation bar with an inline title, which
> stays at every sheet detent.
>
> `onItemClick` receives the conversation's first message as the SDK's `BaseMessage`. Open the
> agent's chat with it as the parent message to continue that conversation.
>
> The ✕ shows only when `onCloseClick` is set, and then replaces the back button — the screen
> has one way out. Pushed without `onCloseClick`, the system back button is the way out.

> [tab] UIKit
>
> ```swift theme={null}
> final class AgentChatViewController: UIViewController {
>     func showHistory() {
>         let history = CometChatAIAssistantChatHistory()
>             .set(user: agent)
>             .set(onMessageClicked: { [weak self] message in
>                 self?.dismiss(animated: true) { openConversation(message) }
>             })
>             .set(onNewChatClick: { [weak self] in
>                 self?.dismiss(animated: true) { startNewChat() }
>             })
>         present(UINavigationController(rootViewController: history), animated: true)
>     }
> }
> ```
>
> `CometChatAIAssistantChatHistory` is a view controller. Present it in a navigation
> controller: the inline title stays at every sheet detent.
>
> The ✕ appears while the screen is the root of its navigation stack; tapping it runs
> `set(onClose:)`, or dismisses the screen when none is set. Pushed onto a stack, the screen
> keeps the back button and shows no ✕.

***

## What It Shows

* The agent's **top-level text messages** — each the start of a conversation — 20 at a time,
  newest first. Replies and deleted messages are left out.
* A row is the message's text on up to two lines. A mention reads as `@Name`, and markdown
  markers are removed.
* A header above each day's rows — "Today", "Yesterday", then a date such as "Oct 12, 2026".
  It stays pinned while that day's rows scroll beneath it. A message with no send time sits
  under "Updating".
* The next page loads when you scroll to within two rows of the end. A list that fits on the
  screen does not load more by itself.

***

## Deleting

Long-press a row, or swipe it left, and choose **Delete**. "Delete this conversation?" asks
first; confirming deletes the message on the server and removes the row. If the server
refuses, the row stays and "Unable to delete conversation" appears briefly.

***

## Actions and Events

### Callback Methods

> [tab] SwiftUI
>
> | Prop | Signature | When |
> | - | - | - |
> | `onCloseClick` | `() -> Void` | the ✕ is tapped |
> | `onNewChatClick` | `() -> Void` | the New Chat row is tapped |
> | `onItemClick` | `(BaseMessage) -> Void` | a row is tapped |
> | `onItemLongClick` | `(BaseMessage) -> Void` | a row is long-pressed; replaces the menu and the swipe |
> | `onOptionSelected` | `(BaseMessage, MenuOption) -> Void` | a row option is chosen |
> | `onError` | `(CometChatError) -> Void` | a request fails |
>
> Setting `onItemLongClick` replaces the menu and the swipe entirely — the long press is then
> yours:
>
> ```swift theme={null}
> CometChatAIAssistantChatHistory(user: agent, onItemLongClick: { message in
>     log("long-pressed \(message.id)")
> })
> ```

> [tab] UIKit
>
> | Setter | Signature | When |
> | - | - | - |
> | `set(onMessageClicked:)` | `(BaseMessage) -> Void` | a row is tapped |
> | `set(onNewChatClick:)` | `() -> Void` | the New Chat row is tapped |
> | `set(onClose:)` | `() -> Void` | the ✕ is tapped; the default dismisses |
> | `set(onItemLongClick:)` | `(BaseMessage) -> Void` | a row is long-pressed; replaces the swipe and the menu |
> | `set(onError:)` | `(CometChatException) -> Void` | a request fails |
> | `set(onLoad:)` | `([BaseMessage]) -> Void` | the loaded messages change |
> | `set(onEmpty:)` | `() -> Void` | the list is empty |
>
> Every callback is also a `CometChatAIAssistantChatHistoryDelegate` method:
>
> ```swift theme={null}
> final class HistoryEvents: NSObject, CometChatAIAssistantChatHistoryDelegate {
>     func onItemClick(message: BaseMessage, indexPath: IndexPath) { openConversation(message) }
>     func onNewChatClick(user: User?) { startNewChat() }
>     func onError(error: NSError) { log(error.localizedDescription) }
> }
>
> @MainActor func makeHistory(events: HistoryEvents) -> CometChatAIAssistantChatHistory {
>     let history = CometChatAIAssistantChatHistory()
>     history.delegate = events   // weak: keep `events` alive yourself
>     return history
> }
> ```

### SDK Events (Real-Time, Automatic)

A delete made elsewhere — in the chat, or on another device — removes the row. Conversations
started while the screen is open do not appear until it is opened again.

***

## States

| State | What shows |
| - | - |
| Before a fetch | the empty state |
| Loading the first page | thirty shimmer rows |
| No conversations | "No conversation history found" |
| A page failed | "Oops!", with no retry |

The New Chat row stays in every state. A page that fails after rows have loaded replaces them
with the error state. Deleting the last row loaded shows the empty state, even if older
conversations are still on the server.

***

## Functionality

> [tab] SwiftUI
>
> | Prop | Type | Default |
> | - | - | - |
> | `store` | `AIAssistantChatHistoryStore?` | `nil` |
> | `user` | `User?` | the agent; required for a fetch |
> | `group` | `Group?` | builds the request, does not fetch — see Common Patterns |
> | `style` | `CometChatAIAssistantChatHistoryStyle` | |
> | `hideEmptyState` | `Bool` | `false` |
> | `hideErrorState` | `Bool` | `false` |

> [tab] UIKit
>
> | Method | Does |
> | - | - |
> | `set(user:parentMessage:withParent:)` | sets the agent and fetches; the parent arguments are not applied, because the history lists top-level conversations only |
> | `set(group:parentMessage:)` | sets a group; builds the request, does not fetch |
> | `set(messagesRequestBuilder:)` | sets the `MessagesRequest.MessageRequestBuilder`; call it before setting the agent |
> | `set(hideDateSeparator:)` | removes the day headers and keeps the rows |
> | `set(hideEmptyState:)`, `set(hideErrorState:)` | hide a state |
> | `set(style:)` | applies an `AiAssistantChatHistoryStyle` |
>
> Also properties: `user`, `group`, `onMessageClicked`, `onNewChatButtonClicked`, `delegate`,
> `style`, `dateTimeFormatter`, `hideDateSeparator`, `listItemCellClass` and `viewModel`.

***

## Custom View Slots

Replace a state's view, change its words, or hide it.

> [tab] SwiftUI
>
> The loading, empty and error views are initialiser arguments (`loadingView`, `emptyView`,
> `errorView`):
>
> ```swift theme={null}
> CometChatAIAssistantChatHistory(
>     user: agent,
>     emptyView: { AnyView(MyHistoryEmptyView()) },
>     hideErrorState: true,
>     onError: { error in log(error.message) })
> ```
>
> The same through modifiers, for a whole subtree — `.cometChatAIAssistantChatHistoryLoadingView`,
> `.cometChatAIAssistantChatHistoryEmptyView`, `.cometChatAIAssistantChatHistoryErrorView` and
> `.cometChatAIAssistantChatHistoryHidden`:
>
> ```swift theme={null}
> NavigationStack {
>     CometChatAIAssistantChatHistory(user: agent)
> }
> .cometChatAIAssistantChatHistoryEmptyView { MyHistoryEmptyView() }
> .cometChatAIAssistantChatHistoryHidden([.errorState])
> ```

> [tab] UIKit
>
> `set(emptyView:)`, `set(errorView:)` and `set(loadingView:)` each take a `UIView`:
>
> ```swift theme={null}
> let history = CometChatAIAssistantChatHistory()
>     .set(user: agent)
>     .set(emptyView: MyEmptyView())
>     .set(hideErrorState: true)
> history.errorStateTitleText = "Couldn't load your chats"
> ```
>
> Replace the row with your own `CometChatAIAssistantChatHistoryListItem` subclass through
> `listItemCellClass`.

***

## Menu Options

Add your own options after Delete, or replace the list. The long-press menu and the swipe draw
from the same list.

> [tab] SwiftUI
>
> Add options with `addOptions`, or replace the list with `options`:
>
> ```swift theme={null}
> CometChatAIAssistantChatHistory(
>     user: agent,
>     addOptions: { _ in [MenuOption(id: "share", title: "Share", systemImage: "square.and.arrow.up")] },
>     onOptionSelected: { message, option in
>         if option.id == "share" { log("share \(message.id)") }
>     })
> ```

> [tab] UIKit
>
> Add options with `set(addOptions:)`, or replace the list with `set(options:)`. Both take a
> closure returning `[CometChatAIAssistantChatHistoryOption]`:
>
> ```swift theme={null}
> let history = CometChatAIAssistantChatHistory()
>     .set(user: agent)
>     .set(addOptions: { _ in
>         [CometChatAIAssistantChatHistoryOption(id: "share", title: "Share",
>                                                icon: UIImage(systemName: "square.and.arrow.up"),
>                                                onClick: { message, _ in log("share \(message.id)") })]
>     })
> ```

***

## Common Patterns

### Show a group's history

> [tab] SwiftUI
>
> Pass `group` instead of `user` for a group's history. A group scope builds the request but
> does not fetch; set it on a store and ask for the first page yourself:
>
> ```swift theme={null}
> struct GroupHistory: View {
>     @State private var store = AIAssistantChatHistoryStore()
>
>     var body: some View {
>         CometChatAIAssistantChatHistory(store: store)
>             .task {
>                 store.setGroup(group)
>                 store.fetchMessages()
>             }
>     }
> }
> ```

> [tab] UIKit
>
> `set(group:parentMessage:)` builds the request but does not fetch by itself.

### Change the day header words

> [tab] SwiftUI
>
> The day headers cannot be reworded in this toolkit.

> [tab] UIKit
>
> Change the header words through `dateTimeFormatter`:
>
> ```swift theme={null}
> struct HistoryDates: CometChatDateTimeFormatter {
>     func today(_ date: Date) -> String? { "This day" }
> }
>
> @MainActor func makeHistory() -> CometChatAIAssistantChatHistory {
>     let history = CometChatAIAssistantChatHistory()
>     history.dateTimeFormatter = HistoryDates()
>     return history
> }
> ```

***

## Advanced Methods

### Store Access

> [tab] SwiftUI
>
> `AIAssistantChatHistoryStore` holds the state the list draws. Pass one to keep the history
> across presentations, or to drive it yourself:
>
> ```swift theme={null}
> struct RememberedHistory: View {
>     @State private var store = AIAssistantChatHistoryStore()
>
>     var body: some View {
>         NavigationStack {
>             CometChatAIAssistantChatHistory(store: store, user: agent)
>         }
>     }
> }
> ```
>
> Keep one store per agent: the request is built the first time a scope is set, and a later
> agent reuses it.

> [tab] UIKit
>
> The state lives in the view controller's `viewModel`. Keep one view model per agent: the
> request is built once.

### Subclassing

> [tab] SwiftUI
>
> `CometChatAIAssistantChatHistory` is a `View` struct. Customise it with its slots, modifiers
> and style.

> [tab] UIKit
>
> The setup, the style, the state views, the option list, the menu and the close item are
> `open`:
>
> ```swift theme={null}
> final class PinnableHistory: CometChatAIAssistantChatHistory {
>     override func configureOptions(for message: BaseMessage) -> [CometChatAIAssistantChatHistoryOption] {
>         super.configureOptions(for: message) + [
>             CometChatAIAssistantChatHistoryOption(id: "pin", title: "Pin",
>                                                   onClick: { message, _ in log("pin \(message.id)") })
>         ]
>     }
>
>     override func setupStyle() {
>         super.setupStyle()
>         view.backgroundColor = .systemGroupedBackground
>     }
> }
> ```

***

## Style

Every property is optional; anything unset keeps the default look.

> [tab] SwiftUI
>
> ```swift theme={null}
> var style = CometChatAIAssistantChatHistoryStyle()
> style.chatHistoryBackgroundColor = Color(red: 1, green: 0.98, blue: 0.96)
> style.newChatIconTint = .orange
> style.itemTextStyle = .system(size: 16, design: .serif)
> style.dateSeparatorTextColor = .secondary
> style.deleteOptionIconTint = .red
>
> let screen = CometChatAIAssistantChatHistory(user: agent, style: style)
> ```
>
> | Property | Default | What it styles |
> | - | - | - |
> | `chatHistoryBackgroundColor` | `background1` | the screen |
> | `chatHistoryHeaderBackgroundColor` | the system's | the bar, without Liquid Glass |
> | `chatHistoryHeaderTextColor`, `chatHistoryHeaderTextStyle` | the system's inline title (`heading4Bold` once either is set) | the title, without Liquid Glass |
> | `chatHistoryHeaderCloseIcon`, `chatHistoryHeaderCloseIconTint` | `xmark`, `neutral800` | the ✕ |
> | `newChatBackgroundColor` | clear on Liquid Glass, the screen's colour without | the New Chat row |
> | `newChatTextColor`, `newChatTextStyle` | `textPrimary`, `buttonRegular` | "New Chat" |
> | `newChatIcon`, `newChatIconTint` | `plus`, `iconTintSecondary` | its glyph |
> | `dateSeparatorBackgroundColor` | the screen's colour | a day header |
> | `dateSeparatorTextColor`, `dateSeparatorTextStyle` | `textTertiary`, `caption1Medium` | its text |
> | `itemBackgroundColor` | clear | a row |
> | `itemTextColor`, `itemTextStyle` | `textPrimary`, `bodyRegular` | its text |
> | `deleteOptionIcon`, `deleteOptionIconTint` | `trash`, `error` | Delete's glyph and the swipe's fill |
> | `deleteOptionTextColor`, `deleteOptionTextStyle` | `textWhite`, `bodyRegular` | the swipe's title |
>
> On iOS 26 the bar is Liquid Glass and draws its own title, and the rows fade beneath the bar
> and the New Chat row as one surface; the header text and background properties apply on
> earlier systems and with Reduce Transparency on, where the New Chat row is flat. The long-press menu is
> the system's, so the Delete text properties reach the swipe only.

> [tab] UIKit
>
> ```swift theme={null}
> let style = AiAssistantChatHistoryStyle()
> style.backgroundColor = UIColor(red: 1, green: 0.98, blue: 0.96, alpha: 1)
> style.newChatImageTintColor = .systemOrange
> style.itemTextFont = UIFont(name: "Georgia", size: 16)
> style.dateSeparatorTextColor = .secondaryLabel
> style.deleteOptionIconTint = .systemRed
>
> let history = CometChatAIAssistantChatHistory().set(style: style)
> CometChatAIAssistantChatHistory.style.closeIconColor = .label   // every new screen
> ```
>
> | Property | Default | What it styles |
> | - | - | - |
> | `backgroundColor`, `borderColor`, `borderWidth`, `cornerRadius` | `background1`, `neutral200`, 0, 0 | the screen |
> | `headerBackgroundColor`, `headerTitleFont`, `headerTitleTextColor` | the system's; the system's inline title (`heading4Bold`, `textPrimary` once either is set) | the bar, without Liquid Glass |
> | `closeIconColor`, `chatHistoryHeaderCloseIcon` | `neutral800`, `xmark` | the ✕ |
> | `newChatImageTintColor`, `newChatIcon` | `iconTintSecondary`, `plus` | the New Chat glyph |
> | `newChatTitleFont`, `newChatTextColor`, `newChatBackgroundColor` | `buttonRegular`, `textPrimary`, clear on Liquid Glass and the screen's colour without | the New Chat row |
> | `itemTextFont`, `itemTextColor`, `itemBackgroundColor` | `bodyRegular`, `textPrimary`, clear | a row |
> | `dateSeparatorTextFont`, `dateSeparatorTextColor`, `dateSeparatorBackgroundColor` | `caption1Medium`, `textTertiary`, the screen's colour | a day header |
> | `emptyStateTextFont`, `emptyStateTextColor`, `emptyStateSubtitleFont`, `emptyStateSubtitleColor` | `bodyRegular`, `neutral600`, `caption1Regular`, `neutral400` | the empty state |
> | `errorStateTextFont`, `errorStateTextColor`, `errorStateSubtitleFont`, `errorStateSubtitleColor` | `bodyMedium`, `error`, `caption1Regular`, `textSecondary` | the error state |
> | `deleteOptionIcon`, `deleteOptionIconTint`, `deleteOptionTextColor`, `deleteOptionTextFont` | `trash`, `error`, `textWhite`, `bodyRegular` | the Delete swipe |

***

## Next Steps

> [card] [Message Header](https://www.cometchat.com/docs/ui-kit/ios/v6/message-header.md)
>
> The chat-history and new-chat buttons that open this screen

> [card] [Message List](https://www.cometchat.com/docs/ui-kit/ios/v6/message-list.md)
>
> Open a conversation at its parent message


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.