XBag.AI.Testing.Agents
0.1.0-preview.1
dotnet add package XBag.AI.Testing.Agents --version 0.1.0-preview.1
NuGet\Install-Package XBag.AI.Testing.Agents -Version 0.1.0-preview.1
<PackageReference Include="XBag.AI.Testing.Agents" Version="0.1.0-preview.1" />
<PackageVersion Include="XBag.AI.Testing.Agents" Version="0.1.0-preview.1" />
<PackageReference Include="XBag.AI.Testing.Agents" />
paket add XBag.AI.Testing.Agents --version 0.1.0-preview.1
#r "nuget: XBag.AI.Testing.Agents, 0.1.0-preview.1"
#:package XBag.AI.Testing.Agents@0.1.0-preview.1
#addin nuget:?package=XBag.AI.Testing.Agents&version=0.1.0-preview.1&prerelease
#tool nuget:?package=XBag.AI.Testing.Agents&version=0.1.0-preview.1&prerelease
XBag.AI.Testing.Agents
A scripted, recording fake AIAgent for Microsoft Agent Framework.
Use it as the inner agent when you test what wraps an agent: DelegatingAIAgent decorators, AIAgentBuilder.Use(...)
middleware, workflow glue. It answers with a script, one step per run, and records every run.
Part of the XBag family of .NET packages by Murat Ay. Community package, not affiliated with Microsoft. To fake the model under a
ChatClientAgentinstead, useXBag.AI.Testing(ScriptedChatClient), which this package depends on.
Pipeline slot: the INNERMOST AIAgent, below DelegatingAIAgent decorators / AIAgentBuilder middleware.
One scripted step = one agent run.
Install
dotnet add package XBag.AI.Testing.Agents --prerelease
Example
var inner = new FakeAIAgent(name: "inner")
.Reply(run => $"echo {run.LastUserText}")
.Stream("Merhaba ", "İstanbul").Usage(10, 2);
AIAgent agent = new MyAuditingAgent(inner); // the decorator under test
await agent.RunAsync("ping");
await agent.RunStreamingAsync("pong").ToAgentResponseAsync();
inner.ShouldHaveReceivedRuns(2);
Assert.Equal("pong", inner.Runs[1].LastUserText); // Runs[i].Session / .Options are the instances passed in
inner.ShouldBeExhausted(); // no unused script steps
API
| Member | Purpose |
|---|---|
Reply(text), Reply(run => text), Reply(run => AgentResponse), async Reply((run, ct) => ...) |
a whole response; streamed through AgentResponse.ToAgentResponseUpdates() |
Stream(params string[] chunks), Stream(params AgentResponseUpdate[]) |
explicit streaming updates; aggregated with ToAgentResponse() for RunAsync |
Fail(exception) |
the run throws (from the first MoveNextAsync when streaming) |
.Usage(input, output) |
token usage of the previous step |
Runs |
a RecordedRun per run: Messages (snapshot), Session, Options, IsStreaming, LastUserText, Index |
ShouldBeExhausted(), ShouldHaveReceivedRuns(n) |
strictness checks; a run after the last step throws AIAssertionException |
Missing ids are filled deterministically (resp_<n>, msg_<n>_<i>), AgentId is the agent's id and AuthorName
its name. Sessions are FakeAgentSession and round-trip through SerializeSessionAsync / DeserializeSessionAsync
(state lives in StateBag). GetService<AIAgentMetadata>() reports provider "fake". All members are thread-safe.
Built and tested against Microsoft.Agents.AI 1.24.0 on .NET 8 and .NET 10. Status: preview, the API may change before 1.0.
Source, tests and the other XBag packages: https://github.com/Murat7Ay/xbag-ai
| 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
- Microsoft.Agents.AI.Abstractions (>= 1.24.0)
- XBag.AI.Testing (>= 0.1.0-preview.1)
-
net8.0
- Microsoft.Agents.AI.Abstractions (>= 1.24.0)
- XBag.AI.Testing (>= 0.1.0-preview.1)
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 | 102 | 10/10/2026 |