Ananke.AspNetCore
0.7.2
dotnet add package Ananke.AspNetCore --version 0.7.2
NuGet\Install-Package Ananke.AspNetCore -Version 0.7.2
<PackageReference Include="Ananke.AspNetCore" Version="0.7.2" />
<PackageVersion Include="Ananke.AspNetCore" Version="0.7.2" />
<PackageReference Include="Ananke.AspNetCore" />
paket add Ananke.AspNetCore --version 0.7.2
#r "nuget: Ananke.AspNetCore, 0.7.2"
#:package Ananke.AspNetCore@0.7.2
#addin nuget:?package=Ananke.AspNetCore&version=0.7.2
#tool nuget:?package=Ananke.AspNetCore&version=0.7.2
Ananke.AspNetCore
ASP.NET Core integration helpers for Ananke — SSE streaming, ChatSessionEvent-to-SSE bridging, state-machine endpoint utilities, provider configuration, and session management.
Install
dotnet add package Ananke.AspNetCore
Quick start
SSE streaming
using Ananke.AspNetCore.Sse;
app.MapPost("/api/chat", async (ChatRequest request, HttpContext context, CancellationToken ct) =>
{
// One call sets Content-Type + Cache-Control headers
context.Response.EnableSse();
// Write named SSE events with JSON data
await context.Response.WriteSseAsync("session", new { sessionId = "abc" });
await context.Response.WriteSseAsync("delta", new { text = "Hello!" });
await context.Response.WriteSseAsync("done", new { text = "Hello!" });
});
ChatSessionEvent → SSE bridge
Pipe a StreamingChatWorkflow event stream directly to an HTTP response:
using Ananke.AspNetCore.Sse;
var events = StreamingChatWorkflow.Create("chat", model)
.WithSystemPrompt("You are helpful.")
.BuildStream(messages, ct);
await events.WriteSseAsync(context.Response);
Or via a delegate (useful for session-based scenarios where the writer is re-bound per request):
await events.WriteSseAsync(
writeSse: myWriteDelegate,
onError: msg => logger.LogError("Error: {Msg}", msg));
Event mapping:
ChatSessionEvent |
SSE event name |
|---|---|
TextDeltaEvent |
delta |
AudioDeltaEvent |
audio_delta |
ToolCallEvent |
tool_call |
ToolResultEvent |
tool_result |
InterruptedEvent |
interrupted |
ResumedEvent |
resumed |
ErrorEvent |
error |
CompletedEvent |
(silently consumed) |
State-machine SSE loop
Await a state machine's CurrentWork through phase transitions, surviving interrupt-induced cancellation races:
using Ananke.AspNetCore.Sse;
await machine.FireAsync(MyAction.Start);
var reachedDone = await machine.RunSseLoopAsync(MyPhase.Done);
if (reachedDone)
await context.Response.WriteSseAsync("done", new { });
Provider configuration
Register LLM providers at startup and read settings from IConfiguration:
using Ananke.AspNetCore.Configuration;
// Register providers (typically in Program.cs)
AgentModelFactory.RegisterProvider("OpenAI",
defaultModel: "gpt-4.1-mini",
agentFactory: (key, model) => OpenAIChatAgentModel.Create(key, model),
embeddingFactory: (key, model) => OpenAIEmbeddingModel.Create(key, model));
AgentModelFactory.RegisterProvider("Google",
defaultModel: "gemini-2.5-flash",
agentFactory: (key, model) => GeminiAgentModel.Create(key, model));
// Read from configuration (secrets.json / appsettings.json)
// { "Provider": "OpenAI", "OpenAI": { "ApiKey": "sk-...", "Model": "gpt-4.1-mini" } }
var profile = AgentModelFactory.FromConfiguration(builder.Configuration);
var agentModel = profile.CreateAgentModel();
var embedder = profile.CreateEmbeddingModel(); // null if not configured
Session store
Thread-safe in-memory session management:
using Ananke.AspNetCore.Sessions;
var sessions = new InMemorySessionStore<MySession>();
// Atomic get-or-create
var session = sessions.GetOrCreate(sessionId, () => new MySession());
// Lookup
var existing = sessions.Get(sessionId); // null if missing
sessions.TryGet(sessionId, out var s); // bool pattern
// Cleanup
sessions.Remove(sessionId);
var removed = sessions.RemoveAndGet(sessionId); // remove + return
Features
EnableSse()— one-liner SSE response header setupWriteSseAsync(name, data)— JSON-serialized SSE event writing with flushChatSessionEvent→ SSE bridge — maps all workflow event types to named SSE eventsRunSseLoopAsync(terminalState)— reusable state-machine await loop with interrupt-race handlingAgentModelFactory— registry-based provider configuration fromIConfigurationProviderProfile— immutable settings record withCreateAgentModel()/CreateEmbeddingModel()InMemorySessionStore<T>—ConcurrentDictionary-backed thread-safe session store
Related packages
| Package | What it adds |
|---|---|
Ananke.Orchestration |
Workflow builder, agents, ChatSessionEvent, StreamingChatWorkflow |
Ananke.StateMachine |
State machine engine with OnEnter work and interrupt support |
Ananke.Orchestration.OpenAI |
OpenAI IStreamingAgentModel + IEmbeddingModel provider |
Ananke.Orchestration.Google |
Google Gemini IStreamingAgentModel + IEmbeddingModel provider |
Ananke.Orchestration.Anthropic |
Anthropic / Claude IStreamingAgentModel provider |
Documentation
Full docs, demos, and architecture: github.com/sevensamurai/Ananke
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Ananke.Orchestration (>= 0.7.2)
- Ananke.StateMachine (>= 0.7.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.