Skip to content

InMemoryChatStorage

InMemoryChatStorage holds a single conversation for the lifetime of the instance. It is the right choice when you do not need persistence across app restarts, or when you want to inject a prior conversation into a session at construction time.

public actor InMemoryChatStorage: ChatStorage {
public init(_ messages: [ConversationMessage] = [])
}
ParameterDefaultNotes
messages[]Starting conversation. Preserved in full — fetch trims only the returned view, so a loaded conversation is never clipped at construction time.

Fresh session:

let store = InMemoryChatStorage()
let orchestrator = Orchestrator(agents: [agent], store: store)

Seeding a prior conversation — hand the Orchestrator an existing exchange so the agent has context from the start:

let prior: [ConversationMessage] = loadPriorConversation() // your retrieval logic
let store = InMemoryChatStorage(prior)
let orchestrator = Orchestrator(agents: [agent], store: store)

The seeded messages are stored in full; fetch trims only the returned view via trimToEvenPairs, so the loaded conversation is never clipped at construction time.

  • Scope-agnostic. userId, sessionId, and agentId are ignored — every read and write targets the same history. This is what allows seeding without knowing the consumer’s agentId.
  • No [agentId] attribution. fetchAllChats returns the whole conversation unattributed.
  • No persistence. History is lost when the instance is deallocated.

See also: Storage overview · FileChatStorage · DeviceChatStorage · Custom store