wenjin272 commented on code in PR #869:
URL: https://github.com/apache/flink-agents/pull/869#discussion_r3526337003


##########
runtime/src/test/java/org/apache/flink/agents/runtime/actionstate/ActionStateSerdeTest.java:
##########
@@ -333,4 +344,65 @@ public void testKafkaSederDelegatesToActionStateSerde() 
throws Exception {
         assertNull(kafkaSeder.serialize("test-topic", null));
         assertNull(kafkaSeder.deserialize("test-topic", null));
     }
+
+    @Test
+    public void testBuiltInEventSerDeRoundTrip() 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);
+        ActionState deserializedState = 
ActionStateSerde.deserialize(serialized);
+
+        assertEquals(ChatRequestEvent.class, 
deserializedState.getTaskEvent().getClass());
+
+        List<Event> outputEvents = deserializedState.getOutputEvents();
+        assertEquals(6, outputEvents.size());
+        assertEquals(ChatRequestEvent.class, outputEvents.get(0).getClass());
+        assertEquals(ChatResponseEvent.class, outputEvents.get(1).getClass());
+        assertEquals(ToolRequestEvent.class, outputEvents.get(2).getClass());
+        assertEquals(ToolResponseEvent.class, outputEvents.get(3).getClass());
+        assertEquals(ContextRetrievalRequestEvent.class, 
outputEvents.get(4).getClass());
+        assertEquals(ContextRetrievalResponseEvent.class, 
outputEvents.get(5).getClass());
+
+        // On replay, actions declaring a concrete event signature (e.g. 
MathAgent's
+        // `processChatResponse(ChatResponseEvent, ...)`) receive the 
Jackson-reconstructed event
+        // directly and call typed getters WITHOUT going through fromEvent(). 
The JSON creator must
+        // therefore rehydrate nested attributes; otherwise these getters 
throw ClassCastException
+        // on the raw LinkedHashMap. Assert the typed getters directly on the 
deserialized
+        // instances.

Review Comment:
   This comment is overly verbose, and the phrase "going through fromEvent" 
describes a previous implementation that I believe should not appear in the 
final comment.



-- 
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]

Reply via email to