Skip to content

.Net: Serialize ChatHistory for Google Gemini not working #11413

@sophialagerkranspandey

Description

@sophialagerkranspandey

Discussed in #11388

Originally posted by mlefebvre74-dev April 5, 2025
Hi Everyone,

I am following the following Example 3 in the GeminiFunctionCalling sample code and am able to get all the calledToolResult information into the ChatHistory using the GeminiChatMessageContent. All working great however, when I try to save the ChatHistory by serializing the session using this approach:

`
// Code from Example 3 in GeminiFunctionCalling sample code omitted (See link below)

       ChatHistory chatHistory;

        var options = new JsonSerializerOptions
        {
            WriteIndented = true,
        };
        var jsonHistory = JsonSerializer.Serialize(chatHistory, options);

   var saveChatHistory = JsonSerializer.Deserialize<ChatHistory>(chatHistoryJson, options);

`

https://github.com/microsoft/semantic-kernel/blob/7d9f834130042f4eb50946dbc94667270157b22a/dotnet/samples/Concepts/FunctionCalling/Gemini_FunctionCalling.cs

Can someone please advise how I can save the Gemini Chat history including calledToolResult so I can use it for further calls to the Gemini LLM.

Thank you!

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codestaleIssue is stale because it has been open for a while and has no activity

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions