HsbcJone commented on code in PR #1352:
URL: https://github.com/apache/flink-agents/pull/1352#discussion_r4490692168
##########
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:
Fixed in a465b44c.
`_save_tool_request_event_context` now writes `user_context` through
`Event.model_dump_json` before `sensory_memory.set`, and
`_get_tool_request_event_context` restores it with `Event.from_json`. That is
the same attribute encoding events already use: a UUID, datetime, Pydantic
model, or tuple is stored as its JSON form, and a `Row` is reconstructed on
read. A plain JSON map still round-trips as itself. The value stays off
`ToolRequestEvent`.
`test_tool_round_restores_event_serializable_user_context` runs one tool
round whose context holds a UUID, a timezone-aware datetime, a small Pydantic
model, a tuple, and a `Row`. The parked entry passes `validate_memory_value`,
survives a JSON checkpoint of that entry, and the final
`ChatResponseEvent.user_context` equals `Event.from_json` of the request.
Java `ChatModelAction.saveToolRequestEventContext` still stores the `Map` it
is given. Java sensory memory does not reject those objects at `set` (there is
no Python `validate_memory_value` equivalent), so this boundary is Python-only.
Also rebased onto current apache/flink-agents `main`, including #1359. The
#1357 per-model attempt split is unchanged.
--
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]