Path: redb-route/redb.Route.Llm/Storage/Redb/Schemas/MessageProps.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/Storage/Redb/Schemas/MessageProps.cs
----
using redb.Core.Attributes;
namespace redb.Route.Llm.Storage.Redb.Schemas;
///
/// A single message node within a conversation tree. Persisted as a
/// TreeRedbObject<MessageProps> with the conversation root (or
/// another ) as parent — branching is native: any
/// regenerate / parallel-tool / what-if path attaches as another child of the
/// same parent.
///
/// Identifier lives in value_string (per-message GUID; partial index on
/// PostgreSQL/SQLite, no index on MSSQL) and the conversation FK lives in
/// value_long (pointing at the root's _objects.id; indexed on
/// every provider) — both on the _objects row, so transcript queries
/// never scan _values. Parent is tracked natively via the tree's
/// parent_id; no duplicate fields here.
///
/// Content blocks (text / tool-use / tool-result) are stored as a typed
/// nested array () — REDB persists them natively, no
/// JSON-string marshalling.
///
[RedbScheme("LLM Conversation Message")]
public class MessageProps
{
/// Role: "user" / "assistant" / "system" / "tool".
public string Role { get; set; } = string.Empty;
/// Agent iteration that produced the message (0 = user prompt).
public int Iteration { get; set; }
/// When the message was appended.
public DateTimeOffset CreatedAtUtc { get; set; }
/// Provider id ("openai" / "anthropic" / ...); null for non-provider messages.
public string? ProviderId { get; set; }
/// Model id as resolved at call time.
public string? ModelId { get; set; }
/// Stop reason string for assistant messages; null otherwise.
public string? StopReason { get; set; }
/// Tool-use id when this message is a tool result; null otherwise.
public string? ToolUseId { get; set; }
/// Input tokens attributed to this turn (0 for non-assistant messages).
public int InputTokens { get; set; }
/// Output tokens attributed to this turn.
public int OutputTokens { get; set; }
///
/// Prompt tokens written to the provider's cache by this turn, billed at a premium over normal input
/// (LlmUsage.CacheCreationInputTokens). Zero where the provider does not bill cache creation, as DeepSeek.
///
public int CacheCreationInputTokens { get; set; }
///
/// Prompt tokens this turn read back from the provider's cache, billed at a fraction of normal input
/// (LlmUsage.CacheReadInputTokens). is the remainder billed at full price, so the
/// turn's prompt is the sum of the three.
///
public int CacheReadInputTokens { get; set; }
///
/// Effective sampling temperature passed to the provider for the call that
/// produced this assistant message; null on user / tool-result rows.
///
public double? Temperature { get; set; }
/// Effective max-output-tokens cap; null on non-assistant rows.
public int? MaxTokens { get; set; }
/// Effective top-p value; null on non-assistant rows.
public double? TopP { get; set; }
///
/// Prompt-template name resolved at call time. Pairs with
/// and a row in PromptTemplateProps
/// to lock down "which exact prompt drove this answer".
///
public string? PromptTemplateName { get; set; }
/// Prompt-template version (paired with ).
public string? PromptTemplateVersion { get; set; }
///
/// Stable hash of the tool-capabilities set exposed to the model on this
/// call (canonical JSON of {name, description, schema} sorted by name,
/// SHA-256, hex). Lets auditors detect "the same prompt saw a different
/// tool surface yesterday".
///
public string? ToolSetHash { get; set; }
///
/// Opaque provider-side fingerprint identifying the exact backend
/// configuration that served the call (OpenAI returns this as
/// system_fingerprint; other OpenAI-compatible providers may or may
/// not). When the value changes between two otherwise identical requests,
/// the provider re-released the model under the same id.
///
public string? ProviderSystemFingerprint { get; set; }
///
/// Stable identifier of the principal that initiated the call (end-user,
/// service account, on-behalf-of subject — the host decides). Captured
/// pre-call from the fluent builder (.User(...)) or the
/// llm.user.id header; the same value is stamped on every row of
/// the same agent turn (system / user / tool / assistant).
///
public string? UserId { get; set; }
///
/// Connection-factory alias used for this call (e.g. "haiku",
/// "gpt-mini") — the operator-chosen profile name from
/// LlmConnectionFactory.Name. Audits the *intent* (which configured
/// connection was selected) on top of /
/// (which model actually answered). Differs from the
/// (provider, model) pair when the host registers multiple connections to
/// the same provider with different keys / quotas / regions.
///
public string? FactoryName { get; set; }
///
/// Effective base URL the request was sent to, as configured on
/// LlmConnectionFactory.BaseUrl. Null when the factory used the
/// provider's built-in default endpoint. Captures self-hosted gateways
/// (vLLM, llama.cpp, in-house proxies) that auditors otherwise have to
/// chase through environment configuration.
///
public string? BaseUrl { get; set; }
///
/// Provider-issued response identifier surfaced by the backend (top-level
/// id on OpenAI / Anthropic / xAI / Together responses). Null on
/// non-assistant rows or when the provider does not surface one. Lets an
/// auditor cross-reference a persisted row with the provider's own usage
/// / billing logs.
///
public string? ProviderResponseId { get; set; }
///
/// Wall-clock time (milliseconds) the provider spent producing this
/// assistant turn — measured around ILlmProvider.CompleteAsync.
/// Null on user / tool-result / system rows.
///
public long? LatencyMs { get; set; }
///
/// Stable, non-secret fingerprint of the API key used for this call —
/// SHA-256 of the key, first 16 hex chars. Lets a host with multiple keys
/// per provider (per-tenant, per-environment, rotation pairs) tell which
/// key served a given row without storing the key itself. Null when the
/// factory exposes no ApiKey (e.g. on-host providers, secret-ref
/// resolution skipped).
///
public string? ApiKeyFingerprint { get; set; }
///
/// How many times the route framework retried the inbound exchange before
/// the call succeeded — the operator-visible "this row is from a retry"
/// signal. Read from exchange.Properties["RetryAttempt"]
/// (set by RetryProcessor) with fallbacks to
/// exchange.In.Headers["CamelRedeliveryCounter"]
/// (OnExceptionProcessor) and
/// exchange.In.Headers["CamelDeadLetterRedeliveryCount"]
/// (DeadLetterProcessor). Null when no retry counter is on the
/// exchange (first / only delivery). Same value stamped on every row of
/// the same agent turn.
///
public int? RetryCount { get; set; }
///
/// Content blocks for this message, stored as a typed nested array. Each
/// block carries a discriminator ()
/// plus the fields used by the matching LlmContentBlock variant.
/// Provider-emitted JSON ( /
/// ) stays a raw string —
/// those payloads are intentionally schema-less.
///
/// A "thinking" block is the model's reasoning, kept with the turn that
/// produced it: text in , the
/// signature and the redacted payload beside it.
///
///
public MessageContentBlock[] Content { get; set; } = [];
///
/// Free-form audit tags for this row. Stored as a native REDB
/// so LINQ-to-SQL queries like
/// x.AuditTags["ab-bucket"] == "A" or
/// x.AuditTags.ContainsKey("tier") run server-side via
/// redb.Query<MessageProps>(). Captured pre-call (fluent
/// .Audit(k,v) or llm.audit.<name> headers) and stamped
/// identically on every row of the same turn.
///
public Dictionary? AuditTags { get; set; }
}
///
/// Typed nested representation of an LlmContentBlock. Discriminated
/// by ; only the fields used by the active variant are set.
///
public class MessageContentBlock
{
/// Block kind: "text" / "tool_use" / "tool_result" / "thinking".
public string Kind { get; set; } = string.Empty;
/// Set when == "text".
public string? Text { get; set; }
/// Set when == "tool_use" or "tool_result".
public string? ToolUseId { get; set; }
/// Tool name; set when == "tool_use".
public string? ToolName { get; set; }
/// Raw tool input JSON; set when == "tool_use".
public string? InputJson { get; set; }
/// Raw tool output JSON; set when == "tool_result".
public string? OutputJson { get; set; }
/// Error flag for tool results; set when == "tool_result".
public bool IsError { get; set; }
///
/// Reasoning text; set when == "thinking". Empty when the provider signs the
/// block without returning its text, and for a redacted block.
///
public string? ThinkingText { get; set; }
///
/// Provider signature that authenticates ; "thinking" blocks only, null
/// when the provider does not sign. The provider verifies it when the block comes back, so text and
/// signature are stored and replayed exactly as received.
///
public string? Signature { get; set; }
///
/// Encrypted payload of a redacted thinking block; "thinking" blocks only, with
/// empty. Nothing in it can be read — only handed back.
///
public string? RedactedData { get; set; }}