-
Notifications
You must be signed in to change notification settings - Fork 639
.NET: Add Writer-Critic Iterative Refinement Workflow Sample #1790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…custom executors, agents, switch, custom states, different entry points for the executors.
|
More Workflow love, @alliscode & @lokitoth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new foundational workflow sample (08_WriterCriticWorkflow) that demonstrates iterative refinement patterns with Writer and Critic agents, showcasing conditional routing, shared state management, and max iteration safety limits.
- Implements a Writer-Critic feedback loop with conditional workflow routing based on approval decisions
- Demonstrates multiple message handlers in a single executor and shared state tracking across workflow iterations
- Includes max iteration safety cap to prevent infinite loops
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs | New sample implementation demonstrating Writer-Critic iterative refinement workflow with conditional routing, shared state, and multiple message handlers |
| dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/08_WriterCriticWorkflow.csproj | Project file for the new sample with required dependencies |
| dotnet/samples/GettingStarted/Workflows/README.md | Added reference to new Writer-Critic Workflow sample |
| dotnet/agent-framework-dotnet.slnx | Added new sample project to solution |
dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs
Show resolved
Hide resolved
dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs
Outdated
Show resolved
Hide resolved
dotnet/samples/GettingStarted/Workflows/_Foundational/08_WriterCriticWorkflow/Program.cs
Outdated
Show resolved
Hide resolved
…rCriticWorkflow/Program.cs Co-authored-by: Copilot <[email protected]>
…rCriticWorkflow/Program.cs Co-authored-by: Copilot <[email protected]>
| Console.WriteLine($"=== Critic (Iteration {state.Iteration}) ===\n"); | ||
|
|
||
| StringBuilder sb = new(); | ||
| await foreach (AgentRunResponseUpdate update in this._agent.RunStreamingAsync(message, cancellationToken: cancellationToken)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use structured output?
Motivation and Context
This PR adds a new foundational workflow sample that demonstrates an iterative refinement pattern with quality gates - a crucial pattern not covered by existing samples.
Why is this change required?
The current samples demonstrate basic conditional routing (EdgeCondition) and switch-case patterns, but none show how to implement cyclic feedback loops with quality gates, iteration safety mechanisms, and structured decision-making for approval workflows.
Providing a GroupChat Construct is ok but this does not expose the logic inside it and is hard to debug when an issue happens. Also it does not support max iterations, and is hard to customize.
This example aims to change that by implementing a Critic workflow (as in the official first paper) with a maker agent and a critic agent collaborating until the desired outcome is reached, having a final Summarizer agent and executor.
This sets a pattern so everybody can build upon it (as a sub-workflow, add reviewer agents supporting the critic, etc.)
This workflow can be debugged and traced, and in short future, be live-viewed as it runs and supports its rendering as a graph.
What problem does it solve?
Developers building AI workflows often need to implement iterative refinement patterns where:
• Content is created, reviewed, and revised multiple times
• A quality gate agent approves or rejects work with specific feedback
• Safety mechanisms prevent infinite loops
• Iteration state is tracked across multiple executor invocations
What scenario does it contribute to?
Solves #1789
This sample enables real-world scenarios including:
• Content creation pipelines (blog posts, documentation, marketing copy)
• Code review workflows with iterative improvements
• Document review systems (legal, compliance, technical)
• Quality assurance automation
• Design iteration workflows
Description
This sample introduces the Writer-Critic Workflow pattern (08 in Foundational samples), demonstrating:
Core Pattern:
• Writer agent creates initial content
• Critic agent reviews and decides: approve → Summary, or reject → Writer (with feedback)
• Loops until approval or max iterations (3) reached
• Summary executor presents final approved content
Key Technical Contributions:
Code Highlights:
• Uses FlowState for iteration tracking across workflow executions
• Critic outputs CriticDecision with approved/rejected status and feedback
• Writer has dual handlers for initial requests vs. revision requests
• Streaming support for real-time progress visibility
• Console output clearly shows iteration progression
This pattern complements existing samples:
• vs. EdgeCondition (01): Adds cyclic routing, not just divergent paths
• vs. CustomAgentExecutors: Adds max iteration safety and explicit termination logic
• vs. Loop samples: Goal-oriented iteration vs. collection iteration
Contribution Checklist
• [x] The code builds clean without any errors or warnings
• [x] The PR follows the Contribution Guidelines
• [x] All unit tests pass, and I have added new tests where possible
• [ ] Is this a breaking change? No