ZeroPrompt.Core
1.1.0
dotnet add package ZeroPrompt.Core --version 1.1.0
NuGet\Install-Package ZeroPrompt.Core -Version 1.1.0
<PackageReference Include="ZeroPrompt.Core" Version="1.1.0" />
<PackageVersion Include="ZeroPrompt.Core" Version="1.1.0" />
<PackageReference Include="ZeroPrompt.Core" />
paket add ZeroPrompt.Core --version 1.1.0
#r "nuget: ZeroPrompt.Core, 1.1.0"
#:package ZeroPrompt.Core@1.1.0
#addin nuget:?package=ZeroPrompt.Core&version=1.1.0
#tool nuget:?package=ZeroPrompt.Core&version=1.1.0
🎯 ZeroPrompt: Sovereign Pure C# Prompt Templating & Grammar-Constrained Engine
ZeroPrompt is an industrial-grade, zero-allocation prompt templating, Pushdown Automaton (PDA) JSON Grammar state machine, Grammar-Constrained Logit Masker, and dynamic few-shot exemplar selector written in 100% pure C#. It operates at Tier 5 (Presentation & Orchestration) of the ZeroPlatform ecosystem.
⚡ Key Capabilities
- Zero-Allocation Prompt Templating (
PromptTemplate):- Blazing-fast variable interpolation syntax
{{variable_name}}without heavyweight regex or runtime reflection. - Span-based rendering directly into
StringBuilderbuffers. - Parameter validation and missing variable tracking.
- Blazing-fast variable interpolation syntax
- Pushdown Automaton (PDA) JSON Grammar Engine (
JsonGrammarState):- Microsecond deterministic stack-based validation of LLM generation streams.
- Tracks nested objects (
{), arrays ([), string literals, escape sequences, colons, and commas. - Evaluates allowable next character classes (e.g.
AllowOpenBrace,AllowPropertyName,AllowColon,AllowValue,AllowComma).
- Grammar-Constrained Logit Masking (
GrammarLogitMasker):- Dynamically masks out non-conforming tokens during autoregressive decoding (
-Infinityfor invalid tokens). - Guarantees 100% syntactically valid JSON outputs from local LLMs (
ZeroLlm) or remote endpoints, eliminating JSON parse hallucinations in tool-calling workflows.
- Dynamically masks out non-conforming tokens during autoregressive decoding (
- Dynamic Few-Shot Exemplar Selector (
FewShotSelector):- Backed by
ZeroVector.Corehardware-accelerated SIMD vector similarity (VectorMetrics.CosineSimilarity). - Dynamically picks top-$K$ most semantically relevant few-shot input/output demonstrations for prompts.
- Backed by
- Transformer KV-Cache Layout Optimizer (
PromptLayoutOptimizer):- Partitions prompt components strictly into cacheable static prefixes (
StaticSystem,ToolDefinitions,FewShot,ContextRAG) and dynamic request-specific payloads (History,DynamicSuffix). - Guarantees left-to-right prefix stability for local inference engines (
ZeroInference/ vLLM / llama.cpp), cutting TTFT by up to 70%.
- Partitions prompt components strictly into cacheable static prefixes (
- Prefix Radix Cache (
PrefixRadixCache):- Sub-microsecond thread-safe prefix tree for caching tokenized prompt prefixes with 64-bit FNV-1a hashing.
- Zero External Dependencies & Multi-Targeting:
- Compatible with
.NET 8.0+,.NET Framework 4.6.2+, and.NET Standard 2.0.
- Compatible with
🚀 Quick Start
1. Template Rendering
using ZeroPrompt.Core.Templates;
var template = new PromptTemplate("You are a SCADA diagnostic engineer for line {{line_id}}. Analyze status: {{status}}.");
var context = new PromptContext()
.Set("line_id", "LINE-04")
.Set("status", "OVERHEAT_ALARM");
string prompt = template.Render(context);
Console.WriteLine(prompt);
2. JSON Grammar State Machine
using ZeroPrompt.Core.Grammar;
var grammar = new JsonGrammarState();
// Feed tokens as they are sampled from LLM
grammar.Feed("{\"tool\": \"read_register\", \"args\": {\"address\": 40001}}");
if (grammar.IsCompleted)
{
Console.WriteLine("Valid JSON payload generated!");
}
3. Grammar-Constrained Logit Masking
using ZeroPrompt.Core.Grammar;
var masker = new GrammarLogitMasker();
var grammar = new JsonGrammarState();
grammar.Feed("{\"status\": ");
float[] logits = new float[vocabSize];
string[] vocab = GetVocabularyTokens();
// Masks out tokens that violate JSON syntax rules
masker.ApplyMask(grammar, logits, vocab);
4. Semantic Few-Shot Exemplar Selection
using ZeroPrompt.Core.FewShot;
var selector = new FewShotSelector();
selector.Add(new Exemplar("Read PLC register 100", "{\"tool\":\"read_plc\",\"reg\":100}", embedding1));
selector.Add(new Exemplar("Query temperature sensor", "{\"tool\":\"get_temp\",\"id\":1}", embedding2));
string demonstrationPrompt = selector.BuildDemonstrationPrompt(queryEmbedding, k: 1);
5. Transformer KV-Cache Prompt Layout Optimization
using ZeroPrompt.Core.Caching;
var optimizer = new PromptLayoutOptimizer()
.AddSystem("You are an autonomous SCADA diagnostic assistant.")
.AddTools("Tool: read_sensor(name)\nTool: trip_breaker(breaker_id)")
.AddHistory("User: Check voltage\nAssistant: Voltage is 220V")
.AddUserQuery("What is the current on Line 02?");
OptimizedPromptLayout layout = optimizer.Optimize();
// Cacheable immutable prefix (System + Tools)
Console.WriteLine($"Prefix Hash: {layout.PrefixHash:X16}");
Console.WriteLine($"Full Prompt:\n{layout.FullPrompt}");
🛡️ Architecture & Tier Compliance
flowchart TD
PromptTemplate["ZeroPrompt.Core.Templates\n(PromptTemplate, PromptContext)"]
JsonGrammar["ZeroPrompt.Core.Grammar\n(JsonGrammarState, GrammarLogitMasker)"]
FewShot["ZeroPrompt.Core.FewShot\n(FewShotSelector, Exemplar)"]
FewShot --> VectorMetrics["ZeroVector.Core.Metrics\n(SIMD CosineSimilarity)"]
JsonGrammar --> ZeroLlm["ZeroLlm.Core\n(Constrained Sampler)"]
PromptTemplate --> ZeroAgent["ZeroAgent.Core\n(ReAct Orchestrator)"]
📄 License
MIT License. Engineered with pride for sovereign autonomous computing.
| 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 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 | 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 was computed. |
| .NET Framework | net461 was computed. net462 is compatible. 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.6.2
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
- System.Text.Json (>= 8.0.5)
- ZeroConcurrency (>= 1.4.0)
- ZeroPrimitives.Core (>= 1.7.0)
- ZeroTokenizer.Core (>= 1.0.0)
- ZeroVector.Core (>= 1.0.0)
-
.NETStandard 2.0
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
- System.Text.Json (>= 8.0.5)
- ZeroConcurrency (>= 1.4.0)
- ZeroPrimitives.Core (>= 1.7.0)
- ZeroTokenizer.Core (>= 1.0.0)
- ZeroVector.Core (>= 1.0.0)
-
net8.0
- ZeroConcurrency (>= 1.4.0)
- ZeroPrimitives.Core (>= 1.7.0)
- ZeroTokenizer.Core (>= 1.0.0)
- ZeroVector.Core (>= 1.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ZeroPrompt.Core:
| Package | Downloads |
|---|---|
|
ZeroAgent.Core
Pure C# enterprise-grade cognitive AI Agent runtime (ReAct loop, tool registry, episodic memory via ZeroVector, and multi-agent swarm) for .NET. |
|
|
ZeroAgent.Dialog
Deterministic Semantic Task-Oriented Dialogue System and Multi-Tier Agentic Memory Engine (Non-LLM) for ZeroAgent. |
|
|
ZeroAgent.Tools
Industrial and Operational Toolset for ZeroAgent (PLC Modbus, Gorilla TSDB Query, Host Telemetry, Columnar DataFrame, and HITL Safety Gates) in 100% pure C#. |
GitHub repositories
This package is not used by any popular GitHub repositories.