Supprocom.LlamaSharp.ToolCallEnvelopes 0.2.0

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

LlamaSharp.ToolCallEnvelopes

LlamaSharp.ToolCallEnvelopes gives a local LlamaSharp model one small JSON language for final answers, tool requests, and optional refusals. A compiled plan keeps the prompt, GBNF grammar, parser, and argument validator together, so the model cannot be prompted for one shape and parsed as another.

The package targets .NET 10 and leaves model loading, sampling, native context ownership, and chat-template selection in your LlamaSharp adapter.

Install

dotnet add package Supprocom.LlamaSharp.ToolCallEnvelopes --version 0.2.0

Managed control flow

Managed control flow is the short path for an application that wants a useful tool loop today. The runner creates turns, retries invalid model output, validates every call before dispatch, executes calls sequentially, appends tool results, and stops on a final answer or refusal.

var weather = ToolDefinition.Parse(
    "get_weather",
    "Gets the current weather for one city.",
    """
    {
      "type": "object",
      "properties": {
        "city": { "type": "string", "minLength": 1, "maxLength": 64 },
        "unit": { "type": "string", "enum": ["celsius", "fahrenheit"] }
      },
      "required": ["city", "unit"],
      "additionalProperties": false
    }
    """);

var plan = ToolEnvelopePlan.Compile([weather]);

var result = await ToolEnvelopeRunner.RunAsync(
    executor,
    plan,
    "Use current weather data when the user asks about weather.",
    [ToolMessage.User("What is the weather in Zagreb?")],
    async (call, cancellationToken) =>
    {
        var city = call.Arguments.GetProperty("city").GetString();
        return await GetWeatherJsonAsync(city!, cancellationToken);
    },
    cancellationToken: cancellationToken);

if (result is ToolRunResult.Completed
    {
        Outcome: ToolEnvelopeOutcome.AssistantMessage answer
    })
{
    Console.WriteLine(answer.Text);
}

The executor implements ILlamaSharpToolExecutor. It applies the model's native chat template to turn.Prompt, attaches turn.Grammar with the root start rule, and yields only newly generated text. The complete working LlamaSharp adapter is in the demo.

Manual control flow

Manual control flow exposes the same compiled turn without choosing retries, dispatch policy, history storage, context reuse, or when the next turn should start. This is the open route for applications with their own orchestration.

var conversation = new List<ToolMessage>
{
    ToolMessage.User("What is the weather in Zagreb?"),
};

var turn = plan.CreateTurn(
    "Use current weather data.",
    conversation,
    ToolChoice.Auto);

var reader = turn.CreateStreamReader();
await foreach (var fragment in executor.InferAsync(turn, cancellationToken))
    reader.Feed(fragment);

var outcome = reader.Complete();

Read getting started for the managed path, manual control for host-owned orchestration, and the schema profile for the exact accepted JSON Schema subset.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 95 7/13/2026
0.1.7 98 7/12/2026
0.1.6 91 7/12/2026
0.1.5 102 7/12/2026
0.1.3 98 7/8/2026

Compiled prompt, grammar, parser, and schema validation with managed and manual control flow for local LlamaSharp models.