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

   <!--
   * Thank you very much for contributing to Flink Agents.
   * Please add the relevant components in the PR title. E.g., [api], 
[runtime], [java], [python], [hotfix], etc.
   -->
   
   <!-- Please link the PR to the relevant issue(s). Hotfix doesn't need this. 
-->
   Linked issue: #1482
   
   ### Purpose of change
   
   <!-- What is the purpose of this change? -->
   
   A text prompt bound to a chat model setup is now sent as a SYSTEM message in 
Java, as it already is in Python, so the same agent sends the same conversation 
in both languages. As agreed in #1482, Java gets a 
`Prompt.formatMessages(Map<String, String> variables)` overload that uses 
`MessageRole.SYSTEM`, and `BaseChatModelSetup` uses it.
   
   #### Runtime flow
   
   1. `Prompt.formatMessages(variables)` delegates to 
`formatMessages(MessageRole.SYSTEM, variables)`.
   2. `BaseChatModelSetup.prepareRequestMessages` renders the bound prompt with 
the new overload instead of `formatMessages(MessageRole.USER, ...)`.
   3. `ReActAgent` still passes `MessageRole.USER` explicitly when it formats 
user input, and message-list templates keep their own roles.
   
   #### Key decisions
   
   * **A concrete overload, not abstract**, so existing `Prompt` subclasses 
keep compiling without implementing it.
   * `MCPPrompt` had a private `formatMessages(Map<String, Object>)` helper 
with the same erasure as the new public method; it is renamed 
`getPromptMessages`.
   * Python is unchanged: `format_messages` already defaults to 
`MessageRole.SYSTEM`. A Python test now pins that behavior next to the Java one.
   
   ### Behavioral Semantics
   
   <!-- For a non-trivial code change whose implementation is largely 
AI-assisted: interaction decisions, behavioral contracts, and failure behavior. 
See `contribution-guides/ai-assisted-pr.md`. Remove this heading and this 
comment otherwise. -->
   
   #### Behavioral contracts
   
   1. `Prompt.formatMessages(variables)` builds a text template as one SYSTEM 
message, and returns a message-list template with each message's own role.
   2. A chat model setup with a text prompt sends it as a SYSTEM message, 
followed by the request's messages, in Java and Python.
   3. A message-list prompt on a setup keeps its roles.
   
   #### Failure behavior
   
   No new failure paths. Java applications whose setup prompt is a text 
template now send it as a SYSTEM message instead of a USER message. A model 
that requires a USER message can use a message-list prompt with an explicit 
USER message.
   
   ### Tests
   
   <!-- How is this change verified? -->
   
   | Contract | Tests |
   |---|---|
   | 1 | 
`PromptTest.formatMessagesWithoutRoleBuildsTextTemplateAsSystemMessage` |
   | 2 | `BaseChatModelSetupPromptTest.textPromptIsSentAsSystemMessage`; Python 
`test_chat_model_base.py::test_text_prompt_is_sent_as_system_message` |
   | 3 | `BaseChatModelSetupPromptTest.messagesPromptKeepsItsRoles` |
   
   
`ChatModelActionEscalationTest.theVerifierSeesTheRenderedPromptTheCandidateReceived`
 now expects `SYSTEM:` for the candidate's rendered text prompt. The e2e 
assertions on `USER:` in the routing and escalation tests come from 
`ChatMessage.user(...)` inputs, not from a bound prompt, and are unaffected.
   
   Verified locally on main: Java `api` (962), `integrations/mcp` (43), `plan` 
(925) and the runtime chat-model setup tests, with spotless; Python 
`chat_models` and prompt tests, with ruff.
   
   ### API
   
   <!-- Does this change touches any public APIs? -->
   
   New: `Prompt.formatMessages(Map<String, String> variables)`. A user `Prompt` 
subclass that declares its own `formatMessages(Map<...>)` with a different 
value type would hit the same erasure clash as `MCPPrompt` and needs a rename.
   
   Behavior: a Java chat model setup's text prompt is now a SYSTEM message. 0.x 
makes no compatibility guarantee, and the change lands before 1.0.
   
   ### Documentation
   
   <!-- Do not remove this section. Check the proper box only. -->
   
   - [ ] `doc-needed` <!-- Your PR changes impact docs -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-included` <!-- Your PR already contains the necessary 
documentation updates -->
   
   The docs do not state which role a setup's text prompt takes.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   <!-- Do not remove this section. Check the proper box only. -->
   
   - [x] Yes
   - [ ] No
   
   If yes, include a `Generated-by: <tool name and version> (<model name and 
version>)` line, for example `Generated-by: Claude Code 2.1.226 (Claude Opus 
4.6)`, in the commit message so it reaches Git history. Repeat the same line 
here for reviewer visibility. See the [ASF generative tooling 
guidance](https://www.apache.org/legal/generative-tooling.html).
   
   Generated-by: Claude Code 2.1.259 (Claude Opus 5.5)
   


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