ai software technology

Unleashing Autonomous AI: Building Intelligent Agents with .NET 9, Semantic Kernel, and Azure

Explore how to develop advanced autonomous AI agents leveraging the power of .NET 9, Microsoft's Semantic Kernel, and the robust capabilities of Azure. Learn to create intelligent systems capable of independent decision-making and task execution.

Author

AmethiSoft AI Team

Published

March 27, 2026

Read Time

11 min read
Developing Autonomous AI Agents with .NET 9 and Semantic Kernel on Azure

Introduction: The Dawn of Autonomous AI Agents

The landscape of artificial intelligence is rapidly evolving, moving beyond simple conversational interfaces to embrace the development of truly autonomous agents. These intelligent systems are designed not just to respond, but to reason, plan, and execute complex tasks independently, adapting to dynamic environments and learning from their interactions. This shift marks a profound transformation in how we approach software development, enabling unprecedented levels of automation and problem-solving capabilities.

For developers and organizations aiming to harness this power, the combination of .NET 9, Microsoftโ€™s Semantic Kernel, and Azure presents a compelling and robust ecosystem. This stack offers the performance, extensibility, and cloud scalability necessary to build, deploy, and manage sophisticated autonomous AI agents effectively. In this article, weโ€™ll dive deep into how these technologies coalesce to empower the next generation of intelligent applications.

Core Explanation: Deep Dive into Autonomous AI Agent Development

Autonomous AI agents are software entities that can perceive their environment, make decisions, and take actions to achieve specific goals without constant human intervention. Key characteristics include goal-oriented behavior, self-correction, memory, and the ability to interact with external tools and services.

Understanding the Pillars of Agentic AI

Developing such agents requires a framework that can orchestrate interactions between large language models (LLMs), external tools, and long-term memory. This is where Semantic Kernel shines.

Semantic Kernel: The Orchestrator for Intelligent Agents

Semantic Kernel (SK) is an open-source SDK from Microsoft that enables developers to easily combine Large Language Models (LLMs) with conventional programming languages like C#. It acts as an orchestrator, allowing you to create โ€œskillsโ€ (functions) that LLMs can invoke, manage memory, and compose complex โ€œplansโ€ to achieve user goals.

