Read more of this story at Slashdot.
Read more of this story at Slashdot.
As you may have heard, loops are the hottest thing in AI. The buzz is that rather than you writing prompts, you let your agent do so. The problem is that while all the videos I’ve seen are great at touting the advantages and even explaining the moving parts (though each one has slightly different architecture), I’ve yet to see one that gives concrete C# examples—let alone using the Microsoft Agent Framework.

Soooo, this is the very first in a series. I’m finding my way, stumbling in the dark, so some of this may be a bit simplistic—but I believe it is correct as far as it goes. Remember, however, that the first draft of this post was written by AI. I’ve edited it, but your mileage may vary.
Here’s a thought experiment. Imagine having an agent that keeps trying fixes until a web service stays healthy—retrying configuration changes, re-checking status, and stopping only when a health check returns OK or a safety limit is reached. That behavior—automatic, bounded repetition with an evaluation step between attempts—is exactly what loop programming enables in modern agentic AI. This post explains the pattern, why it matters, and how to implement it in C# using the Microsoft Agent Framework (MAF) concepts.
One-sentence takeaway
Loop programming = agent acts → observes → evaluates → repeats (until accepted or bound). Use MAF’s loop primitives (loop wrapper or middleware + evaluators) to implement this pattern safely in .NET.
Why loop programming matters
Core MAF loop terms
Minimal, runnable-style C# example
Below is a full Program.cs and a simple csproj. The example uses a completion-marker evaluator (“DONE”) and a MaxIterations bound. It is a bit brain-dead, but it will give you a sense of how to string one of these together.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Evaluators;
using Microsoft.Agents.AI.OpenAI.Clients;
class Program
{
static async Task Main(string[] args)
{
// Read API key (set as env var)
string? apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY");
if (string.IsNullOrEmpty(apiKey))
{
Console.WriteLine("Set OPENAI_API_KEY environment variable and re-run.");
return;
}// 1) Create provider client (provider-specific)}
var openAiClient = new OpenAiProviderClient(new OpenAiOptions { ApiKey = apiKey });
// 2) Convert provider client to an agent abstraction
AIAgent baseAgent = openAiClient.AsAIAgent();
// 3) Create a simple marker evaluator that stops when "DONE" appears
var evaluator = new CompletionMarkerLoopEvaluator("DONE");
// 4) Wrap the base agent with loop behavior and bounds
var loopOptions = new LoopAgentOptions { MaxIterations = 5 };
AIAgent loopAgent = new LoopAgent(baseAgent, evaluator, loopOptions);
// 5) Prepare request
var request = new AgentRequest
{
Prompt = "Summarize this paragraph and keep refining until you append DONE:\n\n" +
"The quick brown fox jumps over the lazy dog. This sentence includes all the letters of the English alphabet."
};
// 6) Use a timeout for safety
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
try
{
AgentResponse response = await loopAgent.InvokeAsync(request, cts.Token);
Console.WriteLine("Final response:\n" + response.Text);
}
catch (OperationCanceledException)
{
Console.WriteLine("Operation timed out or was canceled.");
}
}
How to adapt this to the real MAF packages
Designing better evaluators (AI judge and custom evaluator)
Marker evaluator (simple)
AIJudge evaluator (higher quality)
Custom evaluator pattern (checks content + side effects)
Sample custom evaluator
public class KeywordOrJudgeEvaluator : ILoopEvaluator
{
private readonly string _stopKeyword;
private readonly AIAgent? _judgeAgent;
public KeywordOrJudgeEvaluator(string stopKeyword, AIAgent? judgeAgent = null)
{
_stopKeyword = stopKeyword;
_judgeAgent = judgeAgent;
}
public async Task<LoopDecision> EvaluateAsync(AgentResponse lastResponse, CancellationToken ct)
{
if (lastResponse.Text?.Contains(_stopKeyword, StringComparison.OrdinalIgnoreCase) == true)
return LoopDecision.Stop();
if (_judgeAgent != null)
{
var judgeRequest = new AgentRequest
{
Prompt = $"Is the following response acceptable? Answer YES or NO.\n\nResponse:\n{lastResponse.Text}\n\nCriteria: [list your criteria]"
};
var judgeResponse = await _judgeAgent.InvokeAsync(judgeRequest, ct);
if (judgeResponse.Text.Trim().StartsWith("YES", StringComparison.OrdinalIgnoreCase))
return LoopDecision.Stop();
}
return LoopDecision.Continue();
}
}
Practical safety and production best practices
Exponential backoff snippet
int attempt = 0;
while (attempt < maxRetries)
{
attempt++;
try { callTool(); break; }
catch (TransientException)
{
await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)));
}
}
Cost and latency tradeoffs
Debugging, testing, and observability tips
Troubleshooting common failure modes
Real-world scenario examples
Conclusion and next steps
Loop programming is a practical, powerful pattern for agentic AI: agent acts, inspects results, evaluates, and repeats — but only when bounded and observable. The Microsoft Agent Framework offers loop wrapper and evaluator patterns to implement this safely; adapt the example above to your MAF version and provider.
BlogWriter
My demo program, BlogWriter, uses a much more deterministic approach. While the author does pass its draft to the reviewer for evaluation, and they do create a small loop, a true looping approach would, perhaps, return better results. Something to try.
More to come soon…
Jason and Myke have spent the last few days using the iPhone Duo, and they're ready to report back. And, oh yeah, there's also a new iPad mini and a draft of Apple's forthcoming announcements this week!

In 1984, Tomy sold a toy robot that promised a domestic future it couldn’t quite deliver. Forty years later, a maker in Miami gave it vision, a voice, and just enough intelligence to finally pull it off.
The post Omnibot Reborn: Giving a 1984 Robot Butler the Brain It Was Promised appeared first on Make: DIY Projects and Ideas for Makers.
What’s the difference between a commercial and a literary plot? Discover how story goals, character journeys, and endings shape your novel.
There aren’t many authors (who actually sell books) who can get away without plotting. Bestselling authors, like Stephen King, who say they don’t plot, don’t realise they actually do it without realising it. They have an innate plotting talent. They just need less help than the rest of us.
I have noticed that even talented literary authors, who obviously don’t plot, have a shorter shelf life and fewer readers than writers who do plot.
My greatest wish as a reader is that more literary writers would learn to plot. Can you imagine the incredible books we would have to read? Some literary authors do this. Kate Atkinson writes beautifully, and her books have plots.
The bottom line? There are fewer book sales and the author makes less money, unless they win a literary prize.
The bottom line?More of these books are sold and the author makes more money. There is next to no chance of winning a literary prize.
I think the way forward for modern writers is to marry the two.
You don’t have to choose between a commercial and a literary plot. You can use the strengths of both to tell a better story. Give your characters clear goals and obstacles to overcome, but also explore their inner lives, relationships, and motivations. Build a plot that keeps readers interested, and give them characters who stay with them long after they finish reading.
The best of both worlds may be the way forward. Give your characters clear goals, build in setbacks, and create complex characters whose journeys keep readers turning the pages. Happy writing.

by Amanda Patterson
© Amanda Patterson
Top Tip: Sign up for our free daily writing links.
The post What’s The Difference Between A Commercial And A Literary Plot? appeared first on Writers Write.

Teach a robot to balance, using reinforcement learning in simulation just like the big labs.
The post Train a Balance Bot With Reinforcement Learning appeared first on Make: DIY Projects and Ideas for Makers.