Mythosia.AI.Abstractions 3.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mythosia.AI.Abstractions --version 3.1.0
                    
NuGet\Install-Package Mythosia.AI.Abstractions -Version 3.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mythosia.AI.Abstractions" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mythosia.AI.Abstractions" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Mythosia.AI.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mythosia.AI.Abstractions --version 3.1.0
                    
#r "nuget: Mythosia.AI.Abstractions, 3.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mythosia.AI.Abstractions@3.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mythosia.AI.Abstractions&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Mythosia.AI.Abstractions&version=3.1.0
                    
Install as a Cake Tool

Mythosia.AI.Abstractions

Core contracts and shared models for the Mythosia.AI ecosystem. Defines IAIService, the optional IAIRunService, IAIRequestFeatureService and IImageGenerationService capabilities, provider-neutral 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.

Upgrading to v3? This is the abstractions release paired with Mythosia.AI v7. See the v3.0 release notes and migration guide.

Current release: 3.1.0

The Run and request-feature capabilities, GPT-6 Astra contracts, common reasoning/search options, citations, and AllowAsync metadata require Mythosia.AI.Abstractions 3.1.0 or later. Use Mythosia.AI 7.1.0 or later for the supplied provider implementations. The new capabilities are optional; existing IAIService implementations gain no required members. See the v3.1.0 release notes.

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; }

    Task<string> GetCompletionAsync(
        string prompt,
        AIRequestProfile? profile = null,
        AIRequestContext? context = null);

    Task<string> GetCompletionAsync(
        Message message,
        AIRequestProfile? profile = null,
        AIRequestContext? context = null);

    IAsyncEnumerable<string> StreamAsync(string prompt, CancellationToken ct = default);
    IAsyncEnumerable<string> StreamAsync(
        Message message,
        AIRequestContext? context = null,
        CancellationToken ct = default);

    IAsyncEnumerable<StreamingContent> StreamAsync(
        string prompt,
        StreamOptions options,
        CancellationToken ct = default);

    IAsyncEnumerable<StreamingContent> StreamAsync(
        Message message,
        StreamOptions options,
        AIRequestContext? context = null,
        CancellationToken ct = default);
}

All concrete providers (OpenAIService, AnthropicService, GoogleAIService, etc.) in Mythosia.AI implement this interface.


IAIRunService and AIRun

Libraries that need to display or cancel ongoing work can depend on IAIRunService without referencing a concrete provider. See the Run guide for application examples.

To adjust effort for a task or ground an answer in hosted sources without coupling middleware to a provider, use optional IAIRequestFeatureService. Its WithReasoning, WithWebSearch and WithFileSearch extensions retain the concrete service type, copy settings for the next logical request, and reject unsupported capabilities explicitly. AICitation, StreamingContent.Citation and AIRun.Citations carry provider source references independently of text observation. Existing IAIService implementations need no new required members. See reasoning and search for scope, provider support and citation indexing.

Run startup is an optional capability, so existing custom IAIService implementations gain no mandatory members. It exposes StartRunAsync overloads for string and Message input with onText, streaming options, request context, and cancellation.

using Mythosia.AI.Services;

if (service is IAIRunService runService)
{
    await using var run = await runService.StartRunAsync(
        "Summarize the documents.",
        onText: text => Console.Write(text),
        cancellationToken: cancellationToken);
    string answer = await run.Result;
}

AIRun is in Mythosia.AI.Models.Runs. It exposes Result, output-only StreamAsync, CanSteer, SteerAsync, Cancel, and DisposeAsync. A single event reader may accompany the text callback. Execution and result collection continue without an event reader; see the run guide for buffering and lifetime contracts.

IImageGenerationService

Image generation is an optional provider capability rather than part of the LLM-focused IAIService contract. Consumers can depend on the abstraction without assuming that every chat provider can generate images.

using Mythosia.AI.Models.Images;
using Mythosia.AI.Services;

