Skip to content

Add Microsoft Agent Framework (Microsoft.Agents.AI) with RAG Example - #1423

Open
zsogitbe wants to merge 2 commits into
SciSharp:masterfrom
zsogitbe:MicrosoftAgentFrameworkExample
Open

Add Microsoft Agent Framework (Microsoft.Agents.AI) with RAG Example#1423
zsogitbe wants to merge 2 commits into
SciSharp:masterfrom
zsogitbe:MicrosoftAgentFrameworkExample

Conversation

@zsogitbe

Copy link
Copy Markdown
Contributor

Overview

This PR introduces a new example to LLama.Examples demonstrating how to integrate LLamaSharp with the Microsoft Agent Framework (Microsoft.Agents.AI), Microsoft's AI abstractions (Microsoft.Extensions.AI), and vector data storage (Microsoft.Extensions.VectorData). Since we are removing Semantic Kernel, we need an agentic example.

Motivation & Context

With Microsoft's release of the unified Microsoft.Extensions.AI abstractions and the Microsoft.Agents.AI framework, many .NET developers are looking for concrete reference implementations to run fully local, offline agents using open-weights GGUF models.

This example bridges that gap by demonstrating:

  1. How to wrap LLamaSharp's StatelessExecutor into Microsoft's IChatClient using AsChatClient().
  2. How to generate local text embeddings using LLamaEmbedder.
  3. How to implement Deterministic RAG (Retrieval-Augmented Generation) to achieve consistent, hallucination-free outputs when working with fast, local Small Language Models (SLMs under 8B parameters).

Key Highlights

  • Zero Disk Footprint: Utilizes an in-memory SQLite vector database (Data Source=:memory:) via CommunityToolkit.VectorData.SqliteVec, ensuring no temporary database files clutter the user's disk upon exit.
  • Dual Model Usage: Demonstrates coordinating a dedicated embedding model (e.g., Qwen3/MiniLM) alongside a chat instruction model (e.g., Llama-3.2-3B).
  • Strict Agent Persona: Showcases how to pass ChatClientAgentRunOptions with zero temperature (0.0f) to lock agent responses strictly to math-verified retrieved facts.

Changes Included

  • Added LLama.Examples/Examples/MicrosoftAgentFrameworkExample.cs containing the end-to-end RAG and Agent workflow.
  • Registered the example in the console selection menu.
  • Added the required abstractions to LLama.Examples.csproj (Microsoft.Agents.AI, Microsoft.Extensions.AI, and CommunityToolkit.VectorData.SqliteVec).

How Has This Been Tested?

  • OS: Windows 11

  • Models Tested:

  • Chat: Llama-3.2-3B-Instruct-Q4_K_M.gguf

  • Embedding: Qwen3-Embedding-0.6B-Q8_0.gguf (1024 dimensions)

  • Verification: Verified that vector similarity search executes in-memory and the agent generates factual summaries based exclusively on the seeded dummy records without hallucinating outside context.


Checklist

  • Code follows the existing formatting and conventions of the repository.
  • Includes standard interactive console prompts for user model paths.
  • No lingering files or side effects left on the local system after execution (:memory: database used).

@martindevans

Copy link
Copy Markdown
Member

Very cool, thanks for adding this! There's a merge conflict, but other than that it looks good to go 馃憤

@martindevans
martindevans requested a lite review from Copilot August 23, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new LLama.Examples console example demonstrating LLamaSharp integration with Microsoft鈥檚 Agent Framework / Microsoft.Extensions.AI abstractions, including an in-memory SQLite vector store flow to showcase a deterministic RAG pattern.

Changes:

  • Added a new MicrosoftAgentFrameworkExample showing embedding + vector search + constrained agent response generation.
  • Extended UserSettings to support prompting/saving a separate embedding-model path.
  • Registered the new example in the interactive menu and added new package references to the examples project.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
LLama.Examples/UserSettings.cs Adds persisted prompt support for an embedding model path.
LLama.Examples/LLama.Examples.csproj Adds new package dependencies for Agent Framework / AI abstractions / SQLite vector store.
LLama.Examples/Examples/MicrosoftAgentFrameworkExample.cs New end-to-end deterministic RAG + agent example using LLamaSharp + Microsoft abstractions.
LLama.Examples/ExampleRunner.cs Registers the new example in the console selection menu.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread LLama.Examples/ExampleRunner.cs Outdated
{ "LLama Model: Get embeddings", GetEmbeddings.Run },
{ "LLama Model: Quantize", QuantizeModel.Run },
{ "Grammar: Constrain response to json format", GrammarJsonResponse.Run },
{ "Microsoft Agent Framework Example", MicrosoftAgentFrameworkExample.Run},
Comment thread LLama.Examples/Examples/MicrosoftAgentFrameworkExample.cs
@zsogitbe

Copy link
Copy Markdown
Contributor Author

Very cool, thanks for adding this! There's a merge conflict, but other than that it looks good to go 馃憤

Thanks Martin! I think that this merge conflict has something to do with your PR. Can you resolve it, or do I need to do something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants