Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/build-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- "dotnet-ai/hybrid-search-ef-core-pgvector/**"
- "dotnet-ai/agent-framework-incident-triage/**"
- "dotnet-ai/mcp-server-csharp-dotnet/**"
- "dotnet-ai/microsoft-extensions-ai-evaluation/**"
- "dotnet-aspire/orchestrate-distributed-system/**"
- "software-architecture/architecture-testing-dotnet/**"
- "distributed-systems/transactional-outbox-ef-core/**"
Expand Down Expand Up @@ -41,6 +42,7 @@ on:
- "dotnet-ai/hybrid-search-ef-core-pgvector/**"
- "dotnet-ai/agent-framework-incident-triage/**"
- "dotnet-ai/mcp-server-csharp-dotnet/**"
- "dotnet-ai/microsoft-extensions-ai-evaluation/**"
- "dotnet-aspire/orchestrate-distributed-system/**"
- "software-architecture/architecture-testing-dotnet/**"
- "distributed-systems/transactional-outbox-ef-core/**"
Expand Down Expand Up @@ -2102,3 +2104,38 @@ jobs:
--no-build
--
src/FirstMcpServer/bin/Release/net10.0/FirstMcpServer.dll

test-microsoft-extensions-ai-evaluation:
name: Test Microsoft.Extensions.AI.Evaluation sample
runs-on: ubuntu-latest

defaults:
run:
working-directory: dotnet-ai/microsoft-extensions-ai-evaluation

steps:
- name: Check out repository
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Install verified .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.404"

- name: Restore
run: dotnet restore MicrosoftExtensionsAIEvaluation.slnx

- name: Build Release
run: dotnet build MicrosoftExtensionsAIEvaluation.slnx --configuration Release --no-restore

- name: Run offline tests
run: dotnet test MicrosoftExtensionsAIEvaluation.slnx --configuration Release --no-build --no-restore

