Skip to content

ConversationBranchService

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Branches a session’s conversation from a given point, and opens a new session that carries the branch.

public sealed class ConversationBranchService

objectConversationBranchService

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Branching copies: items are moved into the new conversation with INSERT … SELECT; the pointer is only lineage information. If a pointer chain had been chosen instead, every history read would become recursive, and SqlChatHistoryProvider — the hottest read path, run on every agent turn — would charge a cost to consumers who never use branching. With this design, the read path does not change by even a single line.

The conversation identity lives in the session’s state bag (AgentPrismSessionStateKeys.ChatHistory); the only way to use a branched conversation is through a new session that carries that identity. This is why the endpoint is the session, not the conversation.

ConversationBranchService(ISessionStore, IAgentCatalog, ITenantContext, IConversationBranchStore?, TimeProvider?)

Section titled “ ConversationBranchService(ISessionStore, IAgentCatalog, ITenantContext, IConversationBranchStore?, TimeProvider?)”

Creates a new branching service.

public ConversationBranchService(ISessionStore sessions, IAgentCatalog catalog, ITenantContext tenantContext, IConversationBranchStore? branchStore = null, TimeProvider? timeProvider = null)

sessions ISessionStore

The session store.

catalog IAgentCatalog

The agent catalog. Required to restore the session.

tenantContext ITenantContext

The tenant context.

branchStore IConversationBranchStore?

The conversation copier. Branching is not supported if this is null — in an in-memory setup, chat history lives in Microsoft Agent Framework’s InMemoryChatHistoryProvider object, inside the session state’s opaque block, and cannot be copied up to a given sequence number.

timeProvider TimeProvider?

The time source. The system clock is used if not given.

ArgumentNullException

One of the required dependencies is null.

Whether branching is supported in this setup.

public bool IsSupported { get; }

bool

true only when a persistent SQL provider (UsePostgreSql, UseSqlServer, UseSqlite) is enabled.

BranchAsync(string, SessionBranchRequest, CancellationToken)

Section titled “ BranchAsync(string, SessionBranchRequest, CancellationToken)”

Branches a session’s conversation.

public ValueTask<SessionBranchOutcome> BranchAsync(string sessionId, SessionBranchRequest request, CancellationToken cancellationToken = default)

sessionId string

The source session.

request SessionBranchRequest

The branching request.

cancellationToken CancellationToken

The cancellation token.

ValueTask<SessionBranchOutcome>

The branching result.

ArgumentNullException

request is null.

ArgumentException

sessionId is empty.