Give Your LLM Vibe Coding Superpowers with .NET 10 ⚡️

Monday, June 23, 2025

Discover how to supercharge your Large Language Models by combining .NET 10's new single-file scripting with tool-calling AI agents to write and execute C# code like a true vibe coder. Let's dive into building your own AI coding sidekick!

🚀 Give Your LLM Vibe Coding Superpowers with .NET 10

Hey coder friend, have you ever wished your AI assistant could do more than just chat? Like actually whip up and run live C# code on demand? Well, buckle up, because with the magic combo of .NET 10’s single-file scripting, Large Language Models (LLMs), and tool-calling capabilities, you’re about to unlock some serious vibe coding superpowers. 🦸‍♂️

🧙‍♂️ What Is “Vibe Coding” Anyway?

If you’re scratching your head over the term, fear not! ChatGPT breaks it down perfectly:

“Vibe coding with AI is like whispering your app dreams to a super-fast coder who never sleeps—you describe what you want (‘make the button red,’ ‘add cat purring’), and the AI writes it. You review, tweak, rinse, repeat… no need to grok every line. It’s part brainstorming session, part code genie — fast, fun, and sometimes buggy magic! 😜”

In short? It’s an AI-powered coding session that’s more about flow and creativity than manual typing. And thanks to .NET 10, the AI can now jump beyond code writing — it can actually run what it pens out! 🎉


🔧 The Ingredients for Your AI-Powered Coding Agent

  1. LLMs capable of tool calling — This lets the AI not just spout code but decide when to actually execute it or fetch real-world data.
  2. .NET 10 single-file scripts — Say goodbye to bulky boilerplate. Now you can run a entire C# script with a simple dotnet run app.cs command.
  3. Microsoft.Extensions.AI libraries — These gems make setting up chat clients with tool invocation (like executing code) a breeze.

Put them together, and you'll have an AI agent that writes, debugs, and runs C# code — iteratively improving with each feedback loop.

Fun fact: Microsoft’s Model Context Protocol (MCP) is making tool-aware LLMs more accessible than ever. Check out MCP if you’re curious!


⚙️ Setting the Stage: Building the Bot

First off, you’ll need to bring in several NuGet packages such as Azure.AI.OpenAI, Microsoft.Extensions.AI, and the new preview packages for logging and AI with .NET 10. The code snippet below sets up your chat client pointing to your Azure OpenAI endpoint (but you can swap in any model that supports tool calling):

using Azure.AI.OpenAI;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Logging;

var runId = Guid.NewGuid();
var azureOpenAIEndpoint = "https://<your-endpoint>.cognitiveservices.azure.com/";
var azureOpenAIModelId = "gpt-4.1";

using var loggerFactory = LoggerFactory.Create(builder =>
    builder.SetMinimumLevel(LogLevel.Information)
           .AddConsole());

var client = new ChatClientBuilder(
        new AzureOpenAIClient(new Uri(azureOpenAIEndpoint), new ApiKeyCredential("<your-api-key>"))
            .GetChatClient(azureOpenAIModelId).AsIChatClient())
    .UseLogging(loggerFactory)
    .UseFunctionInvocation(loggerFactory)
    .Build();

Just swap in your API key and endpoint, and you’re set to roll.


🛠️ Giving Your LLM Code-Execution Superpowers

Writing code is cool, but executing it? Next level. The trick here is to create a "tool" that the LLM can invoke to run C# scripts on the fly. Here's how:

  • Receive code as a string
  • Save it to a temporary .cs file
  • Run it using dotnet run file.cs
  • Capture and return the output so the LLM learns and adapts if errors crop up
