wzhero1 commented on code in PR #756:
URL: https://github.com/apache/flink-agents/pull/756#discussion_r3355556754
##########
python/flink_agents/plan/actions/action.py:
##########
@@ -29,29 +29,39 @@
class Action(BaseModel):
- """Representation of an agent action with event listening and function
execution.
+ """Representation of an agent action with unified trigger conditions.
- This class encapsulates a named agent action that listens for specific
event
- types and executes an associated function when those events occur.
+ This class encapsulates a named agent action that triggers on matching
+ events and executes an associated function.
Attributes:
----------
name : str
Name/identifier of the agent Action.
exec : Function
To be executed when the Action is triggered.
- listen_event_types : List[str]
- List of event types that will trigger this Action's execution.
+ trigger_conditions : List[str]
+ Event-type name strings that will trigger this Action. Multiple
+ entries combine with OR semantics.
"""
model_config = ConfigDict(arbitrary_types_allowed=True)
name: str
# TODO: Raise a warning when the action has a return value, as it will be
ignored.
exec: PythonFunction | JavaFunction
- listen_event_types: List[str]
+ trigger_conditions: List[str]
Review Comment:
**Python Action model lacks backward compat for old JSON key**
Java `ActionJsonDeserializer` (L71-73) falls back to `listen_event_types`
when `trigger_conditions` is absent. The Python pydantic `Action` model only
declares `trigger_conditions: List[str]` with no alias or model_validator
fallback — deserializing old-format plan JSON from persisted Flink state will
raise `ValidationError`.
##########
plan/src/main/java/org/apache/flink/agents/plan/actions/Action.java:
##########
@@ -33,36 +33,36 @@
import java.util.Objects;
/**
- * Representation of an agent action with event listening and function
execution.
+ * Representation of an agent action with unified trigger conditions.
*
- * <p>This class encapsulates a named agent action that listens for specific
event types and
- * executes an associated function when those events occur.
+ * <p>Each entry of {@code triggerConditions} is an event type name string.
Multiple entries combine
+ * with OR.
*/
@JsonSerialize(using = ActionJsonSerializer.class)
@JsonDeserialize(using = ActionJsonDeserializer.class)
public class Action {
private final String name;
private final Function exec;
- private final List<String> listenEventTypes;
+ private final List<String> triggerConditions;
Review Comment:
Discuss:**Keep `listen_event_types`, add `trigger_conditions` as a new
field**
Rather than renaming `listen_event_types` → `trigger_conditions`, I'd
suggest keeping both:
- `listen_event_types`: which events route to this action (static dispatch)
- `trigger_conditions`: CEL expression filter for whether to process a
matched event (dynamic filtering)
These are orthogonal concerns — routing vs. filtering. Keeping
`listen_event_types` also avoids JSON backward-compat issues entirely (the
Python pydantic model currently lacks the fallback that the Java deserializer
has for the old key).
##########
api/src/main/java/org/apache/flink/agents/api/EventType.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Compile-time constants for built-in event types and a runtime registry for
user-defined events.
+ *
+ * <p>Usage in {@code @Action}:
+ *
+ * <ul>
+ * <li>Built-in events: {@code @Action(EventType.InputEvent)}
+ * <li>User-defined events: {@code @Action("MyCustomEvent")}
+ * </ul>
+ *
+ * <p>Resolution via {@link #lookupOrSelf}: built-in → user-registered
→ passthrough.
+ */
+public final class EventType {
Review Comment:
**Reconsider the `EventType` aggregation class**
`EventType.InputEvent` duplicates `InputEvent.EVENT_TYPE` — two sources of
truth for the same value. The `register()` / `lookup()` / `lookupOrSelf()`
registry has zero callers in production code today.
`InputEvent.EVENT_TYPE` is already self-documenting and lives in its natural
namespace. Suggest deferring the registry until the CEL PR actually needs it,
and just using the event class constants directly.
--
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]