How to Keep Microsoft Foundry from Storing an Agent's Conversations in C#
An agent you make with AsAIAgent on a Microsoft Foundry project talks to the Responses API, and Foundry keeps every response it gives. Build the agent on the project's Chat Completions client instead, and Foundry answers without keeping a thing: here both agents got the same question, and only the first answer could be fetched back afterwards.
Foundry stores responses so that a conversation can continue from one: the next request sends a response ID instead of the whole history. The Responses API guide gives the period: By default, response data is retained for 30 days. That's often what you want. When your users' questions and the answers shouldn't stay in the service, the Chat Completions API is the way around it, and in Agent Framework it's one chain of calls.
Syntax
AIAgent <agent> = <projectClient>
.GetProjectOpenAIClient()
.GetChatClient("<deployment>")
.AsIChatClient()
.AsAIAgent(instructions: "<instructions>", name: "<name>");
| Part | What it is |
|---|---|
<agent> | The agent your code runs |
<projectClient> | An AIProjectClient for your Foundry project |
GetProjectOpenAIClient() | Gets the project's OpenAI client |
GetChatClient("<deployment>") | Gets its ChatClient for one model deployment: the client for the Chat Completions API |
AsIChatClient() | Wraps it as an IChatClient, the interface Agent Framework builds agents on |
AsAIAgent(...) | Creates the agent, a ChatClientAgent, with your <instructions> and <name> |
Compare it with the usual way, <projectClient>.AsAIAgent(model: ..., instructions: ..., name: ...), which the documentation of Microsoft.Agents.AI.Foundry describes as creating a non-versioned ChatClientAgent backed by the project's Responses API.
The Example
A console app called StorageCheck asks two agents the same question: At what temperature does water boil at sea level, in degrees Celsius? StoredAgent uses the Responses API and UnstoredAgent the Chat Completions API. Both use the same model deployment, gpt-5.6-luna, and the same instructions. Each run makes two short model calls, billed at your deployment's token prices.
Prerequisites
- A Microsoft Foundry project with a deployed chat model, and the Azure CLI signed in with
az login. - The .NET 10 SDK.
Step 1: Create a Console App and Add the Packages
dotnet new console -o StorageCheck
cd StorageCheck
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/StorageCheck/StorageCheck.csproj:
Restore succeeded.
dotnet new console creates a console app in a new folder, StorageCheck, and cd moves into it. Then add two packages:
dotnet add package Microsoft.Agents.AI.Foundry --version 1.28.0-preview.261106.1
dotnet add package Azure.Identity --version 1.21.0
Each command adds a package reference and restores the project. The first one ends like this:
info : PackageReference for package 'Microsoft.Agents.AI.Foundry' version '1.28.0-preview.261106.1' added to file '/Users/you/source/StorageCheck/StorageCheck.csproj'.
info : Generating MSBuild file /Users/you/source/StorageCheck/obj/StorageCheck.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /Users/you/source/StorageCheck/obj/project.assets.json
log : Restored /Users/you/source/StorageCheck/StorageCheck.csproj (in 1.74 sec).
Microsoft.Agents.AI.Foundryconnects Agent Framework to Microsoft Foundry and brings Agent Framework 1.28.0 with it. It's a preview package, as its version says.Azure.Identitygives the appAzureCliCredential, to sign in to Foundry as your Azure CLI account.
The project file now lists both:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.21.0" />
<PackageReference Include="Microsoft.Agents.AI.Foundry" Version="1.28.0-preview.261106.1" />
</ItemGroup>
</Project>
Step 2: Create the Agent That Uses the Responses API
Replace everything in Program.cs with this, using your own project endpoint and model deployment:
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());
// The Responses API: Foundry keeps every response, so a conversation can continue from it later.
AIAgent storedAgent = project.AsAIAgent(
model: "gpt-5.6-luna",
instructions: "Answer in one short sentence.",
name: "StoredAgent");
new AIProjectClient(...)connects to the Foundry project at that endpoint, signed in as your Azure CLI account throughAzureCliCredential.project.AsAIAgent(...)creates StoredAgent on the project's Responses API, with the deployment, the instructions and a name.
Step 3: Create the Agent That Uses Chat Completions
Add the second agent below the first:
// Chat Completions: Foundry answers and keeps nothing.
AIAgent unstoredAgent = project
.GetProjectOpenAIClient()
.GetChatClient("gpt-5.6-luna")
.AsIChatClient()
.AsAIAgent(instructions: "Answer in one short sentence.", name: "UnstoredAgent");
GetProjectOpenAIClient()gets the project's OpenAI client.GetChatClient("gpt-5.6-luna")gets its client for chat completions, for the same deployment.AsIChatClient()turns that into anIChatClient, andAsAIAgent(...)creates the agent on it, with the same instructions.
The model and the instructions are the same as StoredAgent's. Only the API differs.
Step 4: Ask Both the Same Question
Add the loop at the end of the file:
foreach (AIAgent agent in new[] { storedAgent, unstoredAgent })
{
AgentResponse response = await agent.RunAsync("At what temperature does water boil at sea level, in degrees Celsius?");
Console.WriteLine($"{agent.Name}: {response.Text}");
Console.WriteLine($" Response ID: {response.ResponseId}");
}
RunAsyncsends the question to each agent in turn and returns its answer.response.Textis the answer, andresponse.ResponseIdis, in the words of its documentation, the unique identifier for this specific response.
Step 5: Run It
dotnet run
StoredAgent: Water boils at 100°C at sea level.
Response ID: resp_0d5c216cade26659006b0db14cd0cc8194b236d114cf42d40f
UnstoredAgent: Water boils at 100°C at sea level.
Response ID: chatcmpl-EpzP5LyLKtf9DgTdtcpi1VxUD62X7

