Technical Article
Evaluating AI Agent Workflows with Microsoft Agent Framework in .NET
Use Microsoft Agent Framework evaluation in .NET alongside scenario datasets and deterministic checks to assess agent outcomes, tool use, workflow boundaries, and regressions.
An agent workflow can pass every unit test and still give a poor answer. The graph may route correctly, a tool may execute within its budget, and session state may persist safely, while the model selects weak evidence or misreads the result.
The Building AI Agents with .NET articles already cover many deterministic boundaries: typed messages, tool validation, workflow routing, persistence, and traces. Several of those articles also name the same remaining problem: their tests do not measure live model behavior. Microsoft Agent Framework's evaluation API gives .NET developers a way to address that gap. This article stands apart from the books: it explains an available framework capability and proposes an evaluation approach, not a feature claimed to exist in every companion chapter.
What MAF adds to the evaluation loop
Microsoft Agent Framework documents EvaluateAsync for an AIAgent, local checks such as ToolCalledCheck, expected outputs and tool calls, and evaluation of a completed workflow Run. Workflow evaluation can report an overall result and per-agent results. The .NET surface also works with evaluators from Microsoft.Extensions.AI.Evaluation for quality and safety assessment.
That is useful plumbing, but it does not define success for an insurance claim, purchase approval, or incident investigation. The application still needs representative cases, expected business outcomes, and an explicit rule for which failures block a release. MAF evaluation sits beside deterministic workflow tests; it does not replace them.
Evaluate the task and the path
An agent run has at least two observable results. The outcome is what the user received or what business state changed. The path is the sequence of retrievals, tool calls, handoffs, and approvals that produced it.
Both matter. A correct-looking answer may have used a tool that should not have been available. A valid tool call may still return an answer that invents a policy. A workflow may correctly stop for human approval while presenting the reviewer with incomplete evidence.
For each scenario, record the user request and an independently reviewed expectation. Then check separate dimensions:
- Task completion: Did the run produce the required result, or decline when the task could not be completed safely?
- Grounding: Can important claims be traced to the supplied evidence or tool output?
- Tool behavior: Were the necessary tools called with suitable arguments, and were unnecessary or forbidden calls absent?
- Application rules: Did typed validation, authorization, approval, and side-effect boundaries hold?
- Operations: How long did the run take, how many calls did it make, and what resources did it use?
Microsoft Foundry's agent evaluation guidance similarly separates end-to-end outcomes from the quality of process steps such as tool selection and tool input accuracy. Those are useful lenses, but the application's own business rules still need explicit checks.
Start with cases that describe decisions
A test set should represent the decisions the agent will encounter, not just a collection of easy questions. For the claims-review example in Part 2, a case might say:
{
"id": "claim-review-approval-required",
"request": "Review this high-value claim and explain the next step.",
"expectedOutcome": "waiting-for-human-approval",
"requiredEvidence": ["claim record", "risk assessment"],
"forbiddenEffects": ["final claim decision without approval"],
"category": "approval-boundary"
}
The names above describe an evaluation case, not a schema implemented by the book. A real fixture would also carry the claim fields, policy version, expected workflow status, and exact evidence snapshot needed to replay it.
Add cases for ordinary success, ambiguous requests, missing evidence, conflicting evidence, irrelevant retrieved text, tool failure, cancellation, and attempts to steer the agent with instructions inside retrieved content. Each case should say what the system must do when information is insufficient. An honest refusal or request for clarification can be the correct result.
Keep a small, hand-reviewed set of critical cases. Expand it with failures found during development and carefully selected production traces after removing private data. Version the cases and the evidence they depend on; a changing document or policy can otherwise make a good run appear to regress.
Keep deterministic checks deterministic
The fastest checks do not need a model grader. Assert them in ordinary .NET tests against structured run evidence:
- The final workflow status is
WaitingForApprovalwhen review is required. - No final decision or purchase side effect occurs before approval.
- A tool call stays inside its allowed catalog and call budget.
- Required IDs and citations refer to records that were actually supplied.
- The run ends within the configured deadline and returns a classified failure when a dependency fails.
The existing RequestPort workflow testing article shows why a graph-level assertion matters: calling a policy in isolation cannot prove the correct workflow edge ran. The same principle applies to evaluation. Capture the real route and persisted state, then judge the model's contribution separately.
Microsoft Agent Framework now documents a .NET evaluation API with local checks and expected tool calls. For an agent that should consult a policy search tool, a focused check can look like this:
AgentEvaluationResults results = await agent.EvaluateAsync(
new[] { "What does the policy say about this claim?" },
new LocalEvaluator(
EvalChecks.ToolCalledCheck("search_policy")),
expectedToolCalls: new[]
{
new[] { new ExpectedToolCall("search_policy") },
});
results.AssertAllPassed();
search_policy is an illustrative tool name. A local evaluator makes the grading check local; this example still runs the agent, which may call a model or tool. It proves that the named tool was called, not that the search query was good, its result was used accurately, or the final answer was grounded. Those need additional checks. For a fast offline test, substitute the model boundary as the workflow tests do; for a behavior evaluation, run a controlled live agent against fixed fixtures.
Judge meaning with a written rubric
Some criteria need human judgment or a model-based grader. Write the rubric before examining a candidate run. For a policy answer, the rubric might ask whether the answer cites the right policy, distinguishes known facts from assumptions, states the next action, and avoids claiming that approval has already happened.
A grader should receive the request, permitted evidence, observed tool results, the answer, and the rubric. Keep the rubric specific enough that a reviewer could explain a failure. Calibrate model-graded scores against a small set of human-reviewed examples and inspect disagreements. A fluent explanation is not proof that the underlying action was correct.
Do not make one average score the whole release decision. A high average can hide a rare but serious approval bypass. Track critical rule violations separately from softer quality dimensions, and review examples of both failures and apparently surprising passes.
Microsoft's .NET evaluation libraries provide quality, safety, reporting, and response-caching components. Foundry offers agent-level evaluators for outcome and process checks. These can reduce harness work, but the criterion, test data, and acceptance policy remain application decisions. Check current package and service availability when choosing an implementation, because evaluation APIs and some hosted evaluators continue to change.
Compare versions without hiding variation
Run the same versioned cases against a baseline and a candidate. Record the prompt version, model deployment, tool catalog, retrieval policy, document snapshot, and evaluator version with each result. If several things change at once, a score difference is hard to explain.
Repeat a representative subset of live cases because generated outputs can vary. Compare per-category pass rates and inspect individual failures, especially for safety and side-effect cases. Set hard gates for deterministic invariants and separately chosen thresholds for graded quality, latency, and resource use. A threshold should come from the product's risk tolerance and a measured baseline, not from a generic percentage copied into every application.
After release, review sampled traces and user-reported failures, redact sensitive content, and promote confirmed failure cases into the versioned set. The OpenTelemetry article explains how traces expose timing and execution paths. Traces are evidence for diagnosis; they are not themselves a quality score.
What the evaluation can establish
A disciplined evaluation loop can show that a candidate improved on a defined set of tasks, that important workflow boundaries held, and where model behavior still failed. It cannot prove that every future request is safe or correct. The test set is a sample, graders can disagree with experts, and a deployment may encounter data or tools the evaluation never covered.
The useful goal is therefore continuous evidence: deterministic tests protect the application contract, scenario evaluations probe model behavior, and production feedback supplies the next cases. Together they make changes to prompts, models, tools, and retrieval policies reviewable before those changes reach users.