TimHanewich.AgentFramework 1.2.0

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

TimHanewich.AgentFramework

banner

A lightweight .NET (C#) library for building AI agents on top of the OpenAI Responses API via the TimHanewich.Foundry SDK. TimHanewich.AgentFramework provides a simple abstraction layer for assembling agents with tools, orchestrating multi-agent workflows, tracking token consumption, and more.

TimHanewich.AgentFramework is available on NuGet. To install in your .NET project, run the following command to download:

dotnet add package TimHanewich.AgentFramework

How to use TimHanewich.AgentFramework

It is very easy to build AI agents using a FoundryResource (from the TimHanewich.Foundry SDK). For example:

using TimHanewich.AgentFramework;
using TimHanewich.Foundry;

FoundryResource fr = new FoundryResource("<endpoint>");
fr.ApiKey = "<key>";

Agent myAgent = new Agent("You are a helpful assistant.");
myAgent.FoundryResource = fr;
myAgent.Model = "gpt-5.4-mini";
string response = await myAgent.PromptAsync("Why is the sky blue?");
Console.WriteLine(response); // The sky appears blue primarily due to a phenomenon known as Rayleigh scattering...

Multi-Turn Conversation

The short snippet below demonstrates how a multi-turn conversation can be accomplished. The agent automatically maintains conversation history via the Responses API's PreviousResponseID:

using TimHanewich.AgentFramework;
using TimHanewich.Foundry;

FoundryResource fr = new FoundryResource("<endpoint>");
fr.ApiKey = "<key>";

Agent myAgent = new Agent("You are a helpful assistant.");
myAgent.FoundryResource = fr;
myAgent.Model = "gpt-5.4-mini";
while (true)
{
    //Collect input
    Console.Write("> ");
    string? input = null;
    while (input == null){input = Console.ReadLine();}

    //Prompt
    string response = await myAgent.PromptAsync(input);
    Console.WriteLine("\n" + response);
}

Tool Calling

This library supports tool calling through executable functions — tools that automatically execute when called by the model. You define a tool by extending the ExecutableFunction abstract class:

using TimHanewich.AgentFramework;
using TimHanewich.Foundry;

FoundryResource fr = new FoundryResource("<endpoint>");
fr.ApiKey = "<key>";

Agent myAgent = new Agent("You are a helpful assistant.");
myAgent.FoundryResource = fr;
myAgent.Model = "gpt-5.4-mini";

//Add a custom tool
myAgent.Tools.Add(new WeatherLookup());

//Prompt - the agent will automatically call the tool and return a final response
string response = await myAgent.PromptAsync("What's the weather in New York?");
Console.WriteLine(response);

The ExecutableFunction class is abstract — you create your own tools by inheriting from it and implementing ExecuteAsync:

public class WeatherLookup : ExecutableFunction
{
    public WeatherLookup()
    {
        Name = "get_weather";
        Description = "Get the current weather for a location.";
    }

    public override async Task<string> ExecuteAsync(JObject? arguments)
    {
        string location = arguments["location"].ToString();
        HttpClient hc = new HttpClient();
        HttpResponseMessage resp = await hc.GetAsync("https://wttr.in/" + location + "?format=j1");
        return await resp.Content.ReadAsStringAsync();
    }
}

Tool calls are executed automatically in a loop — the agent will keep calling tools and feeding results back to the model until the model produces a final text response. You can subscribe to events to monitor tool calls as they happen:

//Called when the agent invokes a tool
myAgent.ExecutableFunctionInvoked += (ExecutableFunction ef, JObject arguments) =>
{
    Console.WriteLine(ef.Name + " invoked with: " + arguments.ToString(Formatting.None));
};

//Called when a tool finishes executing and returns
myAgent.ExecutableFunctionReturned += (ExecutableFunction ef, JObject arguments) =>
{
    Console.WriteLine(ef.Name + " returned.");
};

Inference Lifecycle Events

You can monitor each call to the OpenAI Responses API using the InferenceRequested and InferenceReceived events. This is useful for logging, progress indicators, or tracking per-call token usage:

myAgent.InferenceRequested += () =>
{
    Console.WriteLine("Calling OpenAI API...");
};

myAgent.InferenceReceived += (int inputTokens, int outputTokens) =>
{
    Console.WriteLine("Response received! Tokens used: " + inputTokens + " in, " + outputTokens + " out.");
};

Multi-Agent (Agent as Tool)

You can use one agent as a tool for another agent with AgentAsTool. This enables multi-agent orchestration where a parent agent delegates tasks to sub-agents:

using TimHanewich.AgentFramework;
using TimHanewich.Foundry;

FoundryResource fr = new FoundryResource("<endpoint>");
fr.ApiKey = "<key>";

//Set up a sub-agent
Agent AIDA = new Agent("You are AIDA, a smart AI.");
AIDA.FoundryResource = fr;
AIDA.Model = "gpt-5.4-mini";

//Set up a concierge agent that delegates to AIDA
Agent concierge = new Agent("You are a concierge. Delegate tasks to AIDA.");
concierge.FoundryResource = fr;
concierge.Model = "gpt-5.4-mini";
concierge.Tools.Add(new AgentAsTool(AIDA, "AIDA", "General purpose AI agent."));

string response = await concierge.PromptAsync("Write me a haiku about the ocean.");
Console.WriteLine(response);

Token Tracking

Each agent tracks its own token consumption. You can also get recursive token counts that include all sub-agents:

Console.WriteLine("Input tokens: " + myAgent.InputTokensConsumed);
Console.WriteLine("Output tokens: " + myAgent.OutputTokensConsumed);

//Recursive (includes sub-agent tokens)
Console.WriteLine("Total input tokens: " + myAgent.InputTokensConsumedRecursive);
Console.WriteLine("Total output tokens: " + myAgent.OutputTokensConsumedRecursive);

Additional Settings

The Agent class exposes several optional settings:

myAgent.ReasoningEffortLevel = ReasoningEffortLevel.High;  //Control reasoning effort
myAgent.VerbosityLevel = Verbosity.Detailed;               //Control response verbosity
myAgent.WebSearchEnabled = true;                           //Enable built-in web search tool
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.

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.2.0 107 4/28/2026
1.1.0 102 4/23/2026
1.0.0 108 4/21/2026
0.3.0 259 4/24/2025
0.2.1 239 4/24/2025
0.2.0 297 3/7/2025
0.1.1 294 3/5/2025
0.1.0 288 3/4/2025