A collection of C# samples that progressively demonstrate how to build AI agents using the GitHub Copilot SDK and Microsoft Agent Framework (MAF). The samples start with a minimal single-agent "hello world" and build toward real-world multi-agent architectures for line-of-business scenarios.
Building useful AI agents requires three things:
- An LLM backend — a model that understands natural language and can decide when to call tools
- An agent framework — abstractions for wiring tools, instructions, sessions, and multi-agent coordination
- Tool implementations — the actual business logic your agents can invoke
These samples wire those pieces together using:
| Layer | Technology | What it provides |
|---|---|---|
| LLM backend | GitHub Copilot SDK | CopilotClient — model access, auth via gh CLI, streaming, no API keys needed |
| Agent framework | Microsoft Agent Framework | AIAgent — tool dispatch, sessions, multi-agent patterns (agent-as-tool, workflows) |
| Tool primitives | Microsoft.Extensions.AI | AIFunction, AIFunctionFactory — wrap any C# method as a tool the LLM can call |
| Bridge | Microsoft.Agents.AI.GitHub.Copilot |
AsAIAgent() — connects CopilotClient to the MAF AIAgent abstraction |
The key architectural insight is that CopilotClient.AsAIAgent() produces a standard AIAgent instance. This means everything in the Microsoft Agent Framework ecosystem — multi-agent orchestration, workflows, agent-as-tool — works out of the box with GitHub Copilot as the LLM backend.
The samples are ordered as a learning path. Start with HelloWorldAgent to understand the fundamentals, then move to PortfolioAdvisor for multi-agent patterns.
1. HelloWorldAgent — Single agent with tools
Pattern: One agent, two tools, interactive REPL
The minimal starting point. A single AIAgent backed by CopilotClient with two simple tools (get_greeting and get_current_time). Teaches the fundamentals: tool registration via AIFunctionFactory, agent construction via AsAIAgent(), session management, and streaming responses.
User → GitHubCopilotAgent → [get_greeting, get_current_time] → response
You'll learn: How CopilotClient, AIAgent, AIFunction, and AgentSession fit together.
2. PortfolioAdvisor — Multi-agent with PowerShell tools
Pattern: Orchestrator agent delegates to a specialist sub-agent via AsAIFunction()
A portfolio advisor where the user-facing orchestrator delegates analysis tasks to a specialist sub-agent. The sub-agent's tools run in-process PowerShell pipelines (Import-Csv, Group-Object, Measure-Object) against mock portfolio data. Demonstrates the agent-as-tool pattern, multi-agent orchestration, and hosting the PowerShell runtime inside a .NET application via Microsoft.PowerShell.SDK.
User → OrchestratorAgent → AnalysisAgent.AsAIFunction()
│
└─ PowerShell tools (portfolio summary,
sector breakdown, top holdings)
You'll learn: How to build multiple agents with separate responsibilities, wire them together with AsAIFunction(), and leverage the PowerShell ecosystem as agent tooling.
An AI agent is a program that uses a large language model (LLM) to interpret natural-language input, decide what actions to take, and call tools (functions) to accomplish tasks. Unlike a simple chatbot that only generates text, an agent can do things — query databases, run calculations, call APIs, process files.
In Microsoft Agent Framework, an agent is represented by the AIAgent abstraction, which combines:
- Instructions (system prompt) — defines the agent's persona and behavior
- Tools (
AIFunction) — functions the LLM can call - Session (
AgentSession) — conversation history for multi-turn interactions
The agent-as-tool pattern lets one agent call another agent as if it were a regular tool. This is the foundation of multi-agent architectures:
- You build a specialist agent with its own tools and instructions
- You wrap it with
AsAIFunction()to produce anAIFunction - You give that function to an orchestrator agent as one of its tools
- The orchestrator's LLM decides when to delegate to the specialist
This creates a hierarchical architecture where each agent has a focused responsibility. The orchestrator doesn't need to know how the specialist does its work — it only knows what it can do (from the function description).
A single agent with 20+ tools creates problems:
- Tool selection degrades — the LLM has too many choices and picks the wrong one more often
- Instructions bloat — one system prompt tries to cover too many responsibilities
- Context overwhelm — the conversation fills with irrelevant tool results
Multi-agent solves this by giving each specialist a small, focused toolset and domain-specific instructions. The orchestrator only sees high-level specialist descriptions, not every individual tool.
The Microsoft.PowerShell.SDK NuGet package lets you run PowerShell Core inside your .NET process. Instead of shelling out with Process.Start("pwsh", ...), you create a PowerShell instance directly in C#:
using System.Management.Automation;
using var ps = PowerShell.Create();
ps.AddScript("Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 | ConvertTo-Json");
var results = ps.Invoke();This gives agent tools access to the entire PowerShell cmdlet and module ecosystem — CSV processing, Excel files, API calls, data transforms — without external dependencies or platform-specific process management. PowerShell Core is cross-platform (Windows, macOS, Linux).
All samples share the same prerequisites:
| Requirement | Details |
|---|---|
| .NET 8 SDK or later | dotnet --version |
| GitHub CLI | gh --version |
| GitHub Copilot subscription | Required for model access |
Authenticate the CLI before running any sample:
gh auth login# Clone the repo
git clone <repo-url>
cd maf-ghcpsdk-sample
# Start with the hello-world sample
cd HelloWorldAgent
dotnet run
# Then try the multi-agent sample
cd ../PortfolioAdvisor
dotnet runmaf-ghcpsdk-sample/
├── maf-ghcpsdk-sample.sln — Solution file (all samples)
├── README.md — This file
│
├── HelloWorldAgent/ — Sample 1: Single agent fundamentals
│ ├── HelloWorldAgent.csproj
│ ├── Program.cs — Agent wiring + REPL
│ ├── GreetingTools.cs — Pure C# tool implementations
│ └── README.md — Sample-specific documentation
│
└── PortfolioAdvisor/ — Sample 2: Multi-agent + PowerShell
├── PortfolioAdvisor.csproj
├── Program.cs — Orchestrator agent + REPL
├── AnalysisAgentFactory.cs — Sub-agent factory
├── PowerShellTools.cs — Tools using in-process PowerShell
├── data/holdings.csv — Mock portfolio data
└── README.md — Sample-specific documentation
Future samples may explore:
- Constraint solving — using Z3 (via
Microsoft.Z3) for portfolio optimisation, asset allocation, and tax-lot selection - Sequential workflows — chaining agents in a pipeline using
AgentWorkflowBuilder.BuildSequential() - Concurrent workflows — fan-out to multiple specialist agents using
AgentWorkflowBuilder.BuildConcurrent() - Charting and visualisation — generating charts with ScottPlot or MathNet.Numerics
- A2A protocol — hosting agents over HTTP with
MapA2A()for remote agent-to-agent communication
- Microsoft Agent Framework — multi-agent framework,
AIAgentabstraction, workflows - GitHub Copilot SDK — LLM backend,
CopilotClient, auth and streaming - Microsoft.Extensions.AI — shared AI abstractions for .NET
- Hosting PowerShell in .NET — background on in-process PowerShell
Note: The GitHub Copilot SDK and Microsoft Agent Framework packages are in preview and may have breaking changes.