weiqingy opened a new pull request, #828:
URL: https://github.com/apache/flink-agents/pull/828

   Linked issue: #723
   
   ### Purpose of change
   
   The built-in chat-model action stored non-primitive Python objects in 
sensory memory: `UUID` values, an `OutputSchema`, and `ChatMessage` lists. 
Pemja wraps such objects as `PyObject` holders whose JNI pointers go stale 
after a TaskManager/Python restart, so restoring the checkpointed tool context 
crashes in `JcpPyObject_FromJObject`.
   
   This normalizes those values to a primitive-only form before they reach 
memory and reconstructs the rich types on read, entirely inside the three 
tool-context helpers in `chat_model_action.py` (no caller or signature changes):
   
   - `ChatMessage` lists are stored via `model_dump(mode="json")` and 
reconstructed via `ChatMessage.model_validate`. `mode="json"` is required 
because `MessageRole` is a `str, Enum` that a bare `model_dump()` would leave 
as an enum member.
   - `initial_request_id` is stored as `str` and reconstructed to `UUID`.
   - `output_schema` is stored via `OutputSchema.model_dump()` and 
reconstructed via `OutputSchema.model_validate` (None-guarded).
   
   Dict keys were already strings and the retry-stats context already holds 
only `int`s, so both are unchanged. `prompt_args` is user-supplied and already 
round-trips as a `ChatRequestEvent` attribute, so it is left as-is.
   
   This is the first of the agreed changes on #723. A follow-up PR will add a 
`set()`-time validator for user-supplied memory values and document the Python 
memory value contract.
   
   ### Tests
   
   `plan/tests/actions/test_chat_model_action.py`: 9 new unit tests plus a 
recursive `_assert_primitive` helper that asserts the stored form is 
primitive-only (a checkpoint-safety proxy, since no Python checkpoint/restore 
harness exists), and that round-trips reconstruct `UUID` / `OutputSchema` / 
`ChatMessage`, preserve the `UUID`→`str` dict-key match and `RowTypeInfo`, 
handle a `None` output_schema, and keep `model` / `prompt_args`.
   
   `plan/tests/actions/test_chat_model_action_retry.py`: updated the 
hand-seeded context in `test_forwards_saved_prompt_args_to_chat` to the new 
primitive-only stored form.
   
   ```
   cd python
   uv run --no-sync pytest flink_agents/plan/tests/actions/ -v   # 22 passed
   uv run --no-sync pytest flink_agents -k "not e2e_tests" -q    # all green
   ```
   
   ### API
   
   No public API change. The normalization is fully encapsulated in the 
existing tool-context helpers; callers and method signatures are unchanged.
   
   ### Documentation
   
   - [ ] `doc-needed`
   - [x] `doc-not-needed`
   - [ ] `doc-included`
   


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