wenjin272 commented on code in PR #869:
URL: https://github.com/apache/flink-agents/pull/869#discussion_r3523321348
##########
runtime/src/test/java/org/apache/flink/agents/runtime/actionstate/ActionStateSerdeTest.java:
##########
@@ -333,4 +344,63 @@ public void testKafkaSederDelegatesToActionStateSerde()
throws Exception {
assertNull(kafkaSeder.serialize("test-topic", null));
assertNull(kafkaSeder.deserialize("test-topic", null));
}
+
+ @Test
+ public void
testBuiltinChatToolAndContextEventsRoundTripThroughOutputEvents() throws
Exception {
Review Comment:
The test case name is overly verbose and its meaning is unclear. suggest to:
`testBuiltInEventSerDeRoundTrip`
##########
runtime/src/test/java/org/apache/flink/agents/runtime/actionstate/ActionStateSerdeTest.java:
##########
@@ -333,4 +344,63 @@ public void testKafkaSederDelegatesToActionStateSerde()
throws Exception {
assertNull(kafkaSeder.serialize("test-topic", null));
assertNull(kafkaSeder.deserialize("test-topic", null));
}
+
+ @Test
+ public void
testBuiltinChatToolAndContextEventsRoundTripThroughOutputEvents() throws
Exception {
+ ChatMessage msg = new ChatMessage(MessageRole.USER, "hello");
+ UUID requestId = UUID.randomUUID();
+ Document doc = new Document("doc content", Map.of("source",
"unit-test"), "doc-1");
+
+ // Built-in events are persisted both as the triggering taskEvent and
as
+ // outputEvents; cover both paths.
+ ActionState originalState = new ActionState(new
ChatRequestEvent("myModel", List.of(msg)));
+ originalState.addEvent(new ChatRequestEvent("myModel", List.of(msg)));
+ originalState.addEvent(new ChatResponseEvent(requestId, msg));
+ originalState.addEvent(new ToolRequestEvent("myModel",
List.of(Map.of("name", "myTool"))));
+ originalState.addEvent(
+ new ToolResponseEvent(
+ requestId,
+ Map.of("call-1", ToolResponse.success("result")),
+ Map.of("call-1", true),
+ Map.of()));
+ originalState.addEvent(new ContextRetrievalRequestEvent("query text",
"myVectorStore", 5));
+ originalState.addEvent(
+ new ContextRetrievalResponseEvent(requestId, "query text",
List.of(doc)));
+
+ byte[] serialized = ActionStateSerde.serialize(originalState);
Review Comment:
Currently, we inject the type information of `Event` during serialization by
declaring mixins for the `ObjectMapper`.
```
// Add type information for polymorphic Event deserialization
mapper.addMixIn(Event.class, EventTypeInfoMixin.class);
mapper.addMixIn(InputEvent.class, EventTypeInfoMixin.class);
mapper.addMixIn(OutputEvent.class, EventTypeInfoMixin.class);
```
This allows the `ObjectMapper` to reconstruct the specific subclass of Event
during deserialization. But I think that it’s sufficient to keep only
`mapper.addMixIn(Event.class, EventTypeInfoMixin.class);` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]