if (service is IImageGenerationService imageService)
{
    ImageGenerationResult result = await imageService.GenerateImagesAsync(
        new ImageGenerationRequest
        {
            Prompt = "A glass pavilion at sunrise",
            Count = 1,
            Size = "1024x1024"
        });

    IReadOnlyList<GeneratedImage> images = result.Images;
}

DefaultImageModel is independent from IAIService.Model. ImageEditRequest adds ordered InputImages and an optional Mask; provider support varies. OpenAI supports mask editing, while Gemini accepts reference images but rejects a separate mask and requires Count = 1.


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, including AIModels.OpenAI.Gpt6Astra (gpt-6-astra), GPT-5.6, and Grok 4.5/current xAI aliases
Gpt6Reasoning GPT-6 Astra reasoning effort (Auto, Low, Medium, High, XHigh, Max); reasoning cannot be disabled
Gpt6ReasoningMode Standard or Pro reasoning execution on the same GPT-6 Astra model ID
Gpt5_6Reasoning GPT-5.6 reasoning effort (Auto, None, Low, Medium, High, XHigh, Max)
Gpt5_6ReasoningMode Standard or Pro reasoning execution; Pro is a request mode, not a separate GPT-5.6 model ID
GrokReasoning xAI reasoning effort (Auto, None, Low, Medium, High); valid levels depend on the selected Grok model
AIProvider Provider enum (OpenAI, Anthropic, Google, xAI, DeepSeek, Perplexity)
ImageGenerationRequest Provider-neutral prompt and output controls for generating one or more images
ImageEditRequest Image-generation request with ordered reference images and an optional mask
ImageInput Binary image input with MIME type and file name
GeneratedImage Generated bytes, MIME type, optional URL, and revised prompt
ImageGenerationResult Images plus provider, model, request ID, and optional token usage

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 input, cache creation, 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 with optional AllowAsync permission (default false)
FunctionCall One typed provider function call with ID, order, arguments, provider metadata, and actual provider IsAsync status
FunctionCallBatch Ordered calls returned by one assistant response
FunctionCallResult Output or isolated error for one call
FunctionCallResultBatch Results correlated to one function-call batch; native async delivery can be partial
FunctionCallingPolicy Controls function calling behavior and iteration limits
FunctionExecutionMode Selects sequential or bounded-parallel execution for ordinary calls; opted-in async jobs use a separate MaxConcurrency limit
AiFunctionAttribute Marks a method as an AI-callable function, with optional AllowAsync permission (default false)
AiParameterAttribute Describes a function parameter for the AI

When a slow lookup leaves room for independent model work, such as giving general advice while waiting for a forecast, AllowAsync permits the two to overlap on a supporting provider, model, and API. The implementation currently enables it for GPT-6 Astra through Responses; other connections omit the API option and wait for the same handler's result. The permission is preserved when switching models. FunctionCall.IsAsync records the provider's actual call status, so enabling the permission does not guarantee async execution. In Mythosia.AI, FunctionBuilder.WithAsync() is the fluent equivalent of AllowAsync = true.

This is separate from Task-returning handlers and FunctionExecutionMode.Parallel. Pending function jobs belong to the existing completion or streaming request; they are completed and cleaned up before that request ends. Handlers do not receive cancellation tokens, so cancelling or disposing the request does not interrupt an already-started handler.

Exceptions

Type Description
AIServiceException Base exception for AI service errors
AgentMaxStepsExceededException Thrown when agent exceeds maximum iteration steps
ContextLengthExceededException Provider context-window rejection with recovery metadata when available
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

IAIService is Mythosia.AI's provider-neutral contract and is independent from Microsoft.Extensions.AI.IChatClient. It exposes Mythosia-specific stateful sessions (ChatBlock), request profiles and contexts, typed streaming events, and the built-in multi-round function loop. This package does not implement or reference IChatClient, and the two interfaces are not implicitly interchangeable.

