![]() |
VOOZH | about |
dotnet add package CasCap.Common.AI --version 4.12.1
NuGet\Install-Package CasCap.Common.AI -Version 4.12.1
<PackageReference Include="CasCap.Common.AI" Version="4.12.1" />
<PackageVersion Include="CasCap.Common.AI" Version="4.12.1" />Directory.Packages.props
<PackageReference Include="CasCap.Common.AI" />Project file
paket add CasCap.Common.AI --version 4.12.1
#r "nuget: CasCap.Common.AI, 4.12.1"
#:package CasCap.Common.AI@4.12.1
#addin nuget:?package=CasCap.Common.AI&version=4.12.1Install as a Cake Addin
#tool nuget:?package=CasCap.Common.AI&version=4.12.1Install as a Cake Tool
AI agent framework infrastructure — agent creation, session management, MCP tool/prompt resolution, chat history compaction, and slash-command handling.
dotnet add package CasCap.Common.AI
Provides the shared infrastructure for building multi-agent AI systems with support for multiple providers (Azure OpenAI, OpenAI, Ollama), automatic MCP tool discovery from [McpServerTool]-decorated service types, sub-agent delegation (fan-out pattern), persistent session state, and context-window compaction for edge GPU devices.
This library contains no domain-specific MCP query services — those live in downstream consumer projects. It provides the framework that consumer projects use to wire agents, tools, sessions, and prompts together.
Target frameworks: net10.0
| Type | Description |
|---|---|
AgentCommandHandler |
Shared handler for ChatCommand slash-commands (/session info, /session reset, /model, etc.) and agent session persistence |
ToolOutputStrippingChatReducer |
IChatReducer that strips FunctionCallContent/FunctionResultContent from older messages while retaining a sliding window of recent exchanges — critical for reducing context size on edge devices |
InMemorySessionStore |
Volatile in-memory ISessionStore backed by ConcurrentDictionary |
DistributedCacheSessionStore |
Redis-backed ISessionStore wrapping IDistributedCache with sliding expiry |
InMemoryPollTracker |
In-memory IPollTracker with automatic TTL-based expiry for agent-created polls |
| Interface | Description |
|---|---|
ISessionStore |
Persistence abstraction for serialised agent session state (GetAsync, SetAsync, DeleteAsync, ListKeysAsync) |
IPollTracker |
Tracks active polls created by agents and records incoming votes (TrackPoll, RecordVote, GetPoll, RemovePoll, GetActivePolls) |
| Class | Key Methods |
|---|---|
AgentExtensions |
CreateAgent — creates IChatClient + AIAgent from config (Ollama, AzureOpenAI, OpenAI); RunAnalysisAsync — runs inference returning AgentRunResult; CreateToolsFromServiceProvider<T> — discovers [McpServerTool] methods as AITools; CreateToolsForAgent — resolves all tool sources with include/exclude filters; CreateAgentTool — wraps a peer agent as a callable AITool (delegation); ResolveInstructions — resolves from embedded resource, file, or inline string; TranscodeToWavAsync — audio transcode via ffmpeg |
ChatCommandParser |
TryParseCommand — parses / slash-commands; TryCompactSession — manual session compaction; GetStateBagEntries — session state diagnostics |
| Type | Description |
|---|---|
AIConfig |
Root configuration record (IAppConfig) — Providers, Agents, McpUrl, InstructionsPrefix/Suffix, TimeZoneId, PollTtlMs, SessionTtlDays |
AgentConfig |
Per-agent behavioural config — Provider, Instructions/InstructionsSource, MaxMessages (compaction depth), Tools (tool sources), Prompts (prompt sources), Enabled |
ProviderConfig |
AI provider infrastructure config — Type (AgentType), Endpoint, ModelName, ReasoningEffort, ApiKey |
| Type | Description |
|---|---|
AgentRunResult |
Accumulated result of an AI agent run — output text, token usage, tool calls, attachments, timing, streaming support |
AgentRunAttachment |
Binary attachment produced by a tool during an agent run (Base64Content, MimeType, FileName) |
AgentInfo |
MCP-friendly projection of AgentConfig (all properties carry [Description]) |
ProviderInfo |
MCP-friendly projection of ProviderConfig excluding sensitive fields (all properties carry [Description]) |
ToolSource |
Identifies a tool source — in-process Service, remote Endpoint, or peer Agent (fan-out delegation) with IncludeTools/ExcludeTools filters |
PromptSource |
Identifies a prompt source — in-process Service or remote Endpoint with include/exclude filters |
ToolCallInfo |
Captures a single tool/function call name and arguments |
McpPromptDescriptor |
Lightweight descriptor for an MCP prompt (remote or in-process) |
ActivePoll |
Tracks an active poll with thread-safe vote recording and result summary |
PollStatusResult |
MCP tool result summarising a poll's current vote tally (all properties carry [Description]) |
AudioDebugArtifacts |
Captures original and transcoded audio bytes for debug messages |
StateBagEntry |
Summary of a single AgentSessionStateBag entry (key, size, message counts) |
| Enum | Values |
|---|---|
AgentType |
None, AzureOpenAI, AzureAIFoundry, Ollama, OpenAI |
ChatCommand |
Help, SessionInfo, SessionReset, SessionBypass, SessionCompact, SessionDisable, SessionEnable, SessionSave, SessionLoad, SessionDelete, Model, Instructions |
Agent framework infrastructure showing how AgentExtensions creates agents and resolves tools from multiple source types:
graph TD
classDef core fill:#dbeafe,stroke:#3b82f6,color:#1e3a8a
classDef service fill:#d1fae5,stroke:#10b981,color:#064e3b
classDef config fill:#fef3c7,stroke:#f59e0b,color:#78350f
classDef store fill:#e0f2fe,stroke:#0284c7,color:#0c4a6e
AE["AgentExtensions"]:::core
subgraph AgentCreation["Agent Creation"]
CREATE["CreateAgent()<br/>(IChatClient + AIAgent)"]:::core
RUN["RunAnalysisAsync()<br/>(AgentRunResult)"]:::core
end
subgraph ToolResolution["Tool Resolution"]
SVC_TOOLS["CreateToolsFromServiceProvider<T>()<br/>(discovers [McpServerTool] methods)"]:::core
AGENT_TOOL["CreateAgentTool()<br/>(wraps peer agent as AITool)"]:::core
HTTP_TOOLS["GetHttpTools()<br/>(remote MCP endpoint)"]:::core
FILTER["FilterTools()<br/>(include/exclude)"]:::core
end
subgraph Providers["Provider Support"]
OLLAMA["Ollama"]:::config
AZURE["Azure OpenAI"]:::config
OPENAI["OpenAI"]:::config
end
subgraph SessionMgmt["Session Management"]
CMD["AgentCommandHandler<br/>(slash-commands)"]:::service
MEM_STORE["InMemorySessionStore"]:::store
DIST_STORE["DistributedCacheSessionStore<br/>(Redis)"]:::store
end
subgraph Compaction["Chat History Compaction"]
REDUCER["ToolOutputStrippingChatReducer<br/>(IChatReducer)"]:::service
end
subgraph Polling["Poll Tracking"]
POLL["InMemoryPollTracker"]:::service
end
AE --> AgentCreation
AE --> ToolResolution
CREATE --> Providers
CREATE -.configures.-> REDUCER
CMD --> MEM_STORE
CMD --> DIST_STORE
AgentExtensions.ResolveInstructions resolves the InstructionsSource property on each AgentConfig using a two-step fallback:
If neither source is found an exception is thrown. The fallback Instructions string property can still be used for simple inline text.
Long conversations accumulate large context windows — especially from verbose tool call/result JSON payloads. Automatic compaction is configured per-agent via AgentConfig.MaxMessages.
When MaxMessages is set to a positive value, AgentExtensions.CreateAgent configures the agent's InMemoryChatHistoryProvider with a ToolOutputStrippingChatReducer that:
FunctionCallContent or FunctionResultContent (the primary source of context bloat).MaxMessages non-system exchanges.The reducer runs automatically before each agent invocation. Set MaxMessages to 0 or null to disable automatic compaction.
AgentExtensions exposes an ambient AsyncLocal compaction callback so host services can observe when compaction occurs:
AgentExtensions.SetCompactionCallback((inputCount, outputCount, toolDropped, windowTrimmed, target) =>
{
// e.g. send a debug notification
});
| Parameter | Description |
|---|---|
inputCount |
Total messages before compaction |
outputCount |
Total messages after compaction |
toolDropped |
Messages dropped because they consisted solely of FunctionCallContent / FunctionResultContent |
windowTrimmed |
Messages dropped by the sliding window to meet the MaxMessages target |
target |
The configured MaxMessages value |
Each agent uses its own AgentSession keyed by AgentConfig.Name. Sub-agents invoked via the fan-out pattern (ToolSource.Agent) create a fresh stateless session per invocation, ensuring no cross-agent context leakage.
| Store | Implementation | Use Case |
|---|---|---|
InMemorySessionStore |
ConcurrentDictionary |
Console app (volatile) |
DistributedCacheSessionStore |
Redis via IDistributedCache |
Server / background service (persistent) |
| Package | Purpose |
|---|---|
| Azure.AI.OpenAI | Azure OpenAI client |
| Microsoft.Agents.AI | Agent framework |
| Microsoft.Extensions.AI | AI abstractions (ChatMessage, ChatRole) |
| Microsoft.Extensions.AI.Abstractions | AI abstraction interfaces |
| Microsoft.Extensions.AI.OpenAI | OpenAI provider for Microsoft.Extensions.AI |
| ModelContextProtocol | MCP server attributes and types |
| OllamaSharp | Ollama .NET client |
| Project | Purpose |
|---|---|
CasCap.Common.Abstractions |
Shared abstractions and interfaces |
CasCap.Common.Caching |
Redis caching abstractions |
CasCap.Common.Extensions |
Shared extension helpers |
CasCap.Common.Logging.Serilog |
Serilog structured logging configuration |
This project is released under . See the file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.12.1 | 59 | 6/14/2026 |
| 4.12.0 | 56 | 6/12/2026 |
| 4.11.9 | 93 | 6/10/2026 |
| 4.11.8 | 116 | 5/27/2026 |
| 4.11.7 | 108 | 5/27/2026 |
| 4.11.6 | 121 | 5/26/2026 |
| 4.11.5 | 106 | 5/22/2026 |
| 4.11.4 | 103 | 5/20/2026 |
| 4.11.3 | 105 | 5/13/2026 |
| 4.11.2 | 108 | 5/11/2026 |
| 4.11.1 | 101 | 5/11/2026 |
| 4.11.0 | 114 | 5/8/2026 |
| 4.10.5 | 101 | 5/4/2026 |
| 4.10.4 | 99 | 5/2/2026 |
| 4.10.3 | 132 | 4/24/2026 |
| 4.10.2 | 111 | 4/24/2026 |
| 4.10.1 | 120 | 4/23/2026 |