Skip to content

Conversation

@lucas-koehler
Copy link
Contributor

@lucas-koehler lucas-koehler commented Dec 10, 2025

What it does

Fixes #16561

Implement serialization of ParsedChatRequest data to preserve structured information (agent references, variable references, tool requests) across session persistence and restoration.

Previously, only raw text was preserved after session restoration, causing loss of parsed structure data. This affected UI rendering and prevented proper display of agent names, variables, and tool references in restored chat sessions.

Main code changes:

  • Add serialization interfaces for ParsedChatRequest components in chat-model-serialization.ts (SerializableParsedRequestPart, SerializableToolRequest, SerializableResolvedVariable, etc.)
  • Implement toSerializable() methods on ParsedChatRequestTextPart, ParsedChatRequestVariablePart, ParsedChatRequestFunctionPart, and ParsedChatRequestAgentPart classes
  • Update MutableChatRequestModel to serialize/deserialize parsedRequest data via toSerializable() and deserializeParsedRequest() methods
  • Serialize tool functions as id only and restore from the registry. For this, MutableChatModel and MutableChatRequestModel now require the tool registry as constructor parameter
  • Add comprehensive test coverage for serialization/deserialization of all part types, including edge cases and complex mixed requests
16561-pr.webm

How to test

  • Use the AI chat and chat using an agent and variable reference
  • Restart theia
  • Restore the session
  • Observe: The agent, variable and tool function are now highlighted and provide additional information on hover

NOTE: While the serialization also supports functions/tool requests, highlighting them does not work yet in general. See #16722

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

@github-project-automation github-project-automation bot moved this to Waiting on reviewers in PR Backlog Dec 10, 2025
@lucas-koehler lucas-koehler force-pushed the lk/issues/16561-parsed-request-persistence branch 2 times, most recently from 620ad62 to f69415f Compare December 11, 2025 14:29
@lucas-koehler lucas-koehler requested a review from sdirix December 15, 2025 08:25
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level feedback:

  • The ChatModel is restored via the ChatService. At the moment we already avoid handing in registries into the chat model by restoring registry-related data later, see here and here.
  • Could we follow this pattern here too? This would overall be a simpler process and continue with the established pattern, avoiding this registry dependency

@lucas-koehler
Copy link
Contributor Author

@sdirix That is a very good point! Thanks for catching that. I refactored the code accordingly to restore the tool requests from the registry in the chat service.
In the current refactoring, the chat service uses the registry directly as the deserializer registry is currently only meant for response content but tool requests are part of the request.
Is this okay with you or do you think we should extend the registry now to also support request content?

@lucas-koehler lucas-koehler requested a review from sdirix December 15, 2025 17:05
@sdirix
Copy link
Member

sdirix commented Jan 8, 2026

I will review at the latest next week.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me and could be merged as is 👍

I have some comments, please have a look.

if (partData.variableValue !== undefined) {
varPart.resolution = {
variable: {
id: partData.variableId ?? 'restored',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if there is no id we should not restore it? And during storing we should make sure they have an id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem lies earlier: variable ids are only available if the variable is resolved during serialization (see packages/ai-chat/src/common/parsed-chat-request.ts). Currently we serialize the variable in any case.
We could think about serializing unresolved variables as text parts but there could be value in knowing this is a variable even if it was not/could not be resolved at the time of serialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I moved adding a fallback value of the id to the serialization function.

@github-project-automation github-project-automation bot moved this from Waiting on reviewers to Needs merge in PR Backlog Jan 15, 2026
Implement serialization of ParsedChatRequest data to preserve structured
information (agent references, variable references, tool requests) across
session persistence and restoration.

Previously, only raw text was preserved after session restoration, causing
loss of parsed structure data. This affected UI rendering and prevented
proper display of agent names, variables, and tool references in restored
chat sessions.

Main code changes:
- Add serialization interfaces for ParsedChatRequest components in
  chat-model-serialization.ts (SerializableParsedRequestPart,
  SerializableToolRequest, SerializableResolvedVariable, etc.)
- Implement toSerializable() methods on ParsedChatRequestTextPart,
  ParsedChatRequestVariablePart, ParsedChatRequestFunctionPart, and
  ParsedChatRequestAgentPart classes
- Update MutableChatRequestModel to serialize/deserialize parsedRequest
  data via toSerializable() and deserializeParsedRequest() methods
- Serialize tool functions as id only and restore from the registry.
  For this, MutableChatModel and MutableChatRequestModel now require the tool
  registry as constructor parameter
- Add comprehensive test coverage for serialization/deserialization of
  all part types, including edge cases and complex mixed requests
@lucas-koehler lucas-koehler force-pushed the lk/issues/16561-parsed-request-persistence branch from 0cedbf0 to 8c3fce2 Compare January 20, 2026 15:45
@lucas-koehler
Copy link
Contributor Author

@sdirix I added serialization of the description. I also removed the 2 changelog commits during rebase: They cancelled each other and caused conflicts.
I also moved the initialization of the variable id fallback value to the serialization function of a variable part.
For now I left serializing and deserializing variable parts without an id. IMO the core question is whether we want to serialize variable parts with an unresolved variable at all. IMO this can be a follow up issue. WDYT?

@lucas-koehler lucas-koehler requested a review from sdirix January 20, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs merge

Development

Successfully merging this pull request may close these issues.

AI Persistence: Serialize and Restore ParsedRequest

3 participants