LoopAgentOptions.FreshContextPerIteration Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value indicating whether each re-invocation restarts from a clean context: the original input
messages plus an aggregated feedback log, rather than the latest feedback appended to the prior conversation.
Defaults to false.
public bool FreshContextPerIteration { get; set; }
member this.FreshContextPerIteration : bool with get, set
Public Property FreshContextPerIteration As Boolean
Property Value
Remarks
This rebuilds the input messages each iteration and resets the session before each re-invocation so no prior conversation history leaks across iterations. When the loop owns the session it creates a new one each iteration. When the caller supplies a session, LoopAgent serializes it once at the start of the run and restores a fresh clone (by deserializing that snapshot) before each re-invocation; this requires the wrapped agent to support session serialization. The first iteration still runs against the caller's supplied session.
Note that cloning will only result in a fresh context, if the chat history storage mechanism supports cloning. For example the default in-memory storage supports cloning, since the messages are serialized as part of the snapshot.
However, if the Conversations service is used, which stores messages in a single threaded list of messages, then the cloned session will still contain the full message history, since the snapshot only captures an id reference to the conversation and not the individual messages.
On the other hand, if responses are used with response ids, cloning will work well, since response ids are forkable. Each new response has its own id, and is based on the id of the previous response.
On iterations where an evaluator returns explicit messages via ContinueWithMessages(IEnumerable<ChatMessage>), the session is still reset (a fresh or cloned session is used); only the rebuild of the input messages from the feedback log is skipped, because the evaluator's explicit messages are sent verbatim.