Currently, the Chat API in google-genai (Java SDK) does not expose a way to initialize a Chat session with an existing history of messages (e.g., loaded from persistent storage).
When reloading a session from disk (e.g. JSON/YAML), developers currently have to work around this limitation by either:
- Re-sending all previous messages to the model, which is slow and consumes tokens.
- Using reflection to manually populate the private
comprehensiveHistory and curatedHistory fields in ChatBase, which is fragile and not recommended.
It would be very beneficial to have a public API (e.g., an overload of Chats.create() or a builder method) that accepts an initial List<Content> to restore the conversation state.
Currently, the
ChatAPI ingoogle-genai(Java SDK) does not expose a way to initialize aChatsession with an existing history of messages (e.g., loaded from persistent storage).When reloading a session from disk (e.g. JSON/YAML), developers currently have to work around this limitation by either:
comprehensiveHistoryandcuratedHistoryfields inChatBase, which is fragile and not recommended.It would be very beneficial to have a public API (e.g., an overload of
Chats.create()or a builder method) that accepts an initialList<Content>to restore the conversation state.