Zhuoxi2000 commented on code in PR #1060:
URL: https://github.com/apache/flink-agents/pull/1060#discussion_r4056319273


##########
docs/content/docs/development/chat_models.md:
##########
@@ -97,7 +97,7 @@ class MyAgent(Agent):
     @staticmethod
     def process_response(event: Event, ctx: RunnerContext) -> None:
         chat_response = ChatResponseEvent.from_event(event)
-        response_content = chat_response.response.content
+        response_content = chat_response.response.text

Review Comment:
   Done! 



##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/MediaBlock.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.api.chat.messages;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.annotation.Nullable;
+
+import java.util.Objects;
+
+/**
+ * Shared shape for binary media blocks: modality is the concrete type, 
encoding is the MIME type.
+ *
+ * <p>The payload is carried by exactly one of base64 {@code data} or an 
externally managed {@code
+ * url} (enforced by the argument constructor and the per-type factories; the 
no-arg bean path is
+ * lenient for deserialization). URL-backed content is externally managed: 
URLs may expire, may not
+ * be reachable by the model provider, and may be invalid after recovery from 
a checkpoint. The
+ * optional {@code name}/{@code sizeBytes}/{@code sha256} metadata also serves 
the Event Log, which
+ * records media metadata instead of payload bytes.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public abstract class MediaBlock extends ContentBlock {
+
+    @JsonProperty("mime_type")
+    private String mimeType;
+
+    @Nullable private String data;
+
+    @Nullable private String url;
+
+    @Nullable private String name;
+
+    @JsonProperty("size_bytes")
+    @Nullable
+    private Long sizeBytes;
+
+    @Nullable private String sha256;
+
+    protected MediaBlock() {}

Review Comment:
   Fixed.



##########
api/src/main/java/org/apache/flink/agents/api/chat/model/routing/RoutingContext.java:
##########
@@ -97,7 +97,9 @@ private static List<ChatMessage> deepCopy(List<ChatMessage> 
messages) {
                     toolCalls.add(call == null ? null : new HashMap<>(call));
                 }
             }
-            copy.add(new ChatMessage(m.getRole(), m.getContent(), toolCalls, 
m.getExtraArgs()));
+            // The full constructor copies the block list; blocks themselves 
are shared, matching

Review Comment:
   Yep, I went with the immutable approach you suggested.



##########
plan/src/test/java/org/apache/flink/agents/plan/resource/python/PythonPromptTest.java:
##########
@@ -75,9 +75,9 @@ public void testFromSerializedMapWithMessageListTemplate() {
                 prompt.formatMessages(MessageRole.SYSTEM, new HashMap<>());
         assertThat(formattedMessages).hasSize(2);
         
assertThat(formattedMessages.get(0).getRole()).isEqualTo(MessageRole.SYSTEM);
-        assertThat(formattedMessages.get(0).getContent()).isEqualTo("You are a 
helpful assistant.");
+        assertThat(formattedMessages.get(0).getText()).isEqualTo("You are a 
helpful assistant.");

Review Comment:
   Good catch  this was an actual bug.Fixed it 



##########
api/src/main/java/org/apache/flink/agents/api/chat/messages/MediaBlock.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.agents.api.chat.messages;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.annotation.Nullable;
+
+import java.util.Objects;
+
+/**
+ * Shared shape for binary media blocks: modality is the concrete type, 
encoding is the MIME type.
+ *
+ * <p>The payload is carried by exactly one of base64 {@code data} or an 
externally managed {@code
+ * url} (enforced by the argument constructor and the per-type factories; the 
no-arg bean path is
+ * lenient for deserialization). URL-backed content is externally managed: 
URLs may expire, may not
+ * be reachable by the model provider, and may be invalid after recovery from 
a checkpoint. The
+ * optional {@code name}/{@code sizeBytes}/{@code sha256} metadata also serves 
the Event Log, which

Review Comment:
   Done. ContentBlock and MediaSource now handle their own log-safe form 
through sanitize().
   
   For media blocks, we only keep the metadata and sanitized source. Base64 
data is dropped, and URLs are stripped of credentials, query params, and 
fragments.
   
   I also added a dedicated ChatMessageEventLogSerializer for the Event Log 
side rather than putting this into the generic serializer.
   
   There are tests for both STANDARD and VERBOSE to make sure payloads and 
sensitive URL parts don't end up in the logs.
   
   The Python-originated event case is still separate and tracked in #1125.



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