LogicBuilder.App.AI.Utils 1.0.1

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

LogicBuilder.App.AI.Utils

CI CodeQL codecov Quality gate status NuGet

LogicBuilder.App.AI.Utils is a .NET library for declaratively building, running, and consuming Microsoft Agent Foundry AI agents, rather than hand-coding the Azure AI Projects / Microsoft.Agents.AI SDK calls directly.

It is intended for applications that need to:

  • Define AI agents (name, model, instructions, and tools such as MCP servers or web search) declaratively — e.g. from configuration, a database, or a UI — and materialize those definitions into runnable AIAgent instances.
  • Create those agents from application configuration (e.g. an AZURE_AI_FOUNDRY_PROJECT_ENDPOINT setting) without directly wiring up Azure credentials or the AIProjectClient.
  • Drive conversations with an AIAgent (session/thread initialization, single-shot responses, and streaming responses) using a simple, serializable session/thread identifier that callers can persist between requests.
  • Present citation/source references returned by an agent as inline Markdown links within the response text, rather than raw annotation metadata.

Key Concepts

The library is organized around a few cooperating areas:

1. Declarative agent definition (Parameters → Builders)

Two parallel object hierarchies connected by an AutoMapper profile:

  • Parameters (LogicBuilder.App.AI.Utils.Parameters) — plain data objects describing what an agent should look like:

    • IAgentParameters / AgentParameters — agent name, model, instructions, and a collection of tool parameters.
    • IAgentToolParameters — base interface for tool definitions, implemented by:
      • McpToolParameters — describes an MCP (Model Context Protocol) tool/server.
      • WebSearchToolParameters — describes a web search tool.
  • Builders (LogicBuilder.App.AI.Utils.Builders) — objects that know how to construct the corresponding Azure AI Foundry / Agents SDK artifacts:

    • IAgentBuilder / AgentBuilder — wraps an AIProjectClient plus agent metadata and tool builders, and exposes Build() to produce a live AIAgent.
    • IAgentToolBuilder implementations (e.g. McpToolBuilder, WebSearchToolBuilder) — each know how to build the corresponding tool definition consumed by the agent.
  • Mapping (LogicBuilder.App.AI.Utils.Mapping) — ParametersToBuilderMappingProfile is an AutoMapper Profile that maps the parameter hierarchy onto the builder hierarchy (including polymorphic mapping of tool parameter types to their matching tool builder types). An AIProjectClient is supplied via the AutoMapper ResolutionContext.Items (see MappingConstants.AI_PROJECT_CLIENT_CONTEXT) so it can be injected into the constructed AgentBuilder.

2. Configuration-driven agent creation

  • IAgentCreator / AgentCreator — reads the Foundry project endpoint from IConfiguration (AZURE_AI_FOUNDRY_PROJECT_ENDPOINT), constructs an AIProjectClient using DefaultAzureCredential, and uses AutoMapper to turn an AgentParameters instance directly into a ready-to-use AIAgent via AgentBuilder.Build(). This removes the need for calling code to manage Azure credentials or AIProjectClient construction itself.

3. Conversation/session handling

  • IAgentHandler / AgentHandler — a thin, serialization-friendly wrapper around AIAgent conversation APIs:
    • InitializeSession(AIAgent) — creates a new ChatClientAgentSession for the agent and returns it serialized as a JSON string, suitable for persisting as a "thread ID" between requests.
    • SendMessageToAgent(...) — deserializes a previously-saved thread ID, sends a user message to the agent, and returns an AgentStreamResult containing the (citation-formatted) response text along with the updated, re-serialized thread ID.
    • SendMessageToAgentWithStreamingResponse(...) — same as above, but streams response chunks as they arrive (via IAsyncEnumerable<AgentStreamResult>), yielding a final chunk with the updated serialized thread state once streaming completes.
    • AgentStreamResult (LogicBuilder.App.AI.Utils.Structures) — a simple result type distinguishing streamed content chunks (FromChunk) from the final updated thread state (FromState).

