wenjin272 commented on code in PR #1184:
URL: https://github.com/apache/flink-agents/pull/1184#discussion_r4185318162
##########
api/src/main/java/org/apache/flink/agents/api/Event.java:
##########
@@ -255,12 +255,17 @@ protected static <T extends Event> T reconstructFrom(
/**
* Creates an Event from a JSON string.
*
+ * <p>Known built-in event types are restored to their concrete subclass
via {@link
+ * BuiltInEvents#restore(Event)}, so nested typed values survive the
cross-language boundary;
+ * unknown or user-defined types are returned as a generic {@link Event}.
+ *
* @param json the JSON string to deserialize
- * @return the deserialized Event
+ * @return the deserialized Event, or its concrete built-in subclass
* @throws IOException if JSON parsing fails or the 'type' field is
missing or empty
+ * @throws IllegalArgumentException if a built-in event is malformed and
cannot be reconstructed
*/
public static Event fromJson(String json) throws IOException {
- return MAPPER.readValue(json, Event.class);
+ return BuiltInEvents.restore(MAPPER.readValue(json, Event.class));
Review Comment:
With built-in events now restored at the JSON boundary, could we remove
redundant `fromEvent` / `from_event` calls from the existing agents, built-in
actions, and examples?
For example, `ChatModelAction` still calls
`ChatRequestEvent.fromEvent(event)`, and the Python implementation does the
same. Native Java events constructed with their built-in classes already retain
their types, while events crossing the JSON boundary are now restored centrally.
These consumers should be able to use the concrete event directly, with a
cast where needed in Java. The reconstruction methods themselves should remain
available for the registry. Please also cover the simplified consumers with
tests that verify the concrete type reaches the action.
--
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]