How to See Which Model Answered a Microsoft Agent Framework Agent Run in C#
A Microsoft Agent Framework agent's response has no property of its own that says which model answered. The model service's response does, and the agent keeps it in RawRepresentation. This post reads it from two agents on two Microsoft Foundry deployments, and the names that come back aren't the deployment names.
Syntax
AgentResponse <response> = await <agent>.RunAsync(<message>);
string? <modelId> = (<response>.RawRepresentation as ChatResponse)?.ModelId;
| Part | What it is |
|---|---|
<agent> | The agent you run, such as one you created with AsAIAgent. |
<message> | The question for the agent. |
<response> | The AgentResponse that RunAsync returns. |
RawRepresentation | The response the agent got from the layer under it, kept as an object. Agent Framework's reference: Gets or sets the raw representation of the run response from an underlying implementation. |
as ChatResponse | Treats that object as a ChatResponse, the chat response type of Microsoft.Extensions.AI, or gives null if it's something else. |
?.ModelId | Reads the model ID, or gives null when there's no ChatResponse. Its reference: Gets or sets the model ID used in the creation of the chat response. |
<modelId> | The model that answered, as the model service reported it. |
The Example
A console app called ModelCheck asks two agents the same question, What colour is the sky on a clear day?, and prints each answer with the model ID and the response ID. LunaAgent runs on the gpt-5.6-luna deployment through the Responses API, and SolAgent on gpt-5.6-sol through Chat Completions, so the example also shows that both kinds of agent keep a ChatResponse. Running it calls each deployment once, so it costs a little.
Prerequisites
- The .NET 10 SDK.
- A Microsoft Foundry project with a deployed chat model, and the Foundry User role on it. The example uses two deployments; one is enough to see a model ID.
- The Azure CLI, signed in with
az login.
Step 1: Create a Console App
dotnet new console -o ModelCheck
cd ModelCheck
dotnet add package Microsoft.Agents.AI.Foundry --version 1.28.0-preview.261106.1
dotnet add package Azure.Identity --version 1.21.0
dotnet new console -o ModelCheckcreates a console app in a newModelCheckfolder, andcdmoves into it.Microsoft.Agents.AI.Foundryis Agent Framework's package for Microsoft Foundry. Version 1.28.0-preview.261106.1 is a preview release.Azure.Identitylets the app sign in to Foundry with your Azure CLI account.
Step 2: Connect to Your Foundry Project
Replace everything in Program.cs with this, using your own project endpoint:
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
AIProjectClient project = new(
new Uri("https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp"),
new AzureCliCredential());
AIProjectClient connects to the Foundry project at that endpoint, and AzureCliCredential signs in with the account you used for az login, so there's no key in the code. The Microsoft.Extensions.AI namespace holds ChatResponse, which Step 4 needs.
Step 3: Create Two Agents on Two Deployments
Add the two agents below the project client:
// One agent on the Responses API and one on Chat Completions, on two different model deployments.
AIAgent responsesAgent = project.AsAIAgent(model: "gpt-5.6-luna", instructions: "Answer in five words or fewer.", name: "LunaAgent");
AIAgent chatAgent = project.GetProjectOpenAIClient()
.GetChatClient("gpt-5.6-sol")
.AsIChatClient()
.AsAIAgent(instructions: "Answer in five words or fewer.", name: "SolAgent");
project.AsAIAgent(model: "gpt-5.6-luna", ...)creates an agent on the project's Responses API, for the deployment named inmodel.GetProjectOpenAIClient().GetChatClient("gpt-5.6-sol")gets a Chat Completions client for the second deployment.AsIChatClient()wraps it in theIChatClientinterface, andAsAIAgent(...)builds an agent around it.instructionsasks both models for answers of five words or fewer, so the output stays short.
Step 4: Read the Model ID from Each Response
Add the loop that asks both agents and prints what came back:
foreach (AIAgent agent in new[] { responsesAgent, chatAgent })
{
AgentResponse response = await agent.RunAsync("What colour is the sky on a clear day?");
// The agent's response keeps the model service's own response, which names the model that answered.
ChatResponse? modelResponse = response.RawRepresentation as ChatResponse;
Console.WriteLine($"{agent.Name}: {response.Text}");
Console.WriteLine($" Model: {modelResponse?.ModelId}");
Console.WriteLine($" Response ID: {response.ResponseId}");
}
agent.RunAsync(...)sends the question and returns anAgentResponse.AgentResponsehas noModelIdproperty of its own. Its properties areMessages,Text,AgentId,ResponseId,ContinuationToken,CreatedAt,FinishReason,Usage,RawRepresentationandAdditionalProperties.response.RawRepresentation as ChatResponsegets the model service's own response from the agent's. If an agent keeps something else there,modelResponseisnull, andmodelResponse?.ModelIdprints nothing instead of throwing.response.ResponseIdis on the agent's response itself. Its reference: Gets or sets the unique identifier for this specific response.
Step 5: Run It
dotnet run
LunaAgent: Blue, due to scattered sunlight.
Model: gpt-5.6-luna-2026-07-09
Response ID: resp_091a4920ea8b3f8a006b0db43e1bd8819399e62b83e5575145
SolAgent: Blue.
Model: gpt-5.6-sol-2026-07-09
Response ID: chatcmpl-EpzbDwG1FqRLTyTKR7xWrb5grkvLV

