ZeroPrompt.Core
1.3.0
dotnet add package ZeroPrompt.Core --version 1.3.0
NuGet\Install-Package ZeroPrompt.Core -Version 1.3.0
<PackageReference Include="ZeroPrompt.Core" Version="1.3.0" />
<PackageVersion Include="ZeroPrompt.Core" Version="1.3.0" />
<PackageReference Include="ZeroPrompt.Core" />
paket add ZeroPrompt.Core --version 1.3.0
#r "nuget: ZeroPrompt.Core, 1.3.0"
#:package ZeroPrompt.Core@1.3.0
#addin nuget:?package=ZeroPrompt.Core&version=1.3.0
#tool nuget:?package=ZeroPrompt.Core&version=1.3.0
๐ฏ ZeroPrompt: Sovereign Pure C# Prompt Templating & Grammar-Constrained Engine
ZeroPrompt is an industrial-grade, zero-allocation prompt templating, Pushdown Automaton (PDA) JSON Schema 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.
- Schema-Constrained JSON Pushdown Automaton (
SchemaConstrainedJsonGrammar):- 64-bit Bitmask Property Validation: Maps property indices to 64-bit unsigned integers (
ulong), enforcing property whitelists, required property completeness, and strict data type constraints with single-cycle bitwise operations. - Zero Heap Allocations: Replaces heap-allocated bracket stacks with a fixed inline buffer (
char[16]), reducing token candidate testing latency to under $0.5,\mu\text{s}$.
- 64-bit Bitmask Property Validation: Maps property indices to 64-bit unsigned integers (
- Strict Tool Calling Finite Automaton (
ToolCallGrammarState):- Governs the
<tool_call>{"tool": "<name>", "parameters": { ... }}</tool_call>syntax. - Zero Tool Name Hallucination: Only allows the generation of tool names explicitly registered in the agent's tool catalog. Automatically switches parameter schemas upon tool name resolution.
- Governs the
- Context-Aware Grammar Logit Processor (
ToolCallGrammarLogitProcessor):- Integrates directly with
ZeroLlmviaContextAwareLogitProcessor. Dynamically sets invalid syntax/schema token logits to $-\infty$ (-1e9f), mathematically guaranteeing 100% syntactically valid JSON tool calls.
- Integrates directly with
- Dynamic Few-Shot Exemplar Selector (
FewShotSelector):- Backed by
ZeroVector.Corehardware-accelerated SIMD vector similarity (VectorMetrics.CosineSimilarity). - Dynamically selects the top-$K$ most semantically relevant few-shot 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), cutting TTFT by up to 70%.
- Partitions prompt components strictly into cacheable static prefixes (
- 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. Schema-Constrained JSON Grammar
using ZeroPrompt.Core.Grammar;
var schema = new JsonSchemaConstraint("so_query")
.AddProperty("order_id", SchemaPropertyType.String, required: true)
.AddProperty("limit", SchemaPropertyType.Number, required: false);
var grammar = new SchemaConstrainedJsonGrammar(schema);
// Validate character transitions with zero heap allocation
bool valid = grammar.CanAcceptNext("{\"order_id\": \"SO-2026-001\"}".AsSpan());
Console.WriteLine($"Valid: {valid}");
3. Tool Call Grammar Logit Masking
using ZeroPrompt.Core.Grammar;
var schemas = new Dictionary<string, JsonSchemaConstraint>
{
["mds_db_so_query"] = new JsonSchemaConstraint("mds_db_so_query")
.AddProperty("order_id", SchemaPropertyType.String, required: true)
};
var processor = new ToolCallGrammarLogitProcessor(tokenizer, schemas);
// Applied directly during LLM autoregressive token sampling
processor.Process(logitsSpan, pastTokensSpan);
๐ก๏ธ Architecture & Tier Compliance
flowchart TD
PromptTemplate["ZeroPrompt.Core.Templates\n(PromptTemplate, PromptContext)"]
JsonGrammar["ZeroPrompt.Core.Grammar\n(SchemaConstrainedJsonGrammar, ToolCallGrammarState)"]
LogitMasker["ZeroPrompt.Core.Grammar\n(ToolCallGrammarLogitProcessor)"]
FewShot["ZeroPrompt.Core.FewShot\n(FewShotSelector, Exemplar)"]
FewShot --> VectorMetrics["ZeroVector.Core.Metrics\n(SIMD CosineSimilarity)"]
LogitMasker --> ZeroLlm["ZeroLlm.Core.Sampling\n(ContextAwareLogitProcessor)"]
JsonGrammar --> ZeroAgent["ZeroAgent.Core\n(AgentToolRegistry)"]
๐ License
Architected and developed by Phong Vรต (kzxl) for the ZeroUniverse / ZeroPlatform ecosystem. Released under the MIT License.
| 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.1.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.1.0)
-
net8.0
- ZeroConcurrency (>= 1.4.0)
- ZeroPrimitives.Core (>= 1.7.0)
- ZeroTokenizer.Core (>= 1.0.0)
- ZeroVector.Core (>= 1.1.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.Tools
Industrial and Operational Toolset for ZeroAgent (PLC Modbus, Gorilla TSDB Query, Host Telemetry, Columnar DataFrame, and HITL Safety Gates) in 100% pure C#. |
|
|
ZeroAgent.Dialog
Deterministic Semantic Task-Oriented Dialogue System and Multi-Tier Agentic Memory Engine (Non-LLM) for ZeroAgent. |
GitHub repositories
This package is not used by any popular GitHub repositories.