NewLife.AI
1.7.2026.1024
See the version list below for details.
dotnet add package NewLife.AI --version 1.7.2026.1024
NuGet\Install-Package NewLife.AI -Version 1.7.2026.1024
<PackageReference Include="NewLife.AI" Version="1.7.2026.1024" />
<PackageVersion Include="NewLife.AI" Version="1.7.2026.1024" />
<PackageReference Include="NewLife.AI" />
paket add NewLife.AI --version 1.7.2026.1024
#r "nuget: NewLife.AI, 1.7.2026.1024"
#:package NewLife.AI@1.7.2026.1024
#addin nuget:?package=NewLife.AI&version=1.7.2026.1024
#tool nuget:?package=NewLife.AI&version=1.7.2026.1024
NewLife.AI
🌐 简体中文 | 繁體中文 | Español | Deutsch | 日本語 | Français | Português | Русский | 한국어 | العربية
Introduction
NewLife.AI is an open-source AI foundation library for the .NET ecosystem, providing a unified IChatClient interface that wraps 46 mainstream LLM providers. It features built-in function calling, MCP protocol, streaming output, multimodal support, multi-agent capabilities, and can be embedded as a NuGet package in any .NET project (net45 → net10.0, NativeAOT ready).
The library ships 31 runtime languages (English source with automatic fallback) and targets Windows, Linux, macOS, Android and iOS across x64 / x86 / arm64 / arm / loongarch64 / riscv64 / s390x.
NewLife.ChatAI is a complete web chat application built on NewLife.AI (ASP.NET Core), offering an out-of-the-box multi-model chat frontend, a unified AI gateway, and automatic memory evolution. It can be deployed standalone or embedded into existing ASP.NET Core projects via NuGet.
Core Features
- NativeAOT Ready:
IsAotCompatibleon net8.0/net10.0, 38-scenario NativeAOT smoke matrix across Windows / Linux / macOS and x64 / arm64 / loongarch64 - 31 Runtime Languages: English source messages with compiled locale tables; missing translations fall back to English, no code changes needed for new languages
- 46 AI Providers, 6 Protocols: OpenAI / Anthropic / Gemini / Tongyi DashScope / Ollama / AWS Bedrock — switch with a single line of code
- Unified
IChatClientInterface: Aligned with MEAI specification — single-turn, streaming, function calling, multimodal all via a single API - Function Calling (Tools):
[ToolDescription]attribute auto-generates JSON Schema;ToolChatClientmulti-turn loop; built-in search / weather / translation / web scraping / IP geolocation tools - Bidirectional MCP Support: Client connects to external MCP Servers (stdio / HTTP SSE); Server exposes local tools as standard MCP services
- Complete Chat Kernel:
IChatHandlerthree-stage pipeline (OnBefore → Execute → OnAfter), built-in handlers (skill activation / memory injection / persistence / usage tracking / title generation), pluggableIChatFilter - User Memory Evolution: Automatically extracts 10 categories of structured memories from conversations — the more you chat, the better it understands you
- Unified AI Gateway: Compatible with OpenAI / Anthropic / Gemini protocols; snake_case/camelCase auto-adaptation; AppKey multi-tenancy; upstream 429 exponential backoff retry
- Skill System: Markdown prompt reuse,
@recursive references, trigger-word auto-activation - Multi-Agent:
ConversableAgent/GroupChat/ParallelGroupChat/FunctionCallingPlanner - React 19 Web Frontend: SSE streaming + chat presets + Artifact real-time preview (HTML/SVG/Mermaid) + conversation branching + tool call visualization + reasoning timing + multimodal
- Knowledge Evolution Layer: Automatically distills knowledge from conversations, builds a searchable knowledge base with TOC browsing and vector semantic search
- TTS Speech Synthesis: DashScope TTS and CosyVoice V3.5 support; streaming speech synthesis; dedicated frontend TTS API
- Embedding / Vector Retrieval: Built-in HashTextEmbedder v2 and vector storage; knowledge base document vectorization and semantic search
- Multi-Agent Enhancement: New ReflectionAgent and ReviewAgent; complex task decomposition with parallel sub-agent aggregation
- Human-in-the-Loop Checkpoints: Real-time human selection among AI multi-path options; multi-question group decision checkpoints
- Tool Call Enhancement: ToolCallContext context propagation; tool Provider circuit breaker; session-level tool visibility filtering; structured error returns with three-tier permission system
- Memory Evolution: Memory consolidation service with dedup/merge/expiry; learning memory auto-extracts structured knowledge from conversations
Supported AI Providers
46 providers: 9 independent protocol clients + 37 OpenAI-compatible adapters.
Independent Protocol Implementations (9)
| Provider | Protocol | Features |
|---|---|---|
| OpenAI | ChatCompletions / Responses | Vision / Function Calling / Image Generation / o3 Reasoning |
| DeepSeek | DeepSeek API | reasoning_content / DeepSeek v4 exclusive parameters |
| Anthropic | Messages | Claude 3.5 / Claude 4 |
| Gemini | Gemini 1.5 / 2.0 / 2.5 | |
| Alibaba Cloud | DashScope | qwen-plus / qwen-max / Omni multimodal / Files API |
| Azure AI | Azure OpenAI | Deployment name URL + api-key |
| Ollama | Ollama API | Local llama / deepseek / qwen |
| AWS Bedrock | SigV4 Signature | Claude / Llama / Titan / Mistral |
| NewLifeAI | Cascade Proxy | Multi-provider aggregation |
| (Others) | OpenAI Compatible | 37 compatible platforms |
OpenAI-Compatible Family (37)
Doubao (Volcano Engine), Zhipu Qingyan (GLM), Wenxin Yiyan, Moonshot (Kimi), MiniMax, StepFun, Baichuan, iFlytek Spark, 01.AI, Mistral, Perplexity, Cohere, Together AI, Fireworks, OpenRouter, SiliconCloud, DeepInfra, Groq, Cerebras, Hyperbolic, Nebius, Novita, Lepton, 302.AI, xAI (Grok)… and other OpenAI-compatible platforms.
All providers are declared via the [AiClient] attribute; AiClientRegistry auto-scans and registers at startup — zero configuration for new providers.
Quick Start
1. AI SDK Only
dotnet add package NewLife.AI
using NewLife.AI.Clients;
// Single-turn chat
using var client = new DashScopeChatClient("your-api-key", "qwen-plus");
var reply = await client.ChatAsync("Explain large language models in three sentences");
Console.WriteLine(reply);
// Multi-role messages (tuple array, no manual ChatMessage construction)
var reply2 = await client.ChatAsync([
("system", "You are a professional C# development assistant"),
("user", "Explain the difference between ValueTask and Task"),
]);
// Streaming output
await foreach (var chunk in client.GetStreamingResponseAsync([
new ChatMessage { Role = "user", Content = "Write a short poem about code" }
], new ChatOptions()))
{
Console.Write(chunk.Text);
}
2. ASP.NET Core Dependency Injection
dotnet add package NewLife.AI.Extensions
// Register service
builder.Services.AddDashScope("your-api-key", "qwen-plus");
// Keyed multi-provider coexistence
builder.Services.AddOpenAI("openai-key", serviceKey: "openai");
builder.Services.AddAnthropic("anthropic-key", serviceKey: "anthropic");
// Inject and use
public class MyService(IChatClient chatClient)
{
public Task<String> ChatAsync(String question)
=> chatClient.ChatAsync(question);
}
3. Function Calling (Tools)
public class MyTools
{
/// <summary>Get weather for a specified city</summary>
[ToolDescription("get_weather")]
public async Task<String> GetWeatherAsync(
[Description("City name")] String city)
=> $"{city}: Sunny, 22°C today";
}
// Register tools
var registry = new ToolRegistry();
registry.AddTools<MyTools>(new MyTools());
// Add to pipeline — automatic multi-turn tool calling loop
var client = rawClient.AsBuilder()
.UseTools(registry)
.Build();
// Model auto-calls get_weather("Beijing"), returns final text answer
var reply = await client.ChatAsync("What's the weather like in Beijing today?");
4. Constrained Reasoning (ReAct Pattern)
When the AI tends to guess or take shortcuts on complex problems, use the ReAct format in the System Prompt to enforce step-by-step reasoning. ToolChatClient has a built-in while loop (MaxIterations = 10) — no need to hand-write an Agent. Combine with a ReAct System Prompt to further constrain the reasoning direction at each step.
// UseTools pipeline: ToolChatClient loops automatically until the model stops calling tools
var client = rawClient.AsBuilder()
.UseTools(registry)
.Build();
// ReAct System Prompt: Thought → Action → Observation → Answer enforces step-by-step reasoning
var reply = await client.ChatAsync([
("system",
"You must reason step by step in the following format. Do not skip steps or guess directly:\n" +
"Thought: <analyze what needs to be done>\n" +
"Action: <which tool to call and parameters>\n" +
"Observation: <analyze the tool result>\n" +
"(Repeat Thought/Action/Observation until sufficient information is gathered)\n" +
"Answer: <final conclusion based on the above observations>\n\n" +
"Rule: Do not give an Answer without first calling a tool."),
("user", "Is the weather in Beijing suitable for outdoor sports today?"),
]);
5. Run the Full Web Chat Application
git clone https://github.com/NewLifeX/NewLife.AI.git
cd NewLife.AI
# Build frontend (requires Node.js + pnpm)
cd Web && pnpm install && pnpm build && cd ..
# Start
cd NewLife.ChatAI
dotnet run --framework net8.0
Open http://localhost:5000 in your browser — SQLite by default, ready out of the box. On first launch, configure provider API keys via /Admin.
You can also embed NewLife.ChatAI into an existing project via NuGet:
dotnet add package NewLife.ChatAI
using NewLife.ChatAI;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddChatAI();
var app = builder.Build();
app.UseChatAI(redirectToChat: true);
app.Run();
API Gateway
NewLife.ChatAI includes a built-in multi-protocol AI gateway. Third-party systems can integrate without modification — all paths go through memory injection and skill enhancement.
| Protocol | Route | Description |
|---|---|---|
| OpenAI ChatCompletions | POST /v1/chat/completions |
Streaming / non-streaming / function calling / vision |
| OpenAI Responses | POST /v1/responses |
o3 / gpt-5 reasoning models |
| Anthropic Messages | POST /v1/messages |
Claude series |
| Google Gemini | POST /v1/gemini/... |
Gemini series |
| Image Generation | POST /v1/images/generations |
Text-to-Image |
| Image Edit | POST /v1/images/edits |
Inpainting (multipart/form-data) |
| Model Discovery | GET /v1/models |
Available model list |
Authentication: Authorization: Bearer sk-xxxx (AppKey)
Features: Upstream 429 exponential backoff retry (random jitter, up to 5 retries); automatic Token usage recording; dual-dimension statistics by AppKey + User
Extension Development
Adding a New AI Provider
Inherit from OpenAIChatClient, add the [AiClient] attribute — AiClientRegistry auto-scans at startup:
[AiClient("MyAI", "My Service", "https://api.myai.com/v1",
Description = "Custom AI Service")]
[AiClientModel("myai-latest", "MyAI Latest", Code = "MyAI",
FunctionCalling = true, Vision = true)]
public class MyAiChatClient : OpenAIChatClient
{
public MyAiChatClient() { }
public MyAiChatClient(String apiKey, String? model = null, String? endpoint = null)
: base(apiKey, model, endpoint) { }
}
Adding a New Tool
public class MyTools
{
/// <summary>Query current time</summary>
[ToolDescription("get_current_time")]
public String GetCurrentTime()
=> DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
var registry = new ToolRegistry();
registry.AddTools<MyTools>(new MyTools());
// DI scenario
services.AddSingleton<IToolProvider>(_ =>
{
var r = new ToolRegistry();
r.AddTools<MyTools>(new MyTools());
return r;
});
Adding a New IChatHandler
Inject custom logic before (OnBefore) or after (OnAfter) chat — e.g., context injection, auditing, logging:
[ChatHandlerOrder(150)]
public class CurrentTimeHandler : ChatHandlerBase
{
public override Task OnBefore(IChatContext context, CancellationToken cancellationToken)
{
context.ContextMessages.Insert(0,
new ChatMessage { Role = "system", Content = $"Current time: {DateTime.Now:yyyy-MM-dd HH:mm}" });
return Task.CompletedTask;
}
}
// DI registration — MessageFlow auto-sorts by ChatHandlerOrderAttribute
services.AddSingleton<IChatHandler, CurrentTimeHandler>();
Adding a New Filter
Onion-ring model for injecting logging, auditing, content moderation before/after chat:
public class AuditFilter : IChatFilter
{
public async Task OnChatAsync(
ChatFilterContext ctx,
Func<ChatFilterContext, CancellationToken, Task> next,
CancellationToken ct)
{
// before: log input / filter sensitive content
await next(ctx, ct);
// after: log output / write audit log
}
public Task OnStreamCompletedAsync(ChatFilterContext ctx, CancellationToken ct)
=> Task.CompletedTask;
}
Documentation
| Document | Description |
|---|---|
| Requirements Specification | Product goals, feature list, non-functional requirements |
| Architecture Design | Four-layer architecture, module design details |
| AI Orchestration Framework | Tools / Agents / Planner design |
| API Gateway Requirements | Gateway protocol adaptation details |
| MCP Architecture | MCP client and server design |
| Skill Management | Skill system detailed design |
| Self-Learning System | Conversation analysis + memory extraction |
| Chat Data Persistence Flow | MessageFlow detailed process |
| AOT Compatibility | NativeAOT support boundary, smoke matrix and platform/architecture coverage |
| Runtime Localization | 31 runtime languages, locale tables and contribution workflow |
| Feature Module List | Complete feature inventory |
Ecosystem Map
NewLife is a layered ecosystem of independently versioned open-source projects. The map below is shared verbatim by every NewLife repository; each project links to its repository and its primary NuGet package.
| Project | What it does | Downloads |
|---|---|---|
| Foundation | ||
| NewLife.Core | Logging, configuration, caching, networking, serialization, scheduling and APM tracing. | |
| NewLife.XCode | Data middleware: single tables at the tens-of-billions scale, automatic sharding, read-write splitting, 10+ databases. | |
| NewLife.Net | High-performance network library: 1.77M pps / 14.5 Gbps on a single machine (TCP 1KB, 2026-10), 4M long-lived TCP connections. | |
| NewLife.Remoting | Protocol communication and RPC framework for client/server applications and IoT devices. | |
| NewLife.Agent | Installs .NET applications as OS daemons: Windows services and Linux systemd. | |
| NewLife.Templates | dotnet new project templates for console, web, API, service, data and IoT projects. |
|
| Data & Messaging | ||
| NewLife.Redis | Redis client with microsecond latency, millions of ops/s and built-in message queues. | |
| NewLife.RocketMQ | Pure managed RocketMQ client for Apache RocketMQ and Alibaba Cloud Message Queue. | |
| NewLife.MQTT | MQTT client and server, including Alibaba Cloud IoT connectivity. | |
| NewLife.NovaDb | Hybrid database in C#: embedded or networked, relational, time-series, message queue and KV in one. | |
| NewLife.MySql | MySql driver and helper layer built on the NewLife data stack. | |
| Web, AI & Distributed | ||
| NewLife.Cube | Rapid admin-platform framework: permissions, SSO, OAuth server and CRUD scaffolding. | |
| Stardust | Distributed service platform: node management, APM, configuration center, registry and release center. | |
| AntJob | Distributed task and real-time data scheduling platform with sharding, retries and backfill. | |
| NewLife.AI | Unified client for 46 LLM providers plus ChatAI, a ready-to-run web chat application. | |
| Industrial & IoT | ||
| NewLife.IoT | IoT standard library defining protocol contracts and device abstractions. | |
| NewLife.Modbus | Modbus TCP/RTU/ASCII implementation on top of NewLife.IoT. | |
| NewLife.Siemens | Siemens PLC protocol on top of NewLife.IoT. | |
| NewLife.Omron | Omron PLC protocol on top of NewLife.IoT. | |
| NewLife.Melsec | Mitsubishi Melsec PLC protocol on top of NewLife.IoT. | |
| NewLife.OPC | OPC client for industrial data access. | — |
| NewLife.BACnet | BACnet building-automation protocol stack. | |
| ZeroIoT | Lightweight open-source IoT platform with gateway and device management. | — |
| Vehicle Telematics | ||
| NewLife.JT808 | JT/T 808 vehicle positioning protocol: 70+ message bodies, 2011/2013/2019. | |
| NewLife.JT809 | JT/T 809 platform-to-platform protocol for transport authorities. | |
| NewLife.JT1078 | JT/T 1078 in-vehicle video: RTP parsing, FLV/fMP4 remuxing and live streaming. | |
| Domain Components | ||
| NewLife.Office | One package for Excel, Word, PPT, PDF and 15+ document formats. | |
| NewLife.Audio | Cross-platform audio: codecs, device I/O, DSP, containers and streaming. | |
| NewLife.Video | Video codecs, container formats, frame processing and streaming. | |
| NewLife.Map | Unified interface over Baidu, AMap, Tencent and Tianditu with geocoding and coordinate conversion. | |
| NewLife.IP | IPv4 geolocation with an offline memory-mapped database and an online API fallback. | |
| Tools & Products | ||
| CrazyCoder | Developer toolbox: network, serial port, crypto, regex, Modbus and MQTT. | |
| GitCandy | Self-hosted Git source code management system. | — |
| LuckyClover | Installs the matching .NET runtime automatically when launched from an older host. | — |
Badges show the primary package of each project; theme, extension and satellite packages are listed on their NuGet pages. The 30+ packages not listed here (FTP, LoRa, Office extensions, protocol drivers and more) are available under the NewLifeX organization and on newlifex.com.
Team
<img src="/_dp/https://newlifex.com/logo.png" width="48" align="right" alt="NewLife" />
Founded in 2002, the NewLife team has spent more than two decades on the .NET and IoT ecosystem, maintains nearly 100 open-source projects (34 of them core to this map), and delivers integrated software and hardware solutions for power, logistics, healthcare, industrial control and internet industries. We live by the motto "learning has no seniority — mastery earns respect".
Open-source components have been downloaded 6.48M times from NuGet (ecosystem-wide, as of 2026-10).
Website: https://newlifex.com · Open source organization: https://github.com/NewLifeX
<details> <summary>WeChat Official Account: 智能大石头 (scan to follow)</summary>
</details>
License
Issues and Pull Requests are welcome.
- GitHub: https://github.com/NewLifeX/NewLife.AI
- Website: https://newlifex.com
- QQ Group: 1600800
Related Projects
- NewLife.Core — .NET Foundation Library
- XCode — ORM Data Framework
- NewLife.Cube — Rapid Development Platform
| 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 is compatible. 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- NewLife.Core (>= 12.0.2026.1024)
-
.NETStandard 2.0
- NewLife.Core (>= 12.0.2026.1024)
-
.NETStandard 2.1
- NewLife.Core (>= 12.0.2026.1024)
-
net10.0
- NewLife.Core (>= 12.0.2026.1024)
-
net8.0
- NewLife.Core (>= 12.0.2026.1024)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on NewLife.AI:
| Package | Downloads |
|---|---|
|
NewLife.Cube.Core
Cube MVC/Razor layer of the NewLife framework: ASP.NET Core MVC hosting, Razor view templates, user permission management, SSO sign-in, OAuth server, data export and runtime localization, validated with 10 billion rows in a single table. 魔方MVC/Razor兼容层:支持ASP.NET Core MVC传统开发模式,提供用户权限管理、Razor视图模板、SSO登录、OAuth服务端、数据导出与运行时多语言,单表100亿级数据验证。 |
|
|
NewLife.Cube
Cube Web API library of the NewLife framework: entity controllers, permission and menu management, field metadata, OAuth server, JWT authentication and runtime localization. Built for front-end/back-end separation with Vue, Blazor and Ant Design front ends, validated with 10 billion rows in a single table. 魔方WebAPI核心库:实体控制器、权限管理、菜单管理、字段元数据、OAuth服务端、JWT认证与运行时多语言;支持前后端分离架构,对接Vue/Blazor/Antd等前端框架,单表100亿级数据验证。 |
|
|
NewLife.ChatAI
集对话前端、统一 AI 网关、Agent 平台于一身的完整 AI 应用。支持多轮对话、流式输出、函数调用、图像生成、会话管理与使用量统计 |
|
|
NewLife.AI.Extensions
基于 NewLife.AI 基础库的扩展模块,提供中间件、依赖注入、缓存等企业级扩展能力 |
|
|
NewLife.StarChat
集对话前端、统一 AI 网关、Agent 平台于一身的完整 AI 应用。支持多轮对话、流式输出、函数调用、图像生成、会话管理与使用量统计 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.2026.1026-beta0221 | 98 | 10/26/2026 |
| 1.7.2026.1026-beta0051 | 118 | 10/26/2026 |
| 1.7.2026.1026-beta0042 | 161 | 10/26/2026 |
| 1.7.2026.1026-beta0001 | 94 | 10/26/2026 |
| 1.7.2026.1024 | 1,321 | 10/26/2026 |
| 1.6.2026.1021-beta1738 | 144 | 10/21/2026 |
| 1.6.2026.907-beta0517 | 901 | 9/7/2026 |
| 1.6.2026.904-beta0728 | 136 | 9/4/2026 |
| 1.6.2026.901 | 928 | 9/1/2026 |
| 1.6.2026.901-beta1629 | 122 | 9/1/2026 |
| 1.5.2026.821-beta0604 | 138 | 8/21/2026 |
| 1.5.2026.820-beta1456 | 600 | 8/20/2026 |
| 1.5.2026.818-beta0226 | 198 | 8/18/2026 |
| 1.5.2026.818-beta0056 | 147 | 8/18/2026 |
| 1.5.2026.801 | 617 | 8/1/2026 |
| 1.5.2026.801-beta1844 | 165 | 8/1/2026 |
| 1.4.2026.731-beta0845 | 145 | 7/31/2026 |
| 1.4.2026.717-beta0953 | 154 | 7/17/2026 |
| 1.4.2026.708 | 711 | 7/8/2026 |
| 1.4.2026.706-beta1322 | 151 | 7/6/2026 |
原生 AOT 就绪并随包保根,38 场景冒烟覆盖多系统多架构;31 种运行时语言与工具链路本地化;模型能力家族化与元数据解析链,修复 Anthropic/Bedrock/Azure/DeepSeek 协议一致性;消息落库与思考压缩重构;办公文档品牌设计系统;GitHub Packages 与 NuGet.org 双通道发版