Path: redb-route/redb.Route.Llm/LlmEndpointOptions.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/LlmEndpointOptions.cs ---- using redb.Route.Core; namespace redb.Route.Llm; /// /// Typed options for . Bound from URI query parameters via reflection. /// /// The set of accepted parameters is intentionally narrow — model, provider, version /// and credentials must come from , not the URI. /// /// public sealed class LlmEndpointOptions : EndpointOptions { /// Name of the registered in the route registry. /// /// May also come from the URI host (llm://myFactory); the host wins when both are set. /// [RegistryReference(typeof(LlmConnectionFactory))] public string? ConnectionFactory { get; set; } /// Optional per-call temperature override. public double? Temperature { get; set; } /// Optional per-call max-tokens override. public int? MaxTokens { get; set; } /// Optional per-call top-p override. public double? TopP { get; set; } /// /// Reference to a system-prompt template stored in the prompt registry /// (or a literal prompt — applied when no registry entry matches). /// public string? SystemPromptRef { get; set; } /// /// Conversation identifier strategy. Recognised values: /// "none" — no conversation tracking (default); /// "header" — read from llm.conversation.id header; /// "property" — read from exchange.RouteId as conversation key. /// public string Conversation { get; set; } = "none"; /// /// Streaming mode (): stream=calls or stream=body; absent means no /// streaming. Any other value, stream=true included, is refused when the endpoint is created. /// public LlmStreamMode Stream { get; set; } /// /// cacheSystemPrompt=true — ask the provider to cache the system prompt so repeated /// turns re-read it instead of re-paying for it. /// /// Set it only when the system prompt is the same bytes every time. Caching matches on /// the rendered prefix, so a prompt carrying a timestamp or a per-user name is written to the /// cache and never read back: cost, no benefit. Verify with /// LlmUsage.CacheReadInputTokens — zero across repeated calls means the prefix moves. /// public bool CacheSystemPrompt { get; set; } /// /// Schedule expression for consumer mode (cron or fixed interval). When set on /// a From("llm://...") route, the consumer wakes up on this schedule and /// invokes the agent with an empty user message (or with body resolved from /// ). /// public string? Schedule { get; set; } /// Optional reference to a body template used by scheduled consumers. public string? InitialBodyRef { get; set; } /// Maximum tool-loop iterations the agent engine may consume for one call. public int MaxIterations { get; set; } = 8; /// /// Per-run input-token budget (summed across iterations). Null = no ceiling; 0 also means no /// ceiling (the enforcer only enforces positive limits). Distinct from , which /// caps what the provider may generate in a single call. /// URI form: llm://factory?budgetInputTokens=20000. /// public int? BudgetInputTokens { get; set; } /// /// Per-run output-token budget (summed across iterations). Null or 0 = no ceiling. /// URI form: llm://factory?budgetOutputTokens=4000. /// public int? BudgetOutputTokens { get; set; } /// /// Per-run cost ceiling in USD. Null or 0 = no ceiling. A positive value requires an /// that can price the model — the run fails fast /// before the first provider call when the registered calculator cannot. /// URI form: llm://factory?budgetCostUsd=0.5. /// public decimal? BudgetCostUsd { get; set; } /// /// Tool exposure filter. Recognised values: /// null/empty — no tools exposed (default; explicit opt-in required); /// "*" — every descriptor in the registry; /// CSV of names (e.g. "get_order,refund") — only those names from the registry. /// public string? Tools { get; set; } /// /// Optional name of the the LLM stores /// (conversation, approval, batch, idempotency, knowledge, ...) should target /// for this endpoint. The producer/consumer publishes the value into /// exchange.Properties[LlmKeys.RedbName]; storage implementations resolve /// the redb instance via context.GetRedbService(name, exchange), which /// already takes care of per-exchange scoping and disposal. /// /// When null or empty the default unnamed IRedbService registered in the /// route context is used — typically the host-wide instance from /// services.AddRedb(). /// /// URI form: llm://factory?redb=my-llm-db. /// public string? Redb { get; set; } /// /// Principal identifier expression for audit. Either a literal value /// ("system") or a header reference ("${header.X-User-Id}"); /// resolves it pre-call against the inbound /// exchange and stamps the value on every persisted row of the run as /// MessageProps.UserId. Falls back to the llm.user.id /// header when this is null. /// public string? User { get; set; } /// /// Comma-separated audit tags expressed as key=value pairs (each /// value may be a literal or a ${header.X} expression). /// Example: tier=${header.X-Tier},bucket=A. Builders normally /// populate this through repeated .Audit(k, v) calls — values are /// URL-encoded before joining so commas / equals signs in literal values /// are safe. Header-driven tags (llm.audit.<name>) merge on /// top of these; headers win on collision. /// public string? Audit { get; set; } /// /// Prompt-template name persisted alongside every row of the run as /// MessageProps.PromptTemplateName. Pairs with /// so auditors can lock down which /// exact prompt drove an answer. Independent of : /// you can carry name/version even when the prompt body comes from elsewhere. /// public string? PromptTemplateName { get; set; } /// Prompt-template version paired with . public string? PromptTemplateVersion { get; set; } /// /// Comma-separated extra header names propagated from the agent exchange to /// every tool call of the run. A trailing * makes an entry a prefix /// match. Example: x-tenant-id,accept-language,x-app-*. /// /// Propagation is default-deny: without this option a tool route sees /// only the conversation / correlation ids, the resolved principal /// (llm.user.id) and the resolved audit tags (llm.audit.*) — /// never the inbound transport's header set. Add names here only for headers /// the route itself controls. /// /// URI form: llm://factory?propagateToolHeaders=x-tenant-id,x-app-*. /// public string? PropagateToolHeaders { get; set; } /// public override void Validate() { if (MaxIterations < 1) throw new ArgumentException("MaxIterations must be >= 1.", nameof(MaxIterations)); if (Temperature is < 0 or > 2) throw new ArgumentException("Temperature must be between 0 and 2.", nameof(Temperature)); // An unknown parameter and a value that does not convert — 'stream=true', the old switch, among them — are // refused by the core while binding, before this method runs (EndpointOptions.BindFromUri); what the // streaming modes mean is added to that refusal by OptionValueHint below. if (BudgetInputTokens is < 0) throw new ArgumentException("BudgetInputTokens must be >= 0.", nameof(BudgetInputTokens)); if (BudgetOutputTokens is < 0) throw new ArgumentException("BudgetOutputTokens must be >= 0.", nameof(BudgetOutputTokens)); if (BudgetCostUsd is < 0m) throw new ArgumentException("BudgetCostUsd must be >= 0.", nameof(BudgetCostUsd)); } /// What each streaming mode does, added to the core refusal of a value that names none. protected override string? OptionValueHint(string optionName) => optionName == nameof(Stream) ? "'stream=calls': the agent engine streams every model call inside the route; tools, the conversation and the " + "route's transaction work as without streaming, the pieces go to IAgentObserver.OnDeltaAsync and Out.Body is " + "the final text. 'stream=body': the agent run happens when the body is read, and its text streams into " + "Out.Body while the model writes it." : null; }