Microsoft Agent Framework: C# setup, tools and RAG

Learn C# agent setup, tool calling, structured output and RAG through Azure examples, including a SQLite vector store and conversation sessions.

Player not loading? Watch on YouTube

Rasmus Wulff Jensen introduces Microsoft Agent Framework through a C# console example, then explains chat, tool calling, structured output and retrieval augmented generation (RAG). The setup uses an Azure endpoint, API credentials stored in user secrets, deployed models and two NuGet packages. He demonstrates a first response and streaming output. The packages are prerelease at the time of recording.

The provider discussion includes offline models, but the worked examples use Azure rather than a local LLM. Jensen explains that providers supporting IChatClient can share the agent execution code. Tool calling still requires support from the underlying model and provider.

Conversation sessions supply history for follow-up questions, with growing input token usage as the exchange continues. The tool examples wrap C# methods, connect to GitHub's MCP server and use middleware to inspect or cancel calls. Structured output maps responses to a defined C# class or record through JSON schema.

The RAG example combines Azure embeddings with a SQLite vector store. It ingests ten internal Q&A records, retrieves three relevant results and returns them through a search tool. Jensen also traces the requests behind a tool call to explain why instructions, schemas and repeated context contribute to token usage. Workflow execution is outside the tutorial's scope.