wenjin272 commented on code in PR #1352:
URL: https://github.com/apache/flink-agents/pull/1352#discussion_r4490601124


##########
python/flink_agents/plan/actions/chat_model_action.py:
##########
@@ -259,18 +265,24 @@ def _save_tool_request_event_context(
     model: str,
     prompt_args: Dict | None,
     output_schema: OutputSchema | None,
+    user_context: dict[str, Any] | None = None,
 ) -> None:
     """Save the context for a specific tool request event."""
-    context = sensory_memory.get(_TOOL_REQUEST_EVENT_CONTEXT) or {}
-    context[str(tool_request_event_id)] = {
+    stored = sensory_memory.get(_TOOL_REQUEST_EVENT_CONTEXT) or {}
+    entry = {
         "initial_request_id": str(initial_request_id),
         "model": model,
         _PROMPT_ARGS: prompt_args if prompt_args is not None else {},
         "output_schema": output_schema.model_dump()
         if output_schema is not None
         else None,
     }
-    sensory_memory.set(_TOOL_REQUEST_EVENT_CONTEXT, context)
+    # Same attribute name as the event field. Absent when the request omitted 
it,
+    # so a checkpoint from before this field still resumes with no user 
context.
+    if user_context is not None:
+        entry["user_context"] = user_context
+    stored[str(tool_request_event_id)] = entry
+    sensory_memory.set(_TOOL_REQUEST_EVENT_CONTEXT, stored)

Review Comment:
   Could we serialize `user_context` before storing it in sensory memory and 
deserialize it when retrieving it?
   
   Event JSON serialization supports values such as UUIDs, datetimes, Pydantic 
models, tuples, and `Row`, while Python memory does not accept those objects 
directly. Saving a context containing such objects here can therefore raise 
`TypeError` before the `ToolRequestEvent` is sent.
   
   Using Event-compatible serialization at this storage boundary would handle 
this difference. Could we also add a regression test covering a tool round and 
carrying its user context through to the final `ChatResponseEvent`?



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