4. Inline citation formatting

  • IInlineCitationFormatter / InlineCitationFormatter — takes agent response text plus its CitationAnnotation metadata (character-span based source references) and rewrites the text so each citation span is replaced with an inline Markdown link (e.g. [contoso-tents-catalog.pdf](https://.../contoso-tents-catalog.pdf)), using the citation's title/URL to derive a friendly link label. This lets UIs render citations as normal Markdown without needing to understand the underlying annotation model.

Typical Usage

Defining and building an agent directly via AutoMapper

  1. Construct an AIProjectClient (via Azure Identity credentials) for your Foundry project.
  2. Build up an IAgentParameters object graph describing the agent (name, model, instructions, and tools).
  3. Use AutoMapper (configured with ParametersToBuilderMappingProfile) to map the parameters into an IAgentBuilder/AgentBuilder, passing the AIProjectClient through the mapping context.
  4. Call Build() on the resulting AgentBuilder to obtain a ready-to-use AIAgent.
IAgentParameters agentParameters = new AgentParameters
( 
    "AgentName", 
    "gpt-5.2", 
    "You are a helpful AI assistant...", 
    [ 
        new McpToolParameters("GreetingTool", "https://example.com/mcp", true), 
        new WebSearchToolParameters() 
    ] 
); 

AgentBuilder agentBuilder = mapper.Map<AgentBuilder> 
( 
    agentParameters, 
    opts => opts.Items[MappingConstants.AI_PROJECT_CLIENT_CONTEXT] = projectClient 
); 

AIAgent agent = agentBuilder.Build();

Creating an agent from configuration with AgentCreator

// AZURE_AI_FOUNDRY_PROJECT_ENDPOINT must be present in IConfiguration.

IAgentCreator agentCreator = new AgentCreator(configuration, mapper);
AgentParameters agentParameters = new 
( 
    "AgentName", 
    "gpt-5.2", 
    "You are a helpful AI assistant...", 
    [ new WebSearchToolParameters() ] 
);
AIAgent agent = agentCreator.CreateAgent(agentParameters);

Running a conversation with AgentHandler

IAgentHandler agentHandler = new AgentHandler(new InlineCitationFormatter());
// Start a new conversation and persist the returned thread ID (e.g. in a cookie, DB row, etc.). 
string threadId = await agentHandler.InitializeSession(agent);

// Send a message using the persisted thread ID; receive citation-formatted text plus the updated thread ID. 
AgentStreamResult result = await agentHandler.SendMessageToAgent(agent, threadId, "What tents do you offer?"); 
string responseText = result.ContentChunk; threadId = result.UpdatedThreadId;
// Or stream the response as it is generated. 
await foreach (AgentStreamResult chunk in agentHandler.SendMessageToAgentWithStreamingResponse(agent, threadId, "Tell me more.")) 
{ 
    if (chunk.ContentChunk is not null) 
    { // Append chunk.ContentChunk to the UI as it streams in. 
    } 
    else if (chunk.UpdatedThreadId is not null) 
    { threadId = chunk.UpdatedThreadId; 
    } 
}

Solution Layout

Project Purpose
LogicBuilder.App.AI.Utils Core library (parameters, builders, AutoMapper profile, agent creation, conversation handling, and inline citation formatting) — targets .NET Standard 2.0.
LogicBuilder.App.AI.Utils.Tests xUnit/Moq test suite validating parameter → builder mapping, configuration-driven agent creation, conversation/session handling, and inline citation formatting — targets .NET 10.

Dependencies

  • AutoMapper — maps parameter objects to builder objects.
  • Microsoft.Agents.AI.Foundry — provides the AIProjectClient/AIAgent types used to construct and run agents in Microsoft Agent Foundry.
  • Azure.Identity — supplies DefaultAzureCredential used by AgentCreator to authenticate the AIProjectClient.
  • Microsoft.Extensions.Configuration — used by AgentCreator to read the Foundry project endpoint from application configuration.
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 was computed.  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 was computed.  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

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
1.0.1 84 9/23/2026

First release.