Skip to content

.NET: [Bug]: Unable to filter out tool messages from the chat history #4256

@marcominerva

Description

@marcominerva

Description

Using the StorageInputMessageFilter property of InMemoryChatHistoryProvider, I can filter messages before actually saving them to the store. However, suppose I do something like this:

var session = await agent.CreateSessionAsync();
var response = await agent.RunAsync("What is the weather like in Taggia?", session);

Assume that I have added an MCP tool to the Agent that provides weather information. In this situation, when the StorageInputMessageFilter function is invoked, it only receives the user’s question, not the messages generated by the tool that are used to produce the assistant’s response.

So, with this code:

var history = await agent.SerializeSessionAsync(session);
var json = history.GetRawText();

I get something like this:

{
   "stateBag":{
      "InMemoryChatHistoryProvider":{
         "messages":[
            {
               "role":"user",
               "contents":[
                  {
                     "$type":"text",
                     "text":"what is the weather like in taggia?"
                  }
               ]
            },
            {
               "authorName":"Default",
               "createdAt":"2026-02-25T15:29:06+00:00",
               "role":"assistant",
               "contents":[
                  {
                     "$type":"functionCall",
                     "callId":"call_pkfoo13EAg7rE31Zj2AramGU",
                     "name":"get_current_weather",
                     "arguments":{
                        "city":"Taggia"
                     },
                     "informationalOnly":true
                  }
               ],
               "messageId":"chatcmpl-DDB6whyBMG5qsKwQHCMAAwUnHyLx0"
            },
            {
               "authorName":"Default",
               "createdAt":"2026-02-25T15:29:06.5427865+00:00",
               "role":"tool",
               "contents":[
                  {
                     "$type":"functionResult",
                     "callId":"call_pkfoo13EAg7rE31Zj2AramGU",
                     "result":{
                        "content":[
                           {
                              "type":"text",
                              "text":"{\"cityName\":\"Taggia\",\"condition\":\"Clouds\",\"conditionIcon\":\"03d\",\"conditionIconUrl\":\"https://openweathermap.org/img/w/03d.png\",\"conditionDescription\":\"scattered clouds\",\"temperature\":14.79,\"units\":\"Metric\"}"
                           }
                        ],
                        "structuredContent":{
                           "cityName":"Taggia",
                           "condition":"Clouds",
                           "conditionIcon":"03d",
                           "conditionIconUrl":"https://openweathermap.org/img/w/03d.png",
                           "conditionDescription":"scattered clouds",
                           "temperature":14.79,
                           "units":"Metric"
                        }
                     }
                  }
               ],
               "messageId":"094bdfe0e2104be4b517bf687c09b76e"
            },
            {
               "authorName":"Default",
               "createdAt":"2026-02-25T15:29:07+00:00",
               "role":"assistant",
               "contents":[
                  {
                     "$type":"text",
                     "text":"The current weather in Taggia is scattered clouds with a temperature of about 14.8°C."
                  }
               ],
               "messageId":"chatcmpl-DDB6xyFaI8YUys7xJfxaJdOC3wbKg"
            }
         ]
      }
   }
}

I would like to exclude the functionCall and functionResult messages from the history. Is it possible?

Package Versions

Microsoft.Agents.AI.OpenAI: 1.0.0-rc1

.NET Version

.NET 10.0.3

Metadata

Metadata

Assignees

Labels

.NETbugSomething isn't workingv1.0Features being tracked for the version 1.0 GA

Type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions