rosemarYuan commented on code in PR #756:
URL: https://github.com/apache/flink-agents/pull/756#discussion_r3359886351
##########
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:
Fixed in lines 84-88. Added a model_validator fallback that mirrors the Java
ActionJsonDeserializer behavior:
```
# Legacy fallback: listen_event_types → trigger_conditions
if "trigger_conditions" not in self or
self.get("trigger_conditions") is None:
if self.get("listen_event_types"):
self["trigger_conditions"] = list(self["listen_event_types"])
self.pop("listen_event_types", None)
```
Old-format plan JSON with listen_event_types will now deserialize without
ValidationError.
##########
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:
Agreed. I've refactored EventType to be a pure namespace of constants — each
one simply re-exports the value from the corresponding event class (e.g.,
EventType.InputEvent = _InputEvent.EVENT_TYPE), so there's a single source of
truth. The register() / lookup() / lookupOrSelf() registry has been removed
from this PR and will be introduced later when the CEL PR actually requires
dynamic resolution.
Meanwhile, I've also slimmed down the EventType class by removing the
internal utility functions — their concrete implementations are deferred to a
follow-up PR.
--
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]