Path: redb-route/redb.Route.Llm/Engine/AgentRequest.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Llm/Engine/AgentRequest.cs ---- using redb.Route.Abstractions; using redb.Route.Llm.Abstractions.Tools; using redb.Route.Llm.Engine.Governance; using redb.Route.Llm.Providers; namespace redb.Route.Llm.Engine; /// /// Single agent execution request. Carries the user message, optional system prompt, /// conversation context and the parent exchange for TX/scope/principal. /// public sealed class AgentRequest { /// Connection factory used to build the provider. public required LlmConnectionFactory Factory { get; init; } /// Owning exchange — drives DI scope, headers, principal and observability. public required IExchange Exchange { get; init; } /// Initial user message (may include text and tool-result blocks). public required IReadOnlyList UserContent { get; init; } /// System prompt for this run. public string? SystemPrompt { get; init; } /// /// Ask the provider to cache the system prompt across turns — see /// . Worth it only when the system prompt /// is byte-stable; a prompt that varies per request never gets read back. /// public bool CacheSystemPrompt { get; init; } /// /// Messages placed before the loaded conversation history on every iteration of the /// run — a fixed opening exchange the model sees as its own past, a few-shot block, anything /// that must precede the dialog without being part of it. /// /// Not persisted and not part of the conversation. The store keeps what was /// said in this dialog; the preamble is part of how the assistant is assembled, so it is /// re-attached from the request each time rather than written as rows. That is also what /// makes it survive a branch rebuild: a fresh branch loads an empty path and the preamble is /// still there. /// /// Keep it byte-stable and mark its last message with /// when the system prompt is cached too — otherwise /// the cached prefix ends at the system block and the preamble is paid in full on every /// turn. The first preamble message must be a user turn: providers require the /// transcript to open with one. /// public IReadOnlyList Preamble { get; init; } = []; /// Tools available to the model on this run. public IReadOnlyList Tools { get; init; } = []; /// Conversation identifier (when conversation tracking is on). public string? ConversationId { get; init; } /// /// Message id of the conversation node this run should attach under. /// Null = attach under the conversation root (continue at head when resuming; /// new branch when the conversation already has children). /// public string? ConversationParentMessageId { get; init; } /// Per-run budget (defaults to unbounded). public AgentBudget Budget { get; init; } = AgentBudget.Unbounded; /// Maximum tool-loop iterations. public int MaxIterations { get; init; } = 8; /// Per-call sampling overrides. public double? Temperature { get; init; } /// Per-call max-tokens override. public int? MaxTokens { get; init; } /// /// Optional name of the prompt template that produced . /// When set together with , the engine /// stamps every persisted assistant message with the (name, version) pair so /// auditors can reconstruct "which exact prompt drove this answer". Stays /// null when the caller does not use a managed template. /// public string? PromptTemplateName { get; init; } /// Version of the prompt template named by . public string? PromptTemplateVersion { get; init; } /// /// Stable identifier of the principal that initiated this run (end-user, /// service account, on-behalf-of subject — host decides). Persisted on /// every row of the run so audit queries always have a consistent subject. /// Null when no principal is wired. /// public string? UserId { get; init; } /// /// Free-form audit tags captured pre-call (operator-controlled key/value /// pairs — e.g. ab-bucket=A, tier=premium). The same snapshot /// is stamped on every row of the run; null / empty when no tags are wired. /// public IReadOnlyDictionary? AuditTags { get; init; } /// /// Extra header names the route author opted into propagating from this /// exchange to every tool call of the run (e.g. x-tenant-id, /// accept-language). A trailing * makes the entry a prefix match /// (x-app-*). Propagation is default-deny: without an entry here only /// , the resolved /// and the resolved reach a tool — /// the inbound transport's own headers never do. Null / empty = defaults only. /// public IReadOnlyList? PropagateToolHeaders { get; init; } /// /// Make every model call of the run as a stream (stream=calls). The pieces go to /// as they arrive; the loop goes on with the whole answer /// the stream assembled, the same answer a plain call returns, so tools, the conversation, the budget and the /// route's transaction work as without streaming. The connection carries data while the model writes. /// public bool StreamModelCalls { get; init; } /// /// Receiver of this run's pieces, beside the observer: the observer is shared by every run of the engine, and this /// one belongs to the run that set it. stream=body feeds Out.Body through it. Called only when /// is on, in the order the pieces arrive. /// public Func? OnDelta { get; init; } } /// Final agent response. public sealed class AgentResponse { /// Last assistant content (text + any unanswered tool calls). public required IReadOnlyList Content { get; init; } /// Aggregate token usage across all iterations. public LlmUsage Usage { get; init; } = LlmUsage.Empty; /// Number of tool-loop iterations consumed. public int Iterations { get; init; } /// Final stop reason of the last provider call. public LlmStopReason StopReason { get; init; } = LlmStopReason.EndTurn; /// Convenience accessor — first text block in , or empty. public string Text { get { foreach (var b in Content) if (b is LlmTextBlock t) return t.Text; return string.Empty; } } }