LoopContext Class

Definition

Provides the per-run state that a LoopEvaluator uses to decide whether a LoopAgent should re-invoke the wrapped agent and what feedback to provide.

public sealed class LoopContext
type LoopContext = class
Public NotInheritable Class LoopContext
Inheritance
LoopContext

Remarks

A single LoopContext instance is created for each LoopAgent run and is reused across iterations, with Iteration and LastResponse updated before each call to EvaluateAsync(LoopContext, CancellationToken). Because evaluator instances are expected to be stateless and may be shared across concurrent runs, any per-run mutable state must be stored on this context — for example via AdditionalProperties — rather than in fields on the evaluator itself.

Constructors

Name Description
LoopContext(AIAgent, AgentSession, IReadOnlyList<ChatMessage>, AgentResponse, AgentRunOptions)

Initializes a new instance of the LoopContext class.

Properties

Name Description
AdditionalProperties

Gets a mutable bag of per-run state shared across iterations and available to every evaluator.

Agent

Gets the wrapped AIAgent that is being looped.

Feedback

Gets the feedback accumulated across iterations so far, one entry per re-invoked iteration in order.

InitialMessages

Gets the messages that were passed in for the first iteration of the loop.

Iteration

Gets the number of completed agent runs so far (1-based after the first run).

LastResponse

Gets the AgentResponse produced by the iteration that just completed.

RunOptions

Gets the AgentRunOptions that were passed to the loop run, if any.

Session

Gets the AgentSession used for the loop.

Applies to