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 and variable 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 from f12ff83 to 620ad62 Compare December 10, 2025 14:05
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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on reviewers

Development

Successfully merging this pull request may close these issues.

AI Persistence: Serialize and Restore ParsedRequest

3 participants