The recent release of Microsoft’s Semantic Kernel Agents Framework RC1 provides an excellent opportunity to explore its capabilities with C#. In this post, we’ll walk through creating a simple agent using this framework and running it locally with Ollama.
Let’s dive in!
Introduction
AI agents are autonomous systems designed to perform tasks by analyzing their environment and making informed decisions. These agents harness the power of Large Language Models (LLMs) or Small Language Models (SLMs) to understand natural language and seamlessly interact with various tools, including APIs, databases, and other agents.
The true power of AI agents lies in their ability to learn and adapt through feedback mechanisms. They generally fall into two categories: non-agentic chatbots for handling straightforward, immediate tasks, and agentic chatbots capable of managing complex, multi-step operations with memory and reasoning capabilities.
In this post, we’ll focus on building a non-agentic agent using Microsoft’s Semantic Kernel framework and running it locally with Ollama.
Setting Up Your Environment
Before we begin, you’ll need to:
- Install Ollama to manage the SLM and handle the integration
- Download the Phi-4 SLM model to your machine using:
ollama pull phi4:latest
Creating the Simplest Non-agentic Agent
With Ollama and the Phi-4 model in place, let’s create a basic console application.
1 | dotnet new console -n SKOllamaAgent |
Next, add the Semantic Kernel nuget packages to your project using
1 | dotnet add package Microsoft.SemanticKernel |
Let’s create the simplest non-agentic agent using the Semantic Kernel by updating the created Program.cs
file with
1 | var builder = Kernel.CreateBuilder(); |
Impressive, right? We have created a simple agent that can answer questions about C# and .NET in just a few lines of code.
Running the Agent
To see your agent in action, execute this command in your terminal:
1 | dotnet run |
You should now see the agent’s response to your question about the differences between classes and records in C#. Here’s the response I received:
Conclusion
We’ve demonstrated how to create a straightforward non-agentic agent using the Semantic Kernel Agents Framework and run it locally with Ollama. While this example shows the basics, you can enhance this agent’s capabilities by adding more sophisticated instructions and connecting it with various tools and services.
Stay tuned for upcoming posts where we’ll explore more advanced features and implementations.
References
Get the source code on GitHub laurentkempe/aiPlayground/SKOllamaAgent