Adapter responsibilities
Capabilities
Context limit, model/version identity, structured output, tools, embeddings, streaming, locality, and region.
Operational profile
Latency, cost, placement, usage metadata, cancellation, deadlines, and safe retry behavior.
Normalization
Map provider request/response types and failures into stable runtime contracts.
Integrity
Preserve route, version, configuration, and usage facts for evidence.
What stays outside the adapter
- Final authorization and tool execution.
- Run lifecycle and durable state.
- Evidence-retention and tenant-identity policy.
- Approval state and high-risk action decisions.
C# contracts
using System.ComponentModel.DataAnnotations;
/// <summary>Describes model capabilities used for route selection.</summary>
public sealed record ModelCapabilityProfile
{
/// <summary>Gets the stable model route key.</summary>
[Display(Name = "Route Key")]
public required string RouteKey { get; init; }
/// <summary>Gets the maximum supported input units.</summary>
[Display(Name = "Context Limit")]
public required int ContextLimit { get; init; }
/// <summary>Gets whether structured output is supported.</summary>
[Display(Name = "Supports Structured Output")]
public required bool SupportsStructuredOutput { get; init; }
}
/// <summary>Contains a normalized model request.</summary>
public sealed record ModelRequest
{
/// <summary>Gets the prompt-contract version.</summary>
[Display(Name = "Prompt Contract Version")]
public required string PromptContractVersion { get; init; }
/// <summary>Gets the sealed context items.</summary>
[Display(Name = "Context Items")]
public required IReadOnlyList<string> ContextItems { get; init; }
}
/// <summary>Contains a normalized candidate and usage details.</summary>
public sealed record ModelCandidate
{
/// <summary>Gets the candidate content.</summary>
[Display(Name = "Content")]
public required string Content { get; init; }
/// <summary>Gets model usage metadata.</summary>
[Display(Name = "Usage")]
public required ModelUsage Usage { get; init; }
}
/// <summary>Contains normalized model usage.</summary>
public sealed record ModelUsage
{
/// <summary>Gets the input units charged by the adapter.</summary>
[Display(Name = "Input Units")]
public required long InputUnits { get; init; }
/// <summary>Gets the output units charged by the adapter.</summary>
[Display(Name = "Output Units")]
public required long OutputUnits { get; init; }
}
/// <summary>Normalizes a model provider boundary.</summary>
public interface IModelAdapter
{
/// <summary>Gets the route capability profile.</summary>
/// <param name="cancellationToken">Signals cancellation of capability discovery.</param>
/// <returns>The current capability profile.</returns>
Task<ModelCapabilityProfile> GetCapabilitiesAsync(CancellationToken cancellationToken);
/// <summary>Streams normalized model candidates.</summary>
/// <param name="request">The normalized request.</param>
/// <param name="cancellationToken">Stops the provider stream and releases resources.</param>
/// <returns>An asynchronous candidate stream.</returns>
IAsyncEnumerable<ModelCandidate> StreamAsync(
ModelRequest request,
CancellationToken cancellationToken);
}
/// <summary>Represents a normalized model-adapter failure.</summary>
public sealed class ModelAdapterException : Exception
{
/// <summary>Initializes a normalized adapter failure.</summary>
/// <param name="code">The stable runtime error code.</param>
/// <param name="message">The diagnostic message safe for evidence.</param>
public ModelAdapterException(string code, string message) : base(message) => Code = code;
/// <summary>Gets the stable runtime error code.</summary>
public string Code { get; }
}
These files are conceptual MiRuntime editorial references, not a product SDK or certification profile.
Failure normalization
| Provider failure | Normalized runtime error | Retry guidance |
|---|---|---|
| Rate limit | capacity_limited |
Bounded backoff or alternate route. |
| Timeout | timeout |
Retry only if idempotent and within budget. |
| Invalid structured output | schema_invalid |
Constrained repair or alternate model. |
| Context overflow | context_limit_exceeded |
Reduce and reselect context. |
| Unsupported tool mode | capability_mismatch |
Route to a compatible model. |
| Region restriction | placement_denied |
Choose an allowed route or stop. |
Tests
- Contract tests for each adapter implementation.
- Capability mismatch and provider error mapping.
- Streaming cancellation and retry budget.
- Token/usage accounting and deterministic fake adapter.
Source record
References
- ONNX Runtime Documentation Primary source
Microsoft and ONNX Runtime contributors. ONNX Runtime. Published Current documentation; last reviewed 2026-06-20 UTC. Official documentation.
- vLLM Documentation Primary source
vLLM project. vLLM. Published Current documentation; last reviewed 2026-06-20 UTC. Official documentation.
- NVIDIA Triton Inference Server Documentation Primary source
NVIDIA. NVIDIA. Published Current documentation; last reviewed 2026-06-23 UTC. Vendor documentation.
Microsoft. Microsoft Learn. Published Current documentation; last reviewed 2026-06-23 UTC. Official architecture guidance.
