Skip to content

Add C# ChatModelRouterMultiturn demo using Microsoft.Extensions.AI#83

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/transform-python-to-csharp
Draft

Add C# ChatModelRouterMultiturn demo using Microsoft.Extensions.AI#83
Copilot wants to merge 3 commits intomasterfrom
copilot/transform-python-to-csharp

Conversation

Copy link
Contributor

Copilot AI commented Nov 24, 2025

Ports the Python chat-model-router-multiturn.py demo to C# following the existing agent runner pattern in extensions-ai.

Changes

ChatModelRouterMultiturn.cs (new)

  • Interactive multi-turn chat with model router showing which model handled each request
  • History trimming: preserves system message + last N user/assistant pairs
  • Uses Microsoft.Extensions.AI.ChatMessage alias to resolve OpenAI namespace conflict
  • Configurable via appsettings.json with safe defaults

Program.cs

  • Added option 3 for ChatModelRouterMultiturn
  • Configuration parsing with TryParse and null-safe defaults

appsettings.json

  • Added ModelRouter and chat parameters as native JSON types

Usage

// From Program.cs
var modelRouterMultiturn = new ChatModelRouterMultiturn();
await modelRouterMultiturn.Run(
    modelRouter,      // "model-router" deployment
    endpoint, 
    systemPrompt,
    maxHistoryTurns,  // default: 12
    maxOutputTokens,  // default: 10000
    temperature,      // default: 0.7
    topP,             // default: 0.95
    frequencyPenalty, 
    presencePenalty);

The implementation maintains functional parity with the Python version while using Microsoft.Extensions.AI abstractions consistent with other demos in the project.

Original prompt

This section details on the original issue you should resolve

<issue_title>C# Model Router Multiturn</issue_title>
<issue_description>demos\01-essentials\01-foundry\02-sdks\foundry-sdk-py\chat-model-router-multiturn.py contains a python implementation. I want to tranform this into c# in demos\01-essentials\01-foundry\02-sdks\extensions-ai

Keep the agent runner pattern</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 24, 2025 10:01
Co-authored-by: alexander-kastil <16348023+alexander-kastil@users.noreply.github.com>
Co-authored-by: alexander-kastil <16348023+alexander-kastil@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert Python Model Router Multiturn to C# Add C# ChatModelRouterMultiturn demo using Microsoft.Extensions.AI Nov 24, 2025
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.

C# Model Router Multiturn

2 participants