ZeroPrompt.Core 1.1.0

dotnet add package ZeroPrompt.Core --version 1.1.0
                    
NuGet\Install-Package ZeroPrompt.Core -Version 1.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="ZeroPrompt.Core" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroPrompt.Core" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroPrompt.Core" />
                    
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 ZeroPrompt.Core --version 1.1.0
                    
#r "nuget: ZeroPrompt.Core, 1.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 ZeroPrompt.Core@1.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=ZeroPrompt.Core&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroPrompt.Core&version=1.1.0
                    
Install as a Cake Tool

🎯 ZeroPrompt: Sovereign Pure C# Prompt Templating & Grammar-Constrained Engine

License: MIT .NET Multi-Targeting Zero External Dependencies

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 StringBuilder buffers.
    • Parameter validation and missing variable tracking.
  • 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 (-Infinity for invalid tokens).
    • Guarantees 100% syntactically valid JSON outputs from local LLMs (ZeroLlm) or remote endpoints, eliminating JSON parse hallucinations in tool-calling workflows.
  • Dynamic Few-Shot Exemplar Selector (FewShotSelector):
    • Backed by ZeroVector.Core hardware-accelerated SIMD vector similarity (VectorMetrics.CosineSimilarity).
    • Dynamically picks top-$K$ most semantically relevant few-shot input/output demonstrations for prompts.
  • 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%.
  • 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.

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

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.

Version Downloads Last Updated
1.1.0 0 10/1/2026
1.0.0 0 10/1/2026