Both agents gave the same answer. Their IDs show which API answered: resp_ for a response of the Responses API, and chatcmpl- for a chat completion. Your IDs will be different.
Step 6: Check What Foundry Kept
I asked Foundry for each ID with az rest, which sends a request to an Azure REST API signed in with your Azure CLI account, much as How to See the Conversation History Microsoft Foundry Stored for a Response asks it what it stored for a response. The commands work unchanged in bash, zsh and PowerShell. First, StoredAgent's response:
az rest --method get --resource "https://ai.azure.com" --url "https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp/openai/v1/responses/resp_0d5c216cade26659006b0db14cd0cc8194b236d114cf42d40f" --query "{id:id, status:status, model:model, text:output[-1].content[0].text}" --output json
--method getreads, and--resource "https://ai.azure.com"gets the Azure CLI's sign-in token for Foundry.--urlis the project endpoint, then/openai/v1/responses/and the response ID. For your own run, use your project endpoint and the ID it printed.--querykeeps four fields of the stored response: its ID, status, model and the answer's text. The Azure CLI prints them sorted by name.
Foundry returned the stored response:
{
"id": "resp_0d5c216cade26659006b0db14cd0cc8194b236d114cf42d40f",
"model": "gpt-5.6-luna",
"status": "completed",
"text": "Water boils at 100°C at sea level."
}
Then UnstoredAgent's chat completion, at the project's Chat Completions address:
az rest --method get --resource "https://ai.azure.com" --url "https://foundry-devblogs-exp.services.ai.azure.com/api/projects/proj-devblogs-exp/openai/v1/chat/completions/chatcmpl-EpzP5LyLKtf9DgTdtcpi1VxUD62X7"
There was nothing to return:
Not Found
The response is stored, with its model, its status and the answer. The chat completion isn't. Foundry only ever kept chat completions on request, as Microsoft's page on stored completions says: To enable stored completions for your Azure OpenAI deployment set the store parameter to True. UnstoredAgent never sets it, and that page now opens with a warning: Stored completions retire on October 15, 2026.
What You Give Up
A conversation that continues needs its earlier turns. With StoredAgent, Foundry has them. With UnstoredAgent, it doesn't, so your app has to keep them and send them with every request. Microsoft's guide to switching models calls this caller-managed history, where the caller sends The relevant message history plus any new messages with each request. In Agent Framework, a chat history provider does that job: It can store messages in the agent session or in application-owned storage.
The API you pick decides which of the two you can use. Microsoft's model provider overview puts it this way: The selected API determines whether the remote service can own conversation history and whether the agent can instead use an in-memory or custom ChatHistoryProvider.
Clean Up
The run left one stored response in Foundry, StoredAgent's resp_0d5c216cade26659006b0db14cd0cc8194b236d114cf42d40f, and yours leaves one with its own ID. It stays for 30 days unless you delete it sooner: How to Delete a Stored Response in Microsoft Foundry with the Azure CLI does that with one command. UnstoredAgent's chat completion left nothing to delete.
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());
// The Responses API: Foundry keeps every response, so a conversation can continue from it later.
AIAgent storedAgent = project.AsAIAgent(
model: "gpt-5.6-luna",
instructions: "Answer in one short sentence.",
name: "StoredAgent");
// Chat Completions: Foundry answers and keeps nothing.
AIAgent unstoredAgent = project
.GetProjectOpenAIClient()
.GetChatClient("gpt-5.6-luna")
.AsIChatClient()
.AsAIAgent(instructions: "Answer in one short sentence.", name: "UnstoredAgent");
foreach (AIAgent agent in new[] { storedAgent, unstoredAgent })
{
AgentResponse response = await agent.RunAsync("At what temperature does water boil at sea level, in degrees Celsius?");
Console.WriteLine($"{agent.Name}: {response.Text}");
Console.WriteLine($" Response ID: {response.ResponseId}");
}

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting an agent made with AsAIAgent on a project to keep nothing | It uses the Responses API, and Foundry keeps each response, for 30 days by default | Build it on GetChatClient(...).AsIChatClient() |
Looking up a chatcmpl- ID in Foundry | Foundry answers Not Found, because nothing was stored | Only the resp_ IDs lead to stored responses |
| Switching APIs and leaving the responses already stored | They stay in Foundry for the rest of their 30 days | Delete the ones that shouldn't stay |
FAQ
Can the Responses API stop storing too?
It has a switch for it. Microsoft's guide to switching models: For example, OpenAI responses has the store parameter which you can set to true for inference-service-managed chat history, and to false for caller-managed. This example doesn't use it. It changes the API instead, and the run shows the result: nothing to fetch.
Does the Chat Completions agent answer differently?
Not here. Both agents used the same deployment and the same instructions, and both answered Water boils at 100°C at sea level. What changes is where the conversation is kept, not how the model answers.
Conclusion
An agent made with AsAIAgent on a Foundry project uses the Responses API, and Foundry keeps each of its responses for 30 days by default. To keep Foundry from storing the conversation, build the agent on the project's Chat Completions client: GetProjectOpenAIClient().GetChatClient("<deployment>").AsIChatClient().AsAIAgent(...). StorageCheck's StoredAgent left a response that could be fetched back; UnstoredAgent's chatcmpl- ID led to Not Found. The price is that your app keeps the conversation's history itself.
Additional Resources
- Switch models and inference providers at runtime — caller-managed and service-managed chat history, and the
storeparameter. - Model providers — which APIs let the service keep a conversation's history.
- Use the Azure OpenAI Responses API — retrieving and deleting stored responses, and how long they're kept.
- Azure OpenAI stored completions — the
storeparameter for chat completions, and its retirement.
