Loop an AI agent until it gets the right tool result in .NET Microsoft Agent Framework
Authorised Territory demonstrates how to build a .NET console app that repeatedly runs an AI agent until a loop evaluator confirms the agent’s tool output matches an expected condition, using Microsoft Agent Framework components like LoopAgent and DelegateLoopEvaluator.
Overview
The tutorial builds a .NET console application that wraps a “harness” agent in a loop so the agent can keep trying until it returns the correct tool result.
Key elements covered:
- Agent looping using LoopAgent
- Loop evaluation using DelegateLoopEvaluator to decide whether the loop should continue
- Tool calling: the agent calls a tool that retrieves atmospheric pressure
- Condition checking: the evaluator inspects the agent’s latest response to determine whether the expected result has been returned
- Local model runtime: the agent uses granite4.1 running locally via Ollama
The video also references a starting solution from an earlier tutorial: https://youtu.be/2vP-s0yIE_U