XBag.AI.Prompts.Agents 0.1.0-preview.1

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

XBag.AI.Prompts.Agents

CI NuGet .NET 8 | 10 License: MIT

Microsoft Agent Framework glue for XBag.AI.Prompts: PromptInstructionsProvider, an AIContextProvider that renders a prompt template into the agent's instructions at the start of every run, with variables taken from that run (run options, session state, request messages).

Part of the XBag family of .NET packages by Murat Ay, the author of XBag, a .NET process-orchestration and decisioning platform. Community package, not affiliated with Microsoft.

Pipeline slot: agent layer, ChatClientAgentOptions.AIContextProviders, once per RUN.
               ChatClientAgent appends the rendered text to its own ChatOptions.Instructions ("\n" between them)
               and sends it on every model call of the run, tool-loop iterations included.

Install

dotnet add package XBag.AI.Prompts.Agents --prerelease

Example

Per-run instructions from the run options (this is AgentInstructionsTests.cs, run in CI on the real ChatClientAgent, buffered and streaming):

PromptTemplate template = PromptTemplate.Parse("""
    Kullanıcı: {{kullanıcı}}. Şehir: {{şehir}}.
    {{#if vip}}
    VIP müşteri, önce ona cevap ver.
    {{/if}}
    """);

AIAgent agent = model.AsAIAgent(new ChatClientAgentOptions
{
    ChatOptions = new() { Instructions = "Sen Anadolu Kargo'nun asistanısın." },
    AIContextProviders =
    [
        new PromptInstructionsProvider(template, run => new PromptArguments
        {
            ["kullanıcı"] = "Murat",
            ["şehir"] = run.RunOptions?.AdditionalProperties?["şehir"],
            ["vip"] = run.RunOptions?.AdditionalProperties?.ContainsKey("vip") == true,
        }),
    ],
});

await agent.RunAsync("Şube kaçta açılıyor?", options: new AgentRunOptions
{
    AdditionalProperties = new() { ["şehir"] = "İstanbul", ["vip"] = true },
});

Assert.Equal(
    "Sen Anadolu Kargo'nun asistanısın.\nKullanıcı: Murat. Şehir: İstanbul.\nVIP müşteri, önce ona cevap ver.",
    model.Requests[0].Instructions);

API

Type / member What it is
new PromptInstructionsProvider(template, arguments?) Fixed arguments for every run
new PromptInstructionsProvider(template, Func<AgentRunContext, PromptArguments?>) Per-run arguments: run.RunOptions, run.Session (its StateBag), run.RequestMessages, run.Agent
StateKeys Empty: nothing is stored in the session, so several providers can sit on one agent

Errors surface before the model is called: a missing variable throws PromptTemplateException, and a template with message blocks throws InvalidOperationException (instructions are text; render chat templates with RenderMessagesAsync and pass the messages to RunAsync).

What this is not

  • Not a message injector. It sets instructions only. Few-shot messages from a provider would be appended after the user's message by AIContextProvider's merge, so they are not offered.
  • No prompt catalog or DI registration yet: see the roadmap.

If Microsoft ships prompt templates

See XBag.AI.Prompts. The provider seam (AIContextProvider, stable in 1.24.0) would stay the same; only the template behind it would change.

Versions

Depends on Microsoft.Agents.AI.Abstractions 1.24.0 and XBag.AI.Prompts. Tested on .NET 8 and .NET 10. Status: 0.1.0-preview.1, the API may change before 1.0.

License

MIT

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

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.1.0-preview.1 85 10/11/2026