This is an automated email from the ASF dual-hosted git repository.

xtsong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git

commit 4f7d20f5f991d0da456cd2e9668d95cd9071a43c
Author: WenjinXie <[email protected]>
AuthorDate: Fri Nov 7 17:27:33 2025 +0800

    [api][runtime][python] Introduce sensory memory in python.
---
 python/flink_agents/api/runner_context.py          | 11 ++++++++
 .../flink_agents/runtime/flink_runner_context.py   | 17 +++++++++++++
 python/flink_agents/runtime/local_runner.py        | 29 +++++++++++++++++++---
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/python/flink_agents/api/runner_context.py 
b/python/flink_agents/api/runner_context.py
index 0a3eb01..73dcbe4 100644
--- a/python/flink_agents/api/runner_context.py
+++ b/python/flink_agents/api/runner_context.py
@@ -81,6 +81,17 @@ class RunnerContext(ABC):
             The config option value.
         """
 
+    @property
+    @abstractmethod
+    def sensory_memory(self) -> "MemoryObject":
+        """Get the sensory memory.
+
+        Returns:
+        -------
+        MemoryObject
+          The root object of the sensory memory.
+        """
+
     @property
     @abstractmethod
     def short_term_memory(self) -> "MemoryObject":
diff --git a/python/flink_agents/runtime/flink_runner_context.py 
b/python/flink_agents/runtime/flink_runner_context.py
index 8f3c323..5e8331b 100644
--- a/python/flink_agents/runtime/flink_runner_context.py
+++ b/python/flink_agents/runtime/flink_runner_context.py
@@ -88,6 +88,23 @@ class FlinkRunnerContext(RunnerContext):
             action_name=self._j_runner_context.getActionName(), key=key
         )
 
+    @property
+    @override
+    def sensory_memory(self) -> FlinkMemoryObject:
+        """Get the sensory memory object associated with this context.
+
+        Returns:
+        -------
+        MemoryObject
+            The sensory memory object that can be used to access and modify
+            temporary state data.
+        """
+        try:
+            return FlinkMemoryObject(self._j_runner_context.getSensoryMemory())
+        except Exception as e:
+            err_msg = "Failed to get sensory memory of runner context"
+            raise RuntimeError(err_msg) from e
+
     @property
     @override
     def short_term_memory(self) -> FlinkMemoryObject:
diff --git a/python/flink_agents/runtime/local_runner.py 
b/python/flink_agents/runtime/local_runner.py
index 8f0441c..d600f52 100644
--- a/python/flink_agents/runtime/local_runner.py
+++ b/python/flink_agents/runtime/local_runner.py
@@ -58,7 +58,9 @@ class LocalRunnerContext(RunnerContext):
     __key: Any
     events: deque[Event]
     action_name: str
-    _store: dict[str, Any]
+    _sensory_mem_store: dict[str, Any]
+    _short_term_mem_store: dict[str, Any]
+    _sensory_memory: MemoryObject
     _short_term_memory: MemoryObject
     _config: AgentConfiguration
 
@@ -76,9 +78,13 @@ class LocalRunnerContext(RunnerContext):
         self.__agent_plan = agent_plan
         self.__key = key
         self.events = deque()
-        self._store = {}
+        self._sensory_mem_store = {}
+        self._short_term_mem_store = {}
+        self._sensory_memory = LocalMemoryObject(
+            self._sensory_mem_store, LocalMemoryObject.ROOT_KEY
+        )
         self._short_term_memory = LocalMemoryObject(
-            self._store, LocalMemoryObject.ROOT_KEY
+            self._short_term_mem_store, LocalMemoryObject.ROOT_KEY
         )
         self._config = config
 
@@ -122,6 +128,18 @@ class LocalRunnerContext(RunnerContext):
             action_name=self.action_name, key=key
         )
 
+    @property
+    @override
+    def sensory_memory(self) -> MemoryObject:
+        """Get the short-term memory object associated with this context.
+
+        Returns:
+        -------
+        MemoryObject
+            The root object of the short-term memory.
+        """
+        return self._sensory_memory
+
     @property
     @override
     def short_term_memory(self) -> MemoryObject:
@@ -169,6 +187,10 @@ class LocalRunnerContext(RunnerContext):
     def config(self) -> AgentConfiguration:
         return self._config
 
+    def clear_sensory_memory(self) -> None:
+        """Clean up sensory memory."""
+        self._sensory_mem_store.clear()
+
 
 class LocalRunner(AgentRunner):
     """Agent runner implementation for local execution, which is
@@ -228,6 +250,7 @@ class LocalRunner(AgentRunner):
         if key not in self.__keyed_contexts:
             self.__keyed_contexts[key] = LocalRunnerContext(self.__agent_plan, 
key, self.__config)
         context = self.__keyed_contexts[key]
+        context.clear_sensory_memory()
 
         if "value" in data:
             input_event = InputEvent(input=data["value"])

Reply via email to