ConversationBranchService
AgentPrism.Core.dllBranches a session’s conversation from a given point, and opens a new session that carries the branch.
public sealed class ConversationBranchServiceInheritance
Section titled “Inheritance”object ← ConversationBranchService
Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”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.
Constructors
Section titled “Constructors”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)Parameters
Section titled “Parameters”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.
Exceptions
Section titled “Exceptions”One of the required dependencies is null.
Properties
Section titled “Properties”IsSupported
Section titled “ IsSupported”Whether branching is supported in this setup.
public bool IsSupported { get; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”true only when a persistent SQL provider
(UsePostgreSql, UseSqlServer, UseSqlite) is enabled.
Methods
Section titled “Methods”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)Parameters
Section titled “Parameters”sessionId string
The source session.
request SessionBranchRequest
The branching request.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<SessionBranchOutcome>
The branching result.
Exceptions
Section titled “Exceptions”request is null.
sessionId is empty.