Applied AIJun 28, 2026·15 min
Building a coding agent with the OpenAI SDK and .NET
Thinking, reading, editing, grepping — orchestrating an agent’s stages in C#.
LS
Luis Soares
Software architect — .NET · Azure · AI
[ Applied AI ]
Coding agents aren’t one giant prompt. They’re a loop with tools: think, read files, edit slices, search the repo, and repeat until the task is done.
The minimal pipeline
A useful .NET agent usually exposes four capabilities:
- —Plan — break the request into verifiable steps.
- —Read — load only relevant files (avoid context dumps).
- —Edit — small, reviewable patches—not full rewrites.
- —Grep — semantic or text search to find symbols and usages.
csharp
public interface ICodingAgentStep
{
Task<AgentObservation> RunAsync(AgentState state, CancellationToken ct);
}Orchestration in C#
With the OpenAI SDK (or another provider), keep state outside the model: step history, pending diffs, and stop criteria. The LLM suggests the next action; your code validates and executes.
When the agent fails, prefer fixing the loop (better observation, scope limits) over growing the prompt.
LS
Written by Luis Soares — software architect, on the road to Microsoft MVP.