XBag.AI.Testing.Agents 0.1.0-preview.1

This is a prerelease version of XBag.AI.Testing.Agents.
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
                    
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="XBag.AI.Testing.Agents" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XBag.AI.Testing.Agents" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="XBag.AI.Testing.Agents" />
                    
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 XBag.AI.Testing.Agents --version 0.1.0-preview.1
                    
#r "nuget: XBag.AI.Testing.Agents, 0.1.0-preview.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 XBag.AI.Testing.Agents@0.1.0-preview.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=XBag.AI.Testing.Agents&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=XBag.AI.Testing.Agents&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

XBag.AI.Testing.Agents

NuGet License: MIT

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 ChatClientAgent instead, use XBag.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 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. 
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
0.1.0-preview.1 102 10/10/2026