# Hello, AI Agents! What They Are & Why You Should Build One

If you've been watching the AI space from the sidelines and thinking, “This all looks interesting, but where does a **C# developer even begin**?”, you’re not alone. Most of us started there.  
AI agents seem complicated until you actually build one — and then suddenly the whole idea becomes surprisingly straightforward.

This first post in the series is all about getting that initial win. You’ll build a small .NET 8 console application that talks to an AI agent using the **Microsoft Agent Framework** and the **OpenAI .NET SDK**. No ML background required. No giant architecture diagrams. Just code, clarity, and an agent that responds to your questions.

Let’s get something working.

Note : This blogpost is part of the [AI Agent learning series](https://blogs.codingfreaks.net/building-ai-agents) here.

* * *

## **What You'll Build Today**

By the end of this post, you’ll have a functioning AI agent that:

*   Reads instructions you define
    
*   Accepts a question
    
*   Calls an AI model
    
*   Produces a clean, human-readable response
    

Visually, the flow looks like this:

```plaintext
You → Agent → Model → Response
```

And yes — you can build this in **under 50 lines of code**.

* * *

## **Before You Begin**

You’ll need:

*   .NET 8 installed
    
*   A terminal
    
*   An OpenAI-compatible API key
    
*   Basic C# familiarity
    

If you’ve built a console app before, you’re ready.

* * *

# **Building Your First AI Agent**

Let’s walk through the entire process step-by-step.

* * *

## **1\. Create the Project**

```csharp
dotnet new console -n AgentWorkshop
cd AgentWorkshop
```

## **2\. Add the Required Packages**

Install the OpenAI SDK and Microsoft Agent Framework extensions:

```csharp
dotnet add package OpenAI
dotnet add package Microsoft.Agents.AI.OpenAI --prerelease
```

The first package is your API client.  
The second transforms a model into an agent with instructions and behavior.

* * *

## **3\. Write the Agent Code**

Below is the full `Program.cs` for this first post. It’s simple by design, but shows the core pattern used throughout the series.

```csharp
// Program.cs — "Hello, AI Agents!"
// A straightforward introduction to the Microsoft Agent Framework in .NET 8.

using System;
using System.Threading.Tasks;
using OpenAI; // Official OpenAI SDK used by the agent extensions

internal class Program
{
    private static async Task Main(string[] args)
    {
        

        // 1. Add your API key.
        // For local experiments and simplicity let's define the API key here
        const string apiKey = "sk-proj-API";

        if (apiKey.Contains("YOUR_API_KEY_HERE"))
        {
            Console.WriteLine("Please insert your API key before running the application.");
            return;
        }

        // 2. Create an OpenAI client.
        // This client communicates with the model.
        var client = new OpenAIClient(apiKey);

        // 3. Wrap the model as an AI agent.
        // "gpt-4o-mini" is a compact, fast model suitable for simple tasks.
#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
        var agent = client
            .GetOpenAIResponseClient("gpt-4o-mini")
            .CreateAIAgent(
                name: "HelloAgent",
                instructions:
                    "You are a clear, friendly assistant who explains AI agents " +
                    "to developers without assuming prior AI knowledge."
            );
#pragma warning restore OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

        Console.WriteLine("Ask your AI agent a question (or press Enter for a default prompt):");
        Console.Write("> ");
        var question = Console.ReadLine();

        // Provide a fallback question for convenience.
        if (string.IsNullOrWhiteSpace(question))
        {
            question = "Give me a simple explanation of what an AI agent is.";
        }

        Console.WriteLine("\nProcessing your request...\n");

        // 4. Execute the agent request.
        var response = await agent.RunAsync(question);

        // 5. Display the result.
        Console.WriteLine("=== Agent Response ===");
        Console.WriteLine(response);

        Console.WriteLine("\nComplete. You've just created your first AI agent in C#.");
    }
}
```

Run it:

```csharp
dotnet run
```

You’ll see a prompt, enter your question, and the agent will produce a response that follows the instructions you gave it. That “instruction layer” is one of the most powerful parts of building agents — and something we’ll explore more as the series continues.

* * *

# **Try It Yourself**

Once the basic agent is working, experiment a little to build intuition.

### **1\. Adjust the agent’s behavior**

Change the instructions:

```plaintext
instructions: "Explain everything like you're mentoring a new developer."
```

Run it again — notice the shift in tone.

### **2\. Ask a deeper question**

Try something more contextual:

```plaintext
> When should a team consider using an AI agent instead of a traditional API?
```

Now you have a lightweight agent shell running locally.

### **Source code :**

You can find the entire [source code](https://github.com/muralidharand/ai-agents-for-beginners/tree/main/HelloAgent/AgentWorkshop) here for this blogpost.

# **What You Learned Today**

By completing this first post, you now understand:

*   What an AI agent fundamentally is
    
*   How the Microsoft Agent Framework wraps model calls into a structured “agent” pattern
    
*   How to configure the agent’s behavior using simple instructions
    
*   How to build and run a minimal agent in a .NET 8 console app
    

This foundation will make the next steps feel much more natural.

# **Next Up: “Zero to Agent in 30 Minutes: Your Foundry Setup”**

In the [next post](https://blogs.codingfreaks.net/zero-to-agent), we’ll clean up this initial project, move configuration out of the code, and prepare your environment for a full-featured agent workflow.