Applications that use both ecosystems should put an explicit adapter at their integration boundary and decide how message history, tool execution, streaming metadata, and usage are mapped. Keeping that conversion explicit avoids silently losing semantics when either abstraction evolves.


Why This Package?

Mythosia.AI.Rag  →  Mythosia.AI.Abstractions  (no provider SDK 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.


Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Mythosia.AI.Abstractions:

Package Downloads
Mythosia.AI

Build .NET applications with multiple AI providers through consistent completion, streaming and tool workflows. Supports OpenAI GPT-6.1 Sol and GPT-6 Astra/Sol/Luna, Anthropic including Claude Sonnet 5.5 and Opus 5.5, Google, xAI including Grok 4.7, DeepSeek Flash/V4 Pro and Perplexity. Includes immutable request builders, controllable Runs, typed output, cancellable local tools, reasoning, search/citations, image generation/editing, capability inspection and per-request processing-speed observations. Targets .NET Standard 2.1; requires Mythosia.AI.Abstractions 4.2.0. What's New in v8.2.0: GPT-6.1 Sol adds mandatory reasoning, Responses tools and native Run support; Sonnet 5.5 adds adaptive/high defaults and explicit between-tools thinking. Request preparation captures effective settings, runs profile hooks once and validates before side effects. Nested auxiliary requests isolate parent state; forwarded profile changes preserve later request-local tool and policy edits. Claude retains signed and tool history across projection, counting and permitted compaction, preserves persistent instructions, and serializes valid lowercase tool schemas. Streaming fixes cover producer cleanup, HTTP error-body cancellation, identifiable HttpClient timeouts and preservation of outcomes during response disposal. OpenAI Run honors configured endpoints and preserves steering order, cancellation boundaries and terminal outcomes. Existing public execution APIs and service defaults remain. Known limitations: Sonnet 5.5/Opus 5.5 pauses ending in a pending server_tool_use can be rejected before continuation. Custom buffering HTTP content can delay successful SSE body acquisition past cancellation or timeout, retaining the active Run. These cases remain unfixed. Full release notes: https://github.com/AJ-comp/Mythosia.AI/blob/main/src/core/Mythosia.AI/RELEASE_NOTES.md#v820

Mythosia.AI.Rag

Ground AI answers in application-managed documents with loading, splitting, embeddings, vector/text/hybrid retrieval, reranking and metadata filters. Provides standard and Agentic RAG, streaming runs, cancellation and optional PIXIE search. Supports Voyage Context 4, Gemini Embedding 2, OpenAI, Ollama and Perplexity embeddings. Retrieval-aware providers distinguish documents from queries and receive complete ordered document inputs; existing IEmbeddingProvider implementations remain compatible. Validates embedding results before document replacement and isolates query rewriting and reranking. Depends on Mythosia.AI.Abstractions and Mythosia.AI.Rag.Abstractions without referencing the full Mythosia.AI implementation. What's New in v8.3.0: Diagnostics use optional IVectorStoreDiagnostics and InMemory 4.3.0; migrate old InMemory diagnostic interface casts. This minor release intentionally includes a breaking interface migration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.2.0 176 10/3/2026
4.1.0 284 9/24/2026
4.0.0 198 9/13/2026
3.1.0 210 9/8/2026
3.0.0 244 8/8/2026
2.5.0 229 7/23/2026
2.4.0 275 6/10/2026
2.3.0 280 5/30/2026
2.2.0 737 4/28/2026
2.2.0-preview1 239 4/25/2026
2.1.0 478 4/16/2026
2.0.0 600 4/3/2026
1.1.0 233 4/2/2026
1.0.0 310 3/29/2026

v3.1.0 adds optional Run and request-feature capabilities, AIRun, common reasoning and hosted-search options, citations, GPT-6 Astra contracts, and opt-in asynchronous function metadata. Existing IAIService implementations gain no required members; existing streaming enum values are preserved. Full notes: https://github.com/AJ-comp/Mythosia.AI/blob/main/src/core/Mythosia.AI.Abstractions/RELEASE_NOTES.md#v310