The core concepts within Semantic Kernel include:

  • Skills: Collections of native functions (your C# code) and semantic functions (prompts for LLMs). These are the building blocks of an agentโ€™s capabilities, allowing it to perform actions, query databases, or call APIs.
  • Planners: Algorithms that take a userโ€™s goal and available skills, then generate a sequence of steps (a plan) for the agent to execute. This is where the โ€œautonomyโ€ really kicks in, as the planner dynamically determines the best course of action.
  • Memories: Mechanisms for agents to store and retrieve information, providing context for ongoing tasks or learning from past interactions. This can involve vector databases for semantic recall or simple key-value stores.
  • Connectors: Integrations with various AI services (like Azure OpenAI, OpenAI, Hugging Face) and other external systems.

.NET 9: A Performance-Driven Foundation

.NET 9, building on the strong foundations of its predecessors, offers significant enhancements that are particularly beneficial for AI development:

  • Performance Improvements: Continued focus on raw performance, garbage collection, and JIT compilation means faster execution of complex AI workloads and lower latency for agent responses.
  • Native AOT Maturation: The advancements in Native Ahead-Of-Time (AOT) compilation reduce application startup times and memory footprint, making it ideal for deploying efficient, high-performance agents in serverless or containerized environments.
  • New Libraries and APIs: Anticipated additions and improvements to core libraries, especially in areas like numerical computation, vector operations, and asynchronous programming, directly support the demanding requirements of AI applications.
  • Enhanced Tooling: Improved developer experience with Visual Studio and VS Code, streamlining the development, debugging, and deployment of complex agent systems.

Azure: The Scalable and Secure Cloud Backbone

Azure provides the essential infrastructure and services to host, scale, and secure your autonomous AI agents:

  • Azure OpenAI Service: Offers access to powerful LLMs (like GPT-4) within a secure, enterprise-grade environment, with features for fine-tuning and content filtering. This is critical for empowering your agents with advanced reasoning capabilities.
  • Azure AI Search: A robust solution for implementing agent memory, allowing for efficient semantic search and retrieval of vast amounts of information, crucial for agents that need to operate with extensive knowledge bases.
  • Azure Functions & Azure Container Apps: Ideal for deploying agent components as serverless functions or microservices, offering automatic scaling, cost efficiency, and simplified management.
  • Azure Monitor & Application Insights: Provides comprehensive monitoring, logging, and diagnostics, essential for observing agent behavior, troubleshooting, and ensuring reliability in production.
  • Azure Cosmos DB & SQL Database: Scalable data stores for agent state, configurations, and transactional data.

Practical Section: Building a Simple .NET 9 Agent with Semantic Kernel

Letโ€™s illustrate how to create a basic autonomous agent skill using Semantic Kernel in a .NET 9 application. This example will show a simple โ€œemail draftingโ€ skill that the agent can utilize.

First, ensure you have the necessary Semantic Kernel NuGet packages installed:

// In your .NET 9 project file (.csproj)
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.SemanticKernel" Version="1.x.x" />
    <PackageReference Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.x.x" />
    <!-- Replace 1.x.x with the actual latest stable versions -->
  </ItemGroup>

</Project>

Remember to replace 1.x.x with the actual latest stable versions of Semantic Kernel packages.

Next, weโ€™ll set up our Kernel and import a simple prompt-based skill. This skill will draft an email based on a topic and recipient provided.

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.PromptTemplates.Handlebars;

public class EmailAgent
{
    private readonly IKernelBuilder _kernelBuilder;
    private readonly Kernel _kernel;

    public EmailAgent(string azureOpenAiDeploymentName, string azureOpenAiEndpoint, string azureOpenAiApiKey)
    {
        _kernelBuilder = Kernel.CreateBuilder()
            .AddAzureOpenAIChatCompletion(
                deploymentName: azureOpenAiDeploymentName,
                endpoint: azureOpenAiEndpoint,
                apiKey: azureOpenAiApiKey
            );
        // You could also add other services like Memory here
        _kernel = _kernelBuilder.Build();
    }

    public async Task DraftEmail(string recipient, string topic)
    {
        Console.WriteLine($"\n--- Agent is drafting an email for {recipient} about {topic} ---");

        // Define a semantic function (prompt) for drafting an email
        var emailDraftingPrompt = """
            You are an AI assistant that drafts professional emails.
            Draft a concise and polite email for {{recipient}} about the following topic: "{{topic}}".
            Ensure the tone is professional and friendly.
            """;

        var emailSkill = _kernel.CreateFunctionFromPrompt(
            emailDraftingPrompt,
            new HandlebarsPromptTemplateFactory()
        );

        // Execute the skill
        var result = await _kernel.InvokeAsync(
            emailSkill,
            new KernelArguments { { "recipient", recipient }, { "topic", topic } }
        );

        Console.WriteLine($"\n--- Email Draft for {recipient} ---");
        Console.WriteLine(result.GetValue<string>());
        Console.WriteLine("----------------------------------\n");
    }
}

In this code block, we initialize the Kernel with an Azure OpenAI connector. We then define a prompt for an email drafting skill using Handlebars templating. This makes the prompt dynamic and easily modifiable. The DraftEmail method then invokes this skill with specific arguments.

Now, letโ€™s consider a scenario where the agent needs to plan its actions. Semantic Kernelโ€™s Planner can analyze a user goal and available skills to create a step-by-step execution plan.

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.PromptTemplates.Handlebars;
using System.ComponentModel;

public class AgentWithPlanning
{
    private readonly Kernel _kernel;

    public AgentWithPlanning(string azureOpenAiDeploymentName, string azureOpenAiEndpoint, string azureOpenAiApiKey)
    {
        _kernel = Kernel.CreateBuilder()
            .AddAzureOpenAIChatCompletion(
                deploymentName: azureOpenAiDeploymentName,
                endpoint: azureOpenAiEndpoint,
                apiKey: azureOpenAiApiKey
            )
            .Build();

        // Import the email drafting skill as part of a "Mail" plugin/skill collection
        _kernel.ImportPluginFromObject(new MailSkill(), "Mail");
    }

    public async Task ExecutePlan(string goal)
    {
        Console.WriteLine($"\n--- Agent received goal: '{goal}' ---");

        // Create a planner
        var planner = new FunctionCallingStepwisePlanner(new FunctionCallingStepwisePlannerOptions());

        // Execute the plan
        var result = await _kernel.InvokeAsync(planner, new KernelArguments { ["goal"] = goal });

        Console.WriteLine($"\n--- Agent completed goal. Final Result: ---");
        Console.WriteLine(result.GetValue<string>());
        Console.WriteLine("------------------------------------------\n");
    }
}

// Define a simple skill that can be used by the planner
public class MailSkill
{
    [KernelFunction, Description("Drafts a professional email.")]
    public string DraftEmail(
        [Description("The recipient of the email.")] string recipient,
        [Description("The topic of the email.")] string topic
    )
    {
        // In a real scenario, this would interact with an email service
        // For demonstration, we just return a simulated draft.
        return $"Simulated Email Draft for {recipient} on topic '{topic}':\n\n" +
               $"Subject: Regarding {topic}\n\n" +
               $"Dear {recipient},\n\n" +
               $"I hope this email finds you well. I am writing to discuss {topic}...\n\n" +
               $"Best regards,\n" +
               $"AmethiSoft Agent";
    }

    [KernelFunction, Description("Sends an email.")]
    public string SendEmail(
        [Description("The recipient of the email.")] string recipient,
        [Description("The subject of the email.")] string subject,
        [Description("The body of the email.")] string body
    )
    {
        // In a real scenario, this would interact with an email service
        Console.WriteLine($"\n--- Agent is sending an email to {recipient} with subject '{subject}' ---");
        Console.WriteLine($"\nEmail Body:\n{body}");
        return $"Email sent successfully to {recipient}.";
    }
}

Here, we define MailSkill with DraftEmail and SendEmail methods, marked with KernelFunction and Description attributes, making them discoverable by the planner. The AgentWithPlanning class then uses a FunctionCallingStepwisePlanner to interpret a userโ€™s goal and decide which skills from the MailSkill (or any other imported plugin) to invoke and in what order. This demonstrates a basic form of agent autonomy, where the agent determines its own steps to achieve a goal.

Finally, in your Program.cs, you can instantiate and run these agents:

public class Program
{
    public static async Task Main(string[] args)
    {
        // Replace with your actual Azure OpenAI details
        const string AzureOpenAiDeploymentName = "your-deployment-name";
        const string AzureOpenAiEndpoint = "https://your-resource-name.openai.azure.com/";
        const string AzureOpenAiApiKey = "your-api-key";

        if (string.IsNullOrEmpty(AzureOpenAiApiKey) || AzureOpenAiApiKey == "your-api-key")
        {
            Console.WriteLine("Please configure your Azure OpenAI API key, endpoint, and deployment name.");
            return;
        }

        // --- Demonstrate a direct skill invocation ---
        var emailAgent = new EmailAgent(AzureOpenAiDeploymentName, AzureOpenAiEndpoint, AzureOpenAiApiKey);
        await emailAgent.DraftEmail("[email protected]", "quarterly project review meeting");

        // --- Demonstrate an agent with planning capabilities ---
        var planningAgent = new AgentWithPlanning(AzureOpenAiDeploymentName, AzureOpenAiEndpoint, AzureOpenAiApiKey);
        await planningAgent.ExecutePlan("Draft a follow-up email to Alice about the Q3 sales report and then send it.");

        Console.WriteLine("\nAutonomous agent demonstration complete.");
    }
}

This Main method orchestrates the execution, first showing a direct skill call, then demonstrating how a planner can interpret a complex goal and use the available skills to achieve it, simulating autonomous behavior.

Real-World Application and Business Value

The convergence of .NET 9, Semantic Kernel, and Azure opens up a myriad of opportunities for businesses and developers.

Developer Perspective

  • Leverage Existing Skills: .NET developers can seamlessly integrate cutting-edge AI capabilities into their applications without needing to pivot to entirely new language stacks. Semantic Kernel allows C# developers to define and orchestrate AI logic using familiar paradigms.
  • Rapid Prototyping and Iteration: The modular nature of Semantic Kernel skills and the robust tooling in .NET enable faster development cycles for agent-based systems.
  • Performance and Scalability: .NET 9โ€™s performance improvements, combined with Azureโ€™s hyperscale infrastructure, mean that agents can handle high loads and complex tasks efficiently and reliably.
  • Maintainability: By abstracting LLM interactions into structured skills, the codebase becomes more organized, testable, and maintainable.

Business Perspective

  • Enhanced Customer Experience: Autonomous agents can power advanced customer support chatbots, personalized marketing engines, and intelligent virtual assistants, offering 24/7 service and tailored interactions.
  • Operational Efficiency: Automate complex, multi-step workflows like data analysis, report generation, supply chain optimization, and resource management, freeing human capital for more strategic tasks.
  • Intelligent Data Processing: Agents can analyze vast datasets, identify trends, summarize information, and generate actionable insights much faster than traditional methods, aiding in strategic decision-making.
  • Innovation and New Product Development: Companies can build entirely new categories of products and services that leverage proactive, intelligent automation, driving competitive advantage.
  • Cost Reduction: By automating repetitive and time-consuming tasks, businesses can significantly reduce operational costs while improving accuracy and speed.

Future Outlook and Best Practices

The field of autonomous AI agents is still nascent but evolving rapidly. Looking ahead, we anticipate:

  • Advanced Planning and Reasoning: Planners will become more sophisticated, handling ambiguity better, learning from past failures, and performing more complex, multi-modal reasoning.
  • Multi-Agent Systems: Swarms of specialized agents collaborating to solve grander problems, mirroring human organizational structures.
  • Self-Improving Agents: Agents that can dynamically learn new skills or refine existing ones based on real-world interactions and feedback loops.
  • Enhanced Memory Architectures: More advanced persistent memory systems, allowing agents to retain context and learn over very long periods.

Best Practices for Development

  • Modular Design: Structure your agent into distinct, testable skills and plugins. This enhances reusability and maintainability.
  • Robust Error Handling and Observability: Implement comprehensive logging, monitoring (e.g., with Azure Application Insights), and graceful degradation to understand and manage agent behavior in production.
  • Human-in-the-Loop: For critical applications, design agents to allow for human oversight, intervention, and approval, especially for sensitive decisions or actions.
  • Ethical AI Principles: Prioritize fairness, transparency, accountability, and safety in agent design. Implement guardrails and content moderation (e.g., via Azure OpenAI features) to prevent harmful outputs.
  • Iterative Development: Start with simple agents and gradually add complexity. Test agent behavior extensively in controlled environments before deploying to production.
  • Context Management: Effectively manage the agentโ€™s memory and context to ensure relevant information is available to the LLM without exceeding token limits or causing hallucinations.

By embracing these technologies and best practices, AmethiSoft developers can lead the charge in building the next generation of intelligent, autonomous systems that will reshape industries and enhance human capabilities.

Disclaimer: This blog post was generated with the assistance of AI to provide recent technical insights. While we strive for accuracy, please verify critical technical details before using them in production or for legal decisions.

A

AmethiSoft AI Team

Insights Team at AmethiSoft

Share this:

AI Assistance Notice

This article was prepared with the assistance of Artificial Intelligence to provide timely and comprehensive technical insights. While our team reviews all content for relevance and accuracy, we recommend verifying critical technical details for your specific production environment. AmethiSoft is committed to transparency in AI usage.

WhatsApp Us
Email Us