AgentKit is a family of .NET libraries that give an AI agent hardened, provider-neutral tools that are safe by construction: an unsafe operation is not refused at call time, it cannot be expressed. The application decides which tools an agent receives and the controls they carry, and AgentKit makes each tool behave predictably within them. It also gives the agent a session of its own that compacts its context, so a long-running agent behaves the same way on every provider.
- π‘οΈ Safe by Construction: Operations the policy forbids cannot be expressed, not merely refused at call time
- ποΈ Application-Set Controls: Path grants, tool limits, and host capabilities bound every tool
- π§° Ready-Made Tool Families: Text file, file, Markdown, image, todo, memory, and agent delegation
- π§© Custom Tools: Build your own tools through the same guarded factory and publish them as packs
- π Provider-Neutral: Plain
AIFunctiontools for Microsoft Agent Framework, Copilot, and anyIChatClient - π§ Self-Compacting Sessions: Tiered context compaction keeps a long conversation alive on any provider
- ποΈ Large Output Retention: Opt-in, any provider; held in memory for
tool_output_readandtool_output_search - π Honest Context Windows: Sessions account against the window a provider really runs, Ollama included
- πΌοΈ Images That Arrive: Tool-returned images reach the model even on providers that would drop them
- π§ͺ Testable Offline: An in-memory provider session exercises the whole session lifecycle without a model
- π Agent-Readable API Reference: Every package ships a gradually-disclosed Markdown API reference
- π₯οΈ Multi-Platform Support: Builds and runs on Windows, Linux, and macOS, targeting .NET 8, 9, and 10
- π Continuous Compliance: CI generates evidence using Continuous Compliance
Install the core libraries and the adapter for your provider using the .NET CLI:
dotnet add package DemaConsulting.AgentKit.Core
dotnet add package DemaConsulting.AgentKit.Tools
dotnet add package DemaConsulting.AgentKit.Agents.ChatClient # any IChatClient providerFor the GitHub Copilot runtime, add DemaConsulting.AgentKit.Agents.Copilot instead of the IChatClient adapter, and
reference Microsoft.Copilot.SDK 2.0.1 directly from the host application: the SDK provisions its runtime only into a
project that references it directly, and AgentKit starts and owns that runtime itself. On Ollama, also add
DemaConsulting.AgentKit.Agents.Ollama so a session is told the context window the instance is actually running.
Decide what the agent may touch, decide which tools it receives, and hand both to a provider. The example runs on a
local Ollama model through OllamaSharp (dotnet add package OllamaSharp); any other IChatClient drops in on the
same line:
using DemaConsulting.AgentKit.Agents.ChatClient;
using DemaConsulting.AgentKit.Core;
using DemaConsulting.AgentKit.Tools.File;
using DemaConsulting.AgentKit.Tools.TextFile;
using Microsoft.Extensions.AI;
using OllamaSharp;
// What the agent may touch: relative paths anchor to /workspace, which is granted read-write.
var policy = new PathPolicy("/workspace", [PathRule.ReadWrite("/workspace")]);
// Which tools it receives: two of the shipped families, composed onto that policy.
IList<AIFunction> tools =
[
.. new ToolPackBuilder(policy)
.Add(new TextFilePack())
.Add(new FilePack())
.Build()
];
// Any IChatClient works (OpenAI, Azure OpenAI, ...); this one is a local Ollama model.
IChatClient chatClient = new OllamaApiClient(new Uri("http://localhost:11434"), "qwen3.5:9b");
// A Microsoft Agent Framework agent over that client.
var agent = ChatClientAgentFactory.Create(
chatClient,
tools,
instructions: "You are a document assistant. Use the tools provided.");
var response = await agent.RunAsync("List the files in the workspace and summarize the largest one.");
Console.WriteLine(response.Text);Every tool in that list observes the same policy: a request that names a path outside /workspace is refused
with a reason the model can act on. The policy is a path guardrail, not an OS sandbox: a link inside a grant is not a
boundary, so read Path Policy in the User Guide for the link and race caveats. To keep a long
conversation alive past the model's context window, run the agent on a CompactingAgentSession, as the User Guide
describes.
Your application chooses the tools and sets their controls; AgentKit.Core enforces those controls
for every tool and runs the self-compacting session that each provider adapter plugs into.
pwsh ./build.ps1The AgentKit User Guide, covering the safety model, every tool family, building an agent on each provider, and sessions with context compaction, is available on the AgentKit releases page.
Three runnable samples show AgentKit end to end:
- π Document Assistant: Consuming the shipped tools under a two-location policy
- π¬ Research Assistant: Planning, memory, and delegation on a self-compacting session
- π οΈ Custom Tools: Writing your own guarded tools and publishing them as packs
Each release publishes build notes, the User Guide, requirements, a trace matrix, the software and verification design
documents, the code review plan and report, and a code quality report. Each NuGet package also ships its API reference
in its api/ folder: an index, then a page per namespace, type, and member, with every example compiled against the
real API by the build.
Contributions are welcome. See CONTRIBUTING.md for development setup, coding standards, and the pull request process, and review the Code of Conduct.
Copyright (c) DEMA Consulting. Licensed under the MIT License. See LICENSE for details.
By contributing to this project, you agree that your contributions will be licensed under the MIT License.
- π Report Bugs: GitHub Issues
- π‘ Request Features: GitHub Issues
For security concerns and vulnerability reporting, see the Security Policy.

