Mythosia.AI.Abstractions
2.2.0
dotnet add package Mythosia.AI.Abstractions --version 2.2.0
NuGet\Install-Package Mythosia.AI.Abstractions -Version 2.2.0
<PackageReference Include="Mythosia.AI.Abstractions" Version="2.2.0" />
<PackageVersion Include="Mythosia.AI.Abstractions" Version="2.2.0" />
<PackageReference Include="Mythosia.AI.Abstractions" />
paket add Mythosia.AI.Abstractions --version 2.2.0
#r "nuget: Mythosia.AI.Abstractions, 2.2.0"
#:package Mythosia.AI.Abstractions@2.2.0
#addin nuget:?package=Mythosia.AI.Abstractions&version=2.2.0
#tool nuget:?package=Mythosia.AI.Abstractions&version=2.2.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.4.0 ### Streaming Diagnostics (service-level) - New WithStreamDiagnostics(d => d.OnRawLine(...).OnComplete(...)) extension on AIService — register once and every subsequent StreamAsync call automatically invokes the hooks. Same fluent builder pattern as WithRag. - OnRawLine fires for every SSE line received (Debug-level trace of the wire payload). OnComplete fires exactly once on stream exit, success or failure, with a StreamDiagnostics snapshot (LinesRead, AccumulatedTextLength, LastRawLine, Elapsed). - Read-time exceptions are wrapped in StreamReadException with Diagnostics attached and the original exception in InnerException — works regardless of whether WithStreamDiagnostics is registered. - Especially useful against self-hosted vLLM / ollama / unstable proxies, where "the stream just stopped" needs to be told apart from "transport error after N chunks". ### Fixed: NotSupportedException at await foreach ... DisposeAsync() - Replaced the synchronous using (var stream = ...) pattern across all 5 providers (10 SSE loops) with async stream disposal via the new ReadSseLinesAsync helper. Eliminates NotSupportedException thrown by HTTP transports whose stream rejects synchronous Dispose. - The helper's finally block now guards every disposal step with try/catch so a Dispose-time failure cannot mask the real read-side exception, and OnComplete is guaranteed to fire even when disposal fails. ### Fixed: CopyFrom now propagates service-level callbacks - AIService.CopyFrom(source) was silently dropping SystemMessageProvider (declared in v6.3.0 but missing from CopyFrom), StreamRawLineCallback, and StreamCompleteCallback. - These delegates are now propagated by reference, so cross-provider switches (e.g., new AnthropicService(...).CopyFrom(openaiService) in a multi-provider chat UI) keep the registered diagnostics and system-message provider working without re-registration. ### Internal - 5 provider streaming implementations (OpenAI/Grok/Qwen/vLLM, Anthropic, Google, DeepSeek, Perplexity) consolidated to a single ReadSseLinesAsync helper. Removes 9 duplicate SSE-reading loops. Requires Mythosia.AI.Abstractions v2.2.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.2.0: add streaming diagnostics primitives — StreamDiagnostics (LinesRead, DataLinesProcessed, ParseFailures, AccumulatedTextLength, LastRawLine, Elapsed), StreamReadException (wraps IOException/NotSupportedException/etc. with the diagnostics snapshot taken at failure time), and StreamDiagnosticsBuilder (fluent configurator consumed by the new WithStreamDiagnostics extension in Mythosia.AI). Lets callers observe SSE streams (RawLine trace + OnComplete telemetry) and tell "stream silently ended" apart from "transport error after N chunks" — useful against self-hosted vLLM/ollama and unstable proxies. Additive API update; no existing types changed.