Both responses held a ChatResponse, so both model IDs printed. They aren't the deployment names: the deployments are called gpt-5.6-luna and gpt-5.6-sol, and the model IDs add the model version, 2026-07-09.
That difference matters because a deployment's name stays the same while the model version behind it can change. Microsoft's page on model versions gives an example: For example, a deployment of gpt-4o might target version 2024-08-06. When version 2024-11-20 becomes available, deployments set to auto-update switch to the new version automatically. The model ID in each response tells you which version really answered.
The response IDs differ too: resp_ for the agent on the Responses API, and chatcmpl- for the one on Chat Completions.
Clean Up
LunaAgent works on the Responses API, and Foundry stores each response it creates, so the run left LunaAgent's response in the project. SolAgent's chat completion left nothing. Microsoft's Responses API guide gives the period: By default, response data is retained for 30 days. To remove the response sooner, delete it by the ID the run printed: How to Delete a Stored Response in Microsoft Foundry with the Azure CLI. How to Keep Microsoft Foundry from Storing an Agent's Conversations in C# compares the two APIs.
The Complete File
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
AIProjectClient project = new(
new Uri("https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp"),
new AzureCliCredential());
// One agent on the Responses API and one on Chat Completions, on two different model deployments.
AIAgent responsesAgent = project.AsAIAgent(model: "gpt-5.6-luna", instructions: "Answer in five words or fewer.", name: "LunaAgent");
AIAgent chatAgent = project.GetProjectOpenAIClient()
.GetChatClient("gpt-5.6-sol")
.AsIChatClient()
.AsAIAgent(instructions: "Answer in five words or fewer.", name: "SolAgent");
foreach (AIAgent agent in new[] { responsesAgent, chatAgent })
{
AgentResponse response = await agent.RunAsync("What colour is the sky on a clear day?");
// The agent's response keeps the model service's own response, which names the model that answered.
ChatResponse? modelResponse = response.RawRepresentation as ChatResponse;
Console.WriteLine($"{agent.Name}: {response.Text}");
Console.WriteLine($" Model: {modelResponse?.ModelId}");
Console.WriteLine($" Response ID: {response.ResponseId}");
}

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Looking for a ModelId property on AgentResponse | There isn't one, so the code doesn't compile | Read it from response.RawRepresentation as ChatResponse |
| Logging the deployment name as the model | The log can't show which version answered, and the version behind a deployment can change | Log ModelId from the response |
Casting with (ChatResponse)response.RawRepresentation | It throws when an agent keeps a different object there | Use as ChatResponse and ?.ModelId |
FAQ
Why isn't the model ID the deployment name?
The deployment name is the name you gave the deployment. The model ID is what the model service reports in its response: here the model and its version, gpt-5.6-luna-2026-07-09 for the deployment called gpt-5.6-luna.
Is RawRepresentation always a ChatResponse?
For both agents here, one on the Responses API and one on Chat Completions, it was. Its type is object, though, so the code reads it with as and handles null instead of assuming.
Can I get the token usage from the same response?
Yes. AgentResponse has a Usage property of its own, and How to Get the Token Usage and Cost of a Microsoft Agent Framework Agent Run in C# shows how to read it.
Conclusion
AgentResponse doesn't have a ModelId, but its RawRepresentation keeps the model service's ChatResponse, and that has one. Here it named gpt-5.6-luna-2026-07-09 and gpt-5.6-sol-2026-07-09: the model version behind each deployment, which the deployment names alone don't tell you. Log it with the response ID when you need to know exactly which model answered.
Additional Resources
- AgentResponse.RawRepresentation Property — what the property holds.
- ChatResponse.ModelId Property — the model ID in a chat response.
- Model versions in Microsoft Foundry Models — how the model version behind a deployment can change.