var chatOptions = new ChatOptions
{
    Tools = [AIFunctionFactory.Create((string code) =>
    {
        var logger = loggerFactory.CreateLogger("CodeExecution");
        var codeFileName = $"c:\temp\{DateTime.Now:HHmmssfff}-{runId}.cs";
        File.WriteAllText(codeFileName, code);

        var process = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "dotnet",
                Arguments = $"run {codeFileName}",
                RedirectStandardOutput = true
            }
        };

        process.Start();
        process.WaitForExit(TimeSpan.FromMinutes(1));

        var output = process.StandardOutput.ReadToEnd();
        logger.LogInformation("Code execution output: {Output}", output);

        return output;
    },
    description: "Execute the provided code.")]
};

What this bot is really doing is running your script for real and feeding back the results. If your code has bugs (spoiler: it probably will at first), the AI sees that and tries again.

💡 Pro Tip: Adding logging lets you peek behind the curtain and understand what the AI is trying at each step.


🤖 Prompt Engineering: Training Your AI Sidekick

No magic without instructions. You’ll feed the LLM a detailed system prompt telling it exactly how you want it to write and execute code. Since .NET 10 supports referencing NuGet packages in single-file scripts, you need to tell the model how to specify these packages. Otherwise, it defaults to old-school .Main() methods and misses out on package referencing.

Here’s a peek at the system prompt guiding the AI’s vibe coding:

Write code to answer the question.

If you need to use a NuGet package, specify it like this:
#:package PackageName.Some

Examples:
#:package [email protected]
#:package SemanticKernel
#:package Newtonsoft.Json

Your code block should start with required package references, followed by any using statements, then the actual code.
You can write code statements directly without wrapping in a Program class.

Write and execute code to answer the question without asking the user for input or clarification.

Then you define the user prompt, for example:

1. Fetch the CSV file from 'https://raw.githubusercontent.com/fgeorges/star-wars-dataset/refs/heads/master/csv/films/films.csv'
2. Analyze the delimiter used.
3. Determine the CSV columns and their data.
4. Order movies by release date, newest first.
5. Write a .docx document at 'c:\temp\star_wars_movie.docx' with one line per page showing release date, title, and description.

🎯 Without such clear hand-holding via prompt design, your AI might just write old-school boilerplate and miss the whole point.


🧪 Putting It All Together: Run Your Vibe Coding Agent

Invoke the model with your prepared chat history and options:

var result = await client.GetResponseAsync(history, chatOptions);
Console.WriteLine($"LLM response: {result}");

If all sails correctly, the AI:

  • Writes and runs the code
  • Detects errors if any, adjusts code
  • Eventually produces the desired output, e.g., a .docx file summarizing the Star Wars movies

You can find the full sample code gist here for your inner tinkerer.


🔍 Reviewing The Performance: What To Expect

The AI might take multiple shots at getting it right — because, yes, AI code can be messy sometimes. But that's part of the charm. Each iteration is smarter, factoring in compile-time and runtime errors.

The last time the author ran it, here’s what the AI produced:

  • It correctly identified the CSV delimiter as a comma.
  • Listed all the columns in the dataset (title, episode_id, opening crawl, director, etc).
  • Generated a .docx file (c:/temp/star_wars_movie.docx) with each movie ordered newest first, one per page, showing release date, title, and description.

Want to see the full journey and output? It’s all here on OneDrive.


⚠️ A Cautionary Tale: Security First!

Before you get too excited and let your AI run rogue code everywhere, remember: always sandbox this stuff. There is zero guarantee that the code AI generates won't have malicious or buggy parts — so, run it isolated and never on your main system.

Safety first, fun second!


💭 Final Thoughts & Your Take?

So, what's the verdict? The technology is promising but still a bit rough around the edges. Some models want your permission every step; others ignore execution tools completely. Prompt engineering is your best friend here.

Inspired by projects like AutoGen for .NET, .NET 10 is lowering the barrier to build coding agents with real power.

What do YOU think? Is this the future of coding, or just a fun experiment? Drop your thoughts and let's spark a convo! 👇


📚 Resources & Links


Happy vibe coding, my friend! 😄


Written by Peter Bons, a passionate Software Architect and C# lover from the Netherlands.