Mythosia.AI.Abstractions
2.4.0
See the version list below for details.
dotnet add package Mythosia.AI.Abstractions --version 2.4.0
NuGet\Install-Package Mythosia.AI.Abstractions -Version 2.4.0
<PackageReference Include="Mythosia.AI.Abstractions" Version="2.4.0" />
<PackageVersion Include="Mythosia.AI.Abstractions" Version="2.4.0" />
<PackageReference Include="Mythosia.AI.Abstractions" />
paket add Mythosia.AI.Abstractions --version 2.4.0
#r "nuget: Mythosia.AI.Abstractions, 2.4.0"
#:package Mythosia.AI.Abstractions@2.4.0
#addin nuget:?package=Mythosia.AI.Abstractions&version=2.4.0
#tool nuget:?package=Mythosia.AI.Abstractions&version=2.4.0
Mythosia.AI.Abstractions
Core contracts and shared models for the Mythosia.AI ecosystem.
Defines IAIService, all model types, and streaming primitives.
Consumed by Mythosia.AI.Rag and any library that needs the AI service contract without pulling in heavy provider implementations.
Installation
dotnet add package Mythosia.AI.Abstractions
Install this package directly only when writing a library that depends on the AI service contract (e.g., RAG orchestration, custom middleware).
Applications normally take a transitive dependency through Mythosia.AI.
Core Interface
IAIService
The central abstraction for AI completion and streaming.
public interface IAIService
{
string Model { get; }
string Provider { get; }
string SystemMessage { get; set; }
bool StatelessMode { get; set; }
ChatBlock ActivateChat { get; }
// Completion
Task<string> GetCompletionAsync(string prompt);
Task<string> GetCompletionAsync(Message message);
Task<string> GetCompletionAsync(Message message, AIRequestContext context);
// ... additional overloads with AIRequestProfile
// Streaming
IAsyncEnumerable<string> StreamAsync(string prompt, CancellationToken ct = default);
IAsyncEnumerable<StreamingContent> StreamAsync(Message message, StreamOptions options, CancellationToken ct = default);
// ... additional overloads
}
All concrete providers (OpenAIService, AnthropicService, GoogleAIService, etc.) in Mythosia.AI implement this interface.
Models
| Type | Description |
|---|---|
Message |
A conversation message with role, content, and optional multimodal content |
MessageContent |
Base class for multimodal content (TextContent, ImageContent, AudioContent) |
ChatBlock |
Conversation container holding system message and message history |
ActorRole |
Message role enum (System, User, Assistant, Function) |
AIRequestContext |
Per-request context overrides (system message prefix/suffix, message override) |
AIRequestProfile |
Per-request parameter overrides (temperature, max tokens, stateless mode) |
AIModels |
Model identifier constants for all supported providers |
AIProvider |
Provider enum (OpenAI, Anthropic, Google, xAI, DeepSeek, Perplexity) |
Streaming
| Type | Description |
|---|---|
StreamingContent |
Streaming chunk with content, type, metadata, token usage, and round information |
StreamingContentType |
Chunk type enum (Text, Reasoning, FunctionCall, FunctionResult, Status, Error, Completion, RoundUsage) |
StreamOptions |
Streaming behavior options (metadata, function calls, reasoning) |
TokenUsage |
Token count data (input, output, cached, reasoning) |
StreamDiagnostics |
SSE round observability snapshot — lines read, accumulated chars, last raw line, elapsed time |
StreamDiagnosticsBuilder |
Fluent configurator for service-level streaming diagnostics; consumed by Mythosia.AI's WithStreamDiagnostics(d => d.OnRawLine(...).OnComplete(...)) |
Functions
| Type | Description |
|---|---|
FunctionDefinition |
Function schema for LLM function calling |
FunctionCallingPolicy |
Controls function calling behavior and iteration limits |
AiFunctionAttribute |
Marks a method as an AI-callable function |
AiParameterAttribute |
Describes a function parameter for the AI |
Exceptions
| Type | Description |
|---|---|
AIServiceException |
Base exception for AI service errors |
AgentMaxStepsExceededException |
Thrown when agent exceeds maximum iteration steps |
StreamReadException |
Thrown when an SSE read fails (transport error, premature stream end, etc.). Wraps the underlying exception in InnerException and attaches a StreamDiagnostics snapshot via the Diagnostics property |
Relationship to Microsoft.Extensions.AI
Microsoft.Extensions.AI (IChatClient) and IAIService solve different problems at different layers.
IAIService (Mythosia.AI) |
IChatClient (MS.Extensions.AI) |
|
|---|---|---|
| State | Stateful — ChatBlock accumulates conversation history automatically |
Stateless — caller passes the full message list on every call |
| Session management | Multiple ChatBlock sessions per service instance, switchable at runtime |
None; caller manages message lists |
| System message | First-class property; supports per-request prefix/suffix injection via AIRequestContext |
Passed as a ChatMessage with Role = system |
| Request parameters | Strongly-typed AIRequestProfile (temperature, max tokens, stateless, disable functions) |
ChatOptions dictionary |
| Function calling | Automatic ReAct loop with configurable FunctionCallingPolicy (max rounds, timeout, concurrency) |
Single-round; caller implements the loop |
| Streaming chunks | Typed StreamingContent — Text, Reasoning, FunctionCall, FunctionResult, Completion, Error |
Text content updates only |
| Conversation summarization | Built-in SummaryConversationPolicy — auto-summarizes when token/message thresholds are exceeded |
Not provided |
| Multimodal | Message serializes to each provider's wire format automatically |
Caller constructs provider-specific content objects |
| Token usage | Tracks input, output, cached, cache-creation, and reasoning tokens | Input and output tokens only |
IAIService sits at a higher abstraction level than IChatClient. Implementing IChatClient on top of IAIService would discard stateful session management, typed streaming, and the function-calling loop. The two interfaces are not interchangeable.
If interoperability with the MS ecosystem is required, the recommended direction is to accept an IChatClient as a constructor dependency inside a Mythosia.AI provider — not to replace IAIService with IChatClient.
Why This Package?
Mythosia.AI.Rag → Mythosia.AI.Abstractions (zero heavy dependencies)
instead of
Mythosia.AI (Azure.AI.OpenAI, NJsonSchema, TiktokenSharp, ...)
By depending on abstractions rather than the full implementation package, libraries like Mythosia.AI.Rag avoid pulling in provider-specific dependencies. The concrete provider is chosen by the final application.
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Mythosia (>= 1.4.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Mythosia.AI.Abstractions:
| Package | Downloads |
|---|---|
|
Mythosia.AI
## What's New in v6.8.0 ### Added - Reactive context-overflow recovery. When the server rejects a request for exceeding the model's context window, the conversation is compacted and the request is re-sent — no client-side token estimation, and it follows the deployment's real limit automatically. Providers now translate that rejection into ContextLengthExceededException (non-streaming) or a context_length_exceeded-flagged error chunk (streaming). Streaming recovers inside the round loop, replaying only the round that overflowed and keeping the tool results earlier rounds produced. Tunable via AIService.ContextRecoveryMaxRetries (default 1, set 0 to disable). ### Fixed - Forced compaction decided "this would not shrink the request" only after paying for a summary and irreversibly deleting messages. With the default MaxMessageCount of 20 a long agentic run hits this every time — the deletable history sits outside the window and cannot shrink anything — so recovery destroyed conversation history, spent a summary call, and still returned the original error. The check is now pure arithmetic performed before either. - The summarization request inherited the caller's AIRequestContext. RequestMessageOverride replaces the last message of every outgoing request and a summarization request is one message long, so the prompt was swapped for the caller's own message and an ordinary answer was stored as the conversation summary. - Recovery no longer retries a turn whose tools already ran. A retry restarts the provider's round loop from zero, which would execute side-effecting tools a second time. - The rewind baseline is captured per attempt instead of per turn. Once compaction shortened the history the old baseline could never be reached again, so failed attempts past the first left duplicate user messages behind (reachable with ContextRecoveryMaxRetries of 2 or more). - A stream that gave up on recovery ended without its terminating Completion chunk or accumulated usage, making the termination contract depend on whether recovery was enabled. - Anthropic's combined form — "input length and `max_tokens` exceed context limit: X + Y > Z" — is now detected. Since max_tokens rides on every request, this is the wording that actually appears, and it previously went unrecognised so recovery never engaged on Anthropic. - MessageChain.SendAsync() and RetryLastMessageAsync() bound to the raw provider overload and bypassed recovery entirely. - Gemini's legacy streaming path was the last HTTP failure site still throwing an untranslated AIServiceException. - RecoverySkipReason now distinguishes recovery-disabled, retries-exhausted, stateless and summarizing, which previously all reported null. Compaction failures preserve the provider's original stack trace. ### Known limitations - DeepSeek and Perplexity do not recover **while streaming**. Both replace the streaming pipeline wholesale (neither supports function calling, so neither needs a round loop) and recovery lives in that loop; an overflow surfaces as a flagged error chunk instead. Their non-streaming path recovers normally. - Non-streaming recovery restarts the provider's round loop, so it stops rather than replaying completed tool rounds. Streaming replays per round and has no such restriction. - A summarization request still consults `SystemMessageProvider`, so a service configured with one contributes its system message to the summary prompt as well. ### Deprecated - AIService.MaxMessageCount and ChatBlock.RemoveFunctionMessages() are [Obsolete] and will be removed in v7.0 — context management becomes token-based only (ConversationPolicy). Requires Mythosia.AI.Abstractions v2.5.0. --- ## Documentation - Basic Usage: https://github.com/AJ-comp/Mythosia.AI/wiki - Advanced Features: https://github.com/AJ-comp/Mythosia.AI/wiki/Advanced-Features - Release Notes: https://github.com/AJ-comp/Mythosia.AI/wiki/Release-Notes - GitHub: https://github.com/AJ-comp/Mythosia.AI |
|
|
Mythosia.AI.Rag
RAG (Retrieval Augmented Generation) orchestration for Mythosia.AI. Implements Mythosia.AI.Rag.Abstractions v6.x. Includes RagPipeline, text splitters, context builder, OpenAI/vLLM embedding providers, hybrid search (BM25 + Vector + RRF), re-ranking (Cohere, LLM, vLLM), Agentic RAG tool registration with per-call RagQueryOptions and structured search traces, search gate, keyword extraction, weighted-blend final selection, progress reporting, DoclingDocument-to-RagDocument conversion, and per-query VectorFilter passthrough (StoreFilter). Depends on Mythosia.AI.Abstractions (IAIService) instead of the full Mythosia.AI implementation. |
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.4.0: Adds the Anthropic Claude Fable 5 model id constant (AIModels.Anthropic.ClaudeFable5 = claude-fable-5) — Anthropic's new top model tier above Opus (1M context window, 128K max output). Additive minor release; no breaking changes.