- name: Reproduce and compare both offline scorecards
run: |
dotnet run --project src/EvaluationRunner --configuration Release --no-build --no-restore -- . "$RUNNER_TEMP/evaluation-candidate.md"
dotnet run --project src/EvaluationRunner --configuration Release --no-build --no-restore -- --repaired . "$RUNNER_TEMP/evaluation-repaired.md"
diff -u reports/candidate-scorecard.md "$RUNNER_TEMP/evaluation-candidate.md"
diff -u reports/repaired-scorecard.md "$RUNNER_TEMP/evaluation-repaired.md"
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Each sample folder contains a focused implementation of one tutorial topic. The
| [`dotnet-ai/hybrid-search-ef-core-pgvector`](dotnet-ai/hybrid-search-ef-core-pgvector/) | Verified .NET 10 API combining PostgreSQL full-text search (GIN) and pgvector cosine retrieval (HNSW), fused with Reciprocal Rank Fusion | [Hybrid Search in .NET with EF Core 10 and pgvector](https://www.dotnet-guide.com/tutorials/dotnet-ai/hybrid-search-ef-core-pgvector/) |
| [`dotnet-ai/agent-framework-incident-triage`](dotnet-ai/agent-framework-incident-triage/) | Evidence-first Microsoft Agent Framework sample with read-only tools, deterministic incident evidence, `AgentSession` reuse, and correlation-vs-causation boundaries | [Microsoft Agent Framework Tutorial in C#: Build a Tool-Using AI Agent](https://www.dotnet-guide.com/tutorials/dotnet-ai/agent-framework-incident-triage/) |
| [`dotnet-ai/mcp-server-csharp-dotnet`](dotnet-ai/mcp-server-csharp-dotnet/) | .NET 10 MCP stdio server with three read-only tools, deterministic JSON-backed data, real client discovery/invocation, protocol error verification, and deterministic tests | [Build Your First MCP Server in C# and .NET](https://www.dotnet-guide.com/tutorials/dotnet-ai/mcp-server-csharp-dotnet/) |
| [`dotnet-ai/microsoft-extensions-ai-evaluation`](dotnet-ai/microsoft-extensions-ai-evaluation/) | Offline prompt regression testing across 12 incidents and five hard checks, with optional live evaluation | Tutorial in preparation. [Browse .NET AI tutorials](https://www.dotnet-guide.com/tutorials/dotnet-ai/) |
| [`dotnet-aspire/orchestrate-distributed-system`](dotnet-aspire/orchestrate-distributed-system/) | Minimal Aspire AppHost coordinating a web project and API with service discovery and startup ordering | [Aspire in .NET: Orchestrate, Run, and Deploy a Distributed System from One App Host](https://www.dotnet-guide.com/tutorials/dotnet-aspire/orchestrate-distributed-system/) |
| [`software-architecture/architecture-testing-dotnet`](software-architecture/architecture-testing-dotnet/) | Minimal NetArchTest.eNhancedEdition rule that prevents Domain from depending on outer layers | [Architecture Testing in .NET: Enforce Layer and Module Boundaries with NetArchTest and ArchUnitNET](https://www.dotnet-guide.com/tutorials/software-architecture/architecture-testing-dotnet/) |
| [`distributed-systems/transactional-outbox-ef-core`](distributed-systems/transactional-outbox-ef-core/) | Minimal EF Core and SQLite demonstration that saves business state and an outbox message atomically, then publishes it through a one-shot relay | [Transactional Outbox Pattern in .NET with EF Core (.NET 10): Fix the Dual-Write Problem](https://www.dotnet-guide.com/tutorials/distributed-systems/transactional-outbox-ef-core/) |
Expand Down Expand Up @@ -91,6 +92,15 @@ dotnet build .\FirstMcpServer.slnx --configuration Release --no-restore
dotnet test .\tests\FirstMcpServer.Tests\FirstMcpServer.Tests.csproj --configuration Release --no-build
dotnet run --project .\src\McpClientDemo\McpClientDemo.csproj --configuration Release --no-build -- .\src\FirstMcpServer\bin\Release\net10.0\FirstMcpServer.dll
```
### Microsoft.Extensions.AI.Evaluation incident triage

```powershell
cd dotnet-ai\microsoft-extensions-ai-evaluation
dotnet test .\MicrosoftExtensionsAIEvaluation.slnx --configuration Release
dotnet run --project .\src\EvaluationRunner --configuration Release -- .
dotnet run --project .\src\EvaluationRunner --configuration Release -- --repaired .
```

## Repository structure

```text
Expand Down Expand Up @@ -119,13 +129,21 @@ tutorials/
| | |-- docs/
| | |-- src/
| | `-- tests/
| `-- mcp-server-csharp-dotnet/
| |-- FirstMcpServer.slnx
| |-- README.md
| |-- global.json
| |-- verified-environment.json
| |-- docs/
| |-- scripts/
| |-- mcp-server-csharp-dotnet/
| | |-- FirstMcpServer.slnx
| | |-- README.md
| | |-- global.json
| | |-- verified-environment.json
| | |-- docs/
| | |-- scripts/
| | |-- src/
| | `-- tests/
| `-- microsoft-extensions-ai-evaluation/
| |-- MicrosoftExtensionsAIEvaluation.slnx
| |-- cases/
| |-- prompts/
| |-- responses/
| |-- reports/
| |-- src/
| `-- tests/
|-- dotnet-aspire/
Expand Down
3 changes: 3 additions & 0 deletions dotnet-ai/microsoft-extensions-ai-evaluation/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/prompts/*.txt -text
/examples/provenance/prompt.txt -text
/reports/*.md text eol=lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/EvaluationRunner/EvaluationRunner.csproj" />
<Project Path="src/LiveEvaluation/LiveEvaluation.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/EvaluationRunner.Tests/EvaluationRunner.Tests.csproj" />
</Folder>
</Solution>
183 changes: 183 additions & 0 deletions dotnet-ai/microsoft-extensions-ai-evaluation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# Microsoft.Extensions.AI.Evaluation incident triage sample

This solution implements five `Microsoft.Extensions.AI.Evaluation.IEvaluator`
checks against the validated Step 2 dataset and compares baseline and
candidate results for each incident and check. The release policy combines
those results into a SHIP, REVIEW, or BLOCK decision. The evaluators consume response JSON
and case evidence. They require neither a model endpoint nor an API key.

- [12-case incident evaluation dataset](docs/dataset.md)
- [Baseline vs candidate scorecard](reports/candidate-scorecard.md)
- [Baseline vs repaired scorecard](reports/repaired-scorecard.md)

## Reproduce the candidate scorecard

From the extracted sample root, run:

```powershell
dotnet run --project src/EvaluationRunner -c Release -- .
```

To save the output, pass a second path:

```powershell
dotnet run --project src/EvaluationRunner -c Release -- . candidate-scorecard.local.md
```

The runner validates the case and prompt metadata on all 24 hand-authored
responses, evaluates five hard checks per incident and run, and compares
all 60 paired results. The [candidate scorecard](reports/candidate-scorecard.md)
records **BLOCK**. Both prompts pass nine cases overall. The per-check results
show four regressions, two improvements, and one existing noncritical failure.

The command exits successfully after producing the scorecard because the
replay ran successfully. The release decision is shown in the scorecard.
Invalid fixture sets stop replay with a nonzero exit code. The test suite
checks the expected BLOCK and requires a byte-for-byte scorecard match.

The fixtures reproduce the intended tutorial examples without model calls.
The prompt files and matching fixtures are illustrative material.

## Diagnose and replay the repair

Start with the original failing incident:

```powershell
dotnet run --project src/EvaluationRunner -c Release -- --case incident-01-temporal-correlation .
```

This diagnostic compares candidate v2 with repaired v3. Cause support and
unknown preservation improve from FAIL to PASS. It provides quick feedback
on one case. Then run the full repaired suite for a release decision:

```powershell
dotnet run --project src/EvaluationRunner -c Release -- --repaired .
```

The full replay compares repaired v3 against the original baseline v1.
All 12 repaired fixtures pass all five checks. The [repaired scorecard](reports/repaired-scorecard.md)
records **SHIP** under this tutorial's fixture policy. It shows three
citation improvements versus baseline and 57 unchanged passes. The
original candidate scorecard still reproduces **BLOCK**.

Repaired v3 requires evidence that establishes a cause. It also asks for
citations when documenting a gap in the data. All 12 repaired responses
are hand-authored to illustrate these changes. The replay verifies the
harness and its release decision on those fixtures.

## Run the tests

Use .NET SDK 10.0.404 or a later patch in the same SDK feature band.
From the extracted folder, run:

```powershell
dotnet test MicrosoftExtensionsAIEvaluation.slnx -c Release
```

The initial restore needs a reachable NuGet feed. The solution targets
`net10.0` and uses `Microsoft.Extensions.AI.Evaluation` 10.11.1.

## Hard checks

| Check | What it evaluates | Severity on failure |
|---|---|---|
| Response contract | JSON fields and types, unique IDs, and cause-status/null consistency | Critical |
| Required citations | Every required evidence ID is cited | Critical when the case's `critical` flag is true |
| Citation validity | Every cited ID exists in the current case | Critical |
| Unknown preservation | The response preserves the expected unknowns and avoids marking other facts unknown | Critical when a required critical unknown is omitted |
| Cause support | The cause status and cause ID agree with the case | Critical when the response asserts a confirmed cause that disagrees with the case |

Every evaluator returns a named `BooleanMetric` with a reason. A failed
metric records severity in `dotnet-guide.severity` metadata. Invalid JSON fails
the response contract. The remaining checks return a null metric with
`Not evaluated` in the reason, since the fields cannot be trusted. A
case-specific evaluator requires an `IncidentEvaluationContext`.

The general response contract checks that the summary has text. A human can
review its meaning. The tests demonstrate a well-formed response with an
unsupported claim in the summary whose structured checks all pass.

The canonical unsupported-cause example has valid JSON and citations. It fails
cause support and unknown preservation, each at critical severity. Both that
example and the passing examples are hand-authored. The tests also construct
expected structured responses for all 12 cases to exercise the checks.

## Compare two evaluation runs

Use `HardCheckResult.FromMetric` to pair a named `BooleanMetric` with its
incident ID, then pass the resulting rows from both runs to
`HardCheckComparer.Compare`. The result preserves the reason and any failure
severity from each run.

| Baseline | Candidate | Classification |
|---|---|---|
| Pass | Pass | Unchanged pass |
| Pass | Fail | Regression |
| Fail | Pass | Improvement |
| Fail | Fail | Existing failure |
| Either result was unevaluated | | Not comparable |

The comparer pairs rows by the case ID and check name. Input order does not
affect the pairing. Duplicate keys, empty inputs, and keys present in only one
run raise an error. A full-suite caller must still verify that both runs
cover the expected cases and checks.

In the tested incident-01 example, the baseline leaves the cause unconfirmed
and the candidate asserts an unsupported cause. Their cause support row
is classified as a regression with critical candidate severity.

## Mixed-failure walkthrough

Use `incident-03-latency-and-feature-flag` as a second scenario. Its baseline
and candidate response files in `examples/` are hand-authored.

The baseline reports the latency alert and leaves the cause unconfirmed.
It omits the evidence ID for the flag rollout. The candidate cites both
records, then claims the flag caused the latency increase. The evidence
only shows that the rollout preceded the alert.

| Hard check | Baseline | Candidate | Classification |
|---|---|---|---|
| Response contract | Pass | Pass | Unchanged pass |
| Required citations | Fail | Pass | Improvement |
| Citation validity | Pass | Pass | Unchanged pass |
| Unknown preservation | Pass | Fail | Regression |
| Cause support | Pass | Fail | Critical regression |

Both responses fail overall. The per-check comparison shows why they failed
and preserves the improvement. The release-policy test returns `BLOCK`
and identifies cause support as a blocker.

## Evaluate a release

Pass the comparison rows and the independent list of expected incident and
check pairs to `ReleasePolicy.Evaluate`. For a full run, derive the expected
pairs from the configured cases and evaluator names. Use the original
baseline for both candidate and repaired release decisions.

The returned assessment includes the decision and reasons for its issues.
See [the evaluation policy](docs/evaluation-policy.md) for the decision
table, coverage handling, and the optional quality review signal.

## Verify a saved response

`PromptIdentity` computes a SHA-256 hash of the exact UTF-8 prompt.
`ResponseFixture.Load` requires the expected case and prompt. It rejects
a fixture whose case ID, prompt ID, prompt version, or prompt hash differs.
The loader preserves the response text for the evaluators.

See [response provenance](docs/response-provenance.md) for the metadata
contract and the hand-authored example.

## Optional live evaluation

For model-generated evidence, see [optional live evaluation](docs/live-evaluation.md).
The runner captures baseline and candidate outputs into a separate run folder
and writes detailed reports. The committed offline scorecards continue to use
their hand-authored fixtures. The test suite uses scripted clients for live
runner coverage.

## Verification

See the [verification record](docs/verified-environment.md) and
[scope](SCOPE.md) for the offline and live evidence.
16 changes: 16 additions & 0 deletions dotnet-ai/microsoft-extensions-ai-evaluation/SCOPE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Sample scope

This sample teaches prompt regression testing with
`Microsoft.Extensions.AI.Evaluation`. It uses synthetic incident evidence
to show how an answer can improve one hard check and regress on another.

The sample includes 12 incidents, five deterministic checks, and three
sets of hand-authored responses tied to versioned prompts. Compare the
candidate and repaired prompts against the original baseline. The offline
policy applies to the structured response contract and the case evidence.
Read the free-text summary separately for unsupported claims.

The optional live runner captures separate model responses and writes
hard-check and optional coherence results. Its output is independent of the
committed offline scorecards. See the [live evidence](docs/live-evaluation.md)
for the limits of the verified models.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"id": "incident-01-temporal-correlation",
"category": "ambiguous-causation",
"question": "What happened to checkout-api relative to deploy-1842, and is the root cause confirmed?",
"requestedFactIds": [
"root-cause"
],
"evidence": [
{
"id": "E-201",
"observation": "Deployment deploy-1842 completed at 14:02 UTC."
},
{
"id": "E-101",
"observation": "The checkout-api error spike started at 14:09 UTC."
}
],
"requiredEvidenceIds": [
"E-101",
"E-201"
],
"requiredUnknowns": [
"root-cause"
],
"expectedCauseStatus": "unconfirmed",
"expectedCauseId": null,
"critical": true,
"criticalUnknownIds": [
"root-cause"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"id": "incident-02-queue-and-scheduled-export",
"category": "ambiguous-causation",
"question": "How did the queue backlog line up with the scheduled export, and is the root cause confirmed?",
"requestedFactIds": [
"root-cause"
],
"evidence": [
{
"id": "E-202",
"observation": "The scheduled export started at 11:00 UTC."
},
{
"id": "E-203",
"observation": "The fulfillment queue crossed its backlog threshold at 11:04 UTC."
},
{
"id": "E-204",
"observation": "Worker CPU was below its alert threshold during that interval. No per-job worker trace is available."
}
],
"requiredEvidenceIds": [
"E-202",
"E-203"
],
"requiredUnknowns": [
"root-cause"
],
"expectedCauseStatus": "unconfirmed",
"expectedCauseId": null,
"critical": false,
"criticalUnknownIds": [
"root-cause"
]
}
Loading
Loading