AgentInfer 0.3.0
See the version list below for details.
dotnet add package AgentInfer --version 0.3.0
NuGet\Install-Package AgentInfer -Version 0.3.0
<PackageReference Include="AgentInfer" Version="0.3.0" />
<PackageVersion Include="AgentInfer" Version="0.3.0" />
<PackageReference Include="AgentInfer" />
paket add AgentInfer --version 0.3.0
#r "nuget: AgentInfer, 0.3.0"
#:package AgentInfer@0.3.0
#addin nuget:?package=AgentInfer&version=0.3.0
#tool nuget:?package=AgentInfer&version=0.3.0
AgentInfer
Object-oriented agents for .NET. An agent is an interface, its prompt is an attribute, and a Roslyn generator writes the implementation at build time.
[Agent("""
You answer questions about a household ledger.
Use only figures you were given. Never invent an amount.
""")]
public interface ILedgerAnalyst
{
[Prompt("Summarize this spending against its budget in two sentences.")]
public Task<string> SummarizeAsync(string spending, CancellationToken ct = default);
[Prompt("Judge whether this summary is supported by the figures given.")]
public Task<Verdict> ReviewAsync(string summary, string figures, CancellationToken ct = default);
}
That is the whole authoring surface. LedgerAnalystAgent is generated,
implements the interface, and takes an AgentRunner. Consumers inject
ILedgerAnalyst, so mocking an agent in a test needs no framework support and
no model.
Install
dotnet add package AgentInfer
One reference is the whole install: the generator ships inside the runtime
package under analyzers/dotnet/cs. Targets net8.0 and net10.0.
| Package | What it is |
|---|---|
AgentInfer |
The runtime generated code calls into, with the generator inside it |
AgentInfer.Abstractions |
The attributes. netstandard2.0, zero dependencies |
AgentInfer.DependencyInjection |
Configuration binding and DI registration |
The two decisions worth knowing
Predict is the absence of an attribute. [Strategy(Strategies.CodeAct)] is
a line somebody typed, that a reviewer sees, and that grep finds. A framework
that defaults to executing model-written code runs unreviewed code by default.
Opting into code execution has to be visible.
Prompts are string constants, not doc comments. C# strips XML docs into a separate file unreachable at run time. That reads like a handicap and is the opposite: a constant survives compilation and trimming, and cannot fall through to a base class's prompt the way a docstring silently can.
Where it is
The generator, the attributes, a Predict runtime over
Microsoft.Extensions.AI, [AgentTool] with compile-time schemas, enforced
[RequiresPermission], a tool-calling loop, AgentScope for counting and
bounding a whole workflow, and IReplyContract for a typed reply that binds
without reflection — all verified end to end against a stub endpoint.
There is no sandbox and no CodeAct. This library chooses which declared tool
to call and with what arguments, and nothing more. Treat every [AgentTool] you
declare as reachable by anyone who can influence the model's input.
The trim and AOT analyzers are on for everything that ships, so the claim that nothing is discovered at run time is checked by the build rather than asserted here.
Documentation
| Prompts and diagnostics | Prompt files, and the sixteen build errors that check them |
| Tools | Compile-time schemas, optional arguments, enforced permissions |
| Models and roles | Binding a role to a model, and keeping credentials out of the file |
| Composing agents | Chaining, routing, agent-as-tool, and when to write the class by hand |
| Typed replies | IReplyContract, JSON contexts, anticipated failures |
| Bounding and measuring | AgentScope, the instruments, and what a real model changed |
| Gotchas | Four things that cost time here |
Build
Needs the .NET 10 SDK — global.json pins it. The library targets net8.0 as
well, so CI installs the net8.0 runtime to run that half of the tests.
dotnet build
dotnet test
dotnet run --project samples/Incident # four workflow patterns, no model needed
dotnet run --project samples/Intake # a hand-written agent over generated tools
dotnet run --project samples/Ledger # tools, permissions, model roles
samples/Incident and samples/Intake run against a scripted IChatClient, so
they work with nothing installed — the runtime takes an IChatClient and
nothing else, which makes a workflow's shape testable without paying for a
token. It is not a substitute for a real run: every interesting failure
described in the docs came from pointing this at a small local model, and a
scripted one reproduces none of them. Pass --live for that, and --metrics to
print the instruments at exit.
samples/Ledger needs a real endpoint. See
Models and roles for the configuration it reads, and
Bounding and measuring for what the counters are for.
No credential belongs in a committed file. Keys come from the environment or
from appsettings.Development.json, which is gitignored.
Contributing
Issues and pull requests are welcome. CONTRIBUTING.md covers
the part that is not guessable from the tree: the SDK the build pins, the four
things that fail in CI more often than anywhere else, when <Version> has to
move, and why the generator targets the compiler versions it does.
To report a vulnerability, see SECURITY.md — privately, please,
rather than in an issue.
License
MIT. See LICENSE.
| Product | Versions 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. |
-
net10.0
- AgentInfer.Abstractions (>= 0.3.0)
- Microsoft.Extensions.AI (>= 10.10.0)
- Microsoft.Extensions.AI.Abstractions (>= 10.10.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
-
net8.0
- AgentInfer.Abstractions (>= 0.3.0)
- Microsoft.Extensions.AI (>= 10.10.0)
- Microsoft.Extensions.AI.Abstractions (>= 10.10.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AgentInfer:
| Package | Downloads |
|---|---|
|
AgentInfer.DependencyInjection
Configuration binding and DI registration for AgentInfer. |
GitHub repositories
This package is not used by any popular GitHub repositories.