* Python: .NET Samples - Restructure and Improve Samples (Feature Branch) (#4091) * Moved by agent (#4094) * Fix readme links * .NET Samples - Create `04-hosting` learning path step (#4098) * Agent move * Agent reorderd * Remove A2A section from README Removed A2A section from the Getting Started README. * Agent fixed links * Fix broken sample links in durable-agents README (#4101) * Initial plan * Fix broken internal links in documentation Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * Revert template link changes; keep only durable-agents README fix Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * .NET Samples - Create `03-workflows` learning path step (#4102) * Fix solution project path * Python: Fix broken markdown links to repo resources (outside /docs) (#4105) * Initial plan * Fix broken markdown links to repo resources Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * Update README to rename .NET Workflows Samples section --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * .NET Samples - Create `02-agents` learning path step (#4107) * .NET: Fix broken relative link in GroupChatToolApproval README (#4108) * Initial plan * Fix broken link in GroupChatToolApproval README Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * Update labeler configuration for workflow samples * .NET - Reorder Agents samples to start from Step01 instead of Step04 (#4110) * Fix solution * Resolve new sample paths * Move new AgentSkills and AgentWithMemory_Step04 samples * Fix link * Fix readme path * fix: update stale dotnet/samples/Durable path reference in AGENTS.md Co-authored-by: crickman <66376200+crickman@users.noreply.github.com> * Moved new sample * Update solution * Resolve merge (new sample) * Sync to new sample - FoundryAgents_Step21_BingCustomSearch * Updated README * .NET Samples - Configuration Naming Update (#4149) * .NET: Restore AzureFunctions index parity with ConsoleApps under DurableAgents samples (#4221) * Clean-up `05_host_your_agent` * Config setting consistency * Refine samples * AGENTS.md * Move new samples * Re-order samples * Move new project and fixup solution * Fixup model config * Fix up new UT project --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Self-Reflection Evaluation with Groundedness Assessment
This sample demonstrates the self-reflection pattern using Agent Framework with Microsoft.Extensions.AI.Evaluation.Quality evaluators. The agent iteratively improves its responses based on real groundedness evaluation scores.
For details on the self-reflection approach, see Reflexion: Language Agents with Verbal Reinforcement Learning (NeurIPS 2023).
What this sample demonstrates
- Self-reflection loop that improves responses using real
GroundednessEvaluatorscores - Using
RelevanceEvaluatorandCoherenceEvaluatorfor multi-metric quality assessment - Combining quality and safety evaluators with
CompositeEvaluator - Configuring
ContentSafetyServiceConfigurationfor safety evaluators alongside LLM-based quality evaluators - Tracking improvement across iterations
Prerequisites
Before you begin, ensure you have the following prerequisites:
- .NET 10 SDK or later
- Azure AI Foundry project (hub and project created)
- Azure OpenAI deployment (e.g., gpt-4o or gpt-4o-mini)
- Azure CLI installed and authenticated (for Azure credential authentication)
Note: This demo uses Azure CLI credentials for authentication. Make sure you're logged in with az login and have access to the Azure Foundry resource. For more information, see the Azure CLI documentation.
Azure Resources Required
- Azure AI Hub and Project: Create these in the Azure Portal
- Azure OpenAI Deployment: Deploy a model (e.g., gpt-4o or gpt-4o-mini)
- Agent model: Used to generate responses
- Evaluator model: Quality evaluators use an LLM; best results with GPT-4o
- Azure CLI: Install and authenticate with
az login
Environment Variables
Set the following environment variables:
$env:AZURE_AI_PROJECT_ENDPOINT="https://your-project.api.azureml.ms" # Azure Foundry project endpoint
$env:AZURE_OPENAI_ENDPOINT="https://your-openai.openai.azure.com/" # Azure OpenAI endpoint (for quality evaluators)
$env:AZURE_AI_MODEL_DEPLOYMENT_NAME="gpt-4o-mini" # Model deployment name
Note: For best evaluation results, use GPT-4o or GPT-4o-mini as the evaluator model. The groundedness evaluator has been tested and tuned for these models.
Run the sample
Navigate to the sample directory and run:
cd dotnet/samples/02-agents/FoundryAgents/FoundryAgents_Evaluations_Step02_SelfReflection
dotnet run
Expected behavior
The sample runs three evaluation scenarios:
1. Self-Reflection with Groundedness
- Asks a question with grounding context
- Evaluates response groundedness using
GroundednessEvaluator - If score is below 4/5, asks the agent to improve with feedback
- Repeats up to 3 iterations
- Tracks and reports the best score achieved
2. Quality Evaluation
- Evaluates a single response with multiple quality evaluators:
RelevanceEvaluator— is the response relevant to the question?CoherenceEvaluator— is the response logically coherent?GroundednessEvaluator— is the response grounded in the provided context?
3. Combined Quality + Safety Evaluation
- Runs both quality and safety evaluators together:
RelevanceEvaluator,CoherenceEvaluator(quality)ContentHarmEvaluator(safety — violence, hate, sexual, self-harm)ProtectedMaterialEvaluator(safety — copyrighted content detection)
Understanding the Evaluation
Groundedness Score (1-5 scale)
The GroundednessEvaluator measures how well the agent's response is grounded in the provided context:
- 5 = Excellent - Response is fully grounded in context
- 4 = Good - Mostly grounded with minor deviations
- 3 = Fair - Partially grounded but includes unsupported claims
- 2 = Poor - Significant amount of ungrounded content
- 1 = Very Poor - Response is largely unsupported by context
Self-Reflection Process
- Initial Response: Agent generates answer based on question + context
- Evaluation:
GroundednessEvaluatorscores the response (1-5) - Feedback: If score < 4, agent receives the score and is asked to improve
- Iteration: Process repeats until good score or max iterations
Best Practices
- Provide Complete Context: Ensure grounding context contains all information needed to answer the question
- Clear Instructions: Give the agent clear instructions about staying grounded in context
- Use Quality Models: GPT-4o recommended for evaluation tasks
- Multiple Evaluators: Use combination of evaluators (groundedness + relevance + coherence)
- Batch Processing: For production, process multiple questions in batch
Related Resources
- Reflexion Paper (NeurIPS 2023)
- Microsoft.Extensions.AI.Evaluation Libraries
- GroundednessEvaluator API Reference
- Azure AI Foundry Evaluation Service
Next Steps
After running self-reflection evaluation:
- Implement similar patterns for other quality metrics (relevance, coherence, fluency)
- Integrate into CI/CD pipeline for continuous quality assurance
- Explore the Safety Evaluation sample (FoundryAgents_Evaluations_Step01_RedTeaming) for content safety assessment