LoopAgentOptions.SessionCreatedCallback Property

Definition

Gets or sets an optional callback invoked whenever LoopAgent creates a new session, so the caller can capture the latest session (for example to continue the conversation after the loop completes). Defaults to null.

public Func<Microsoft.Agents.AI.AgentSession,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask>? SessionCreatedCallback { get; set; }
member this.SessionCreatedCallback : Func<Microsoft.Agents.AI.AgentSession, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask> with get, set
Public Property SessionCreatedCallback As Func(Of AgentSession, CancellationToken, ValueTask)

Property Value

Remarks

The callback is invoked with each session the loop itself creates: the initial loop-owned session (when the caller does not supply one) and, when FreshContextPerIteration is enabled, every session created for a re-invocation — whether a brand-new loop-owned session or a fresh clone deserialized from the caller's original session. It is not invoked for a caller-supplied session, since the caller already holds that one. When it fires multiple times, the most recent invocation carries the session the loop is currently using.

Applies to