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

   <!--
   * 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: #1480
   
   ### Purpose of change
   
   <!-- What is the purpose of this change? -->
   
   In Python, a prompt template variable named `role` now reaches the template, 
as it does in Java. `Prompt.format_messages` took the message role as a keyword 
parameter, so `role="..."` was used as the message role: a text prompt failed 
with a `ValidationError`, a messages prompt left `{role}` unsubstituted, and 
`ReActAgent` failed with `TypeError: got multiple values for keyword argument 
'role'` when its input had a `role` field.
   
   #### Runtime flow
   
   1. `format_messages(role=MessageRole.SYSTEM, /, **kwargs)`: the role is 
positional-only, so every keyword argument, including `role`, is a template 
variable.
   2. A `MessageRole` passed as the `role` keyword raises `TypeError` instead 
of silently becoming a template variable.
   3. `ReActAgent` passes `MessageRole.USER` positionally.
   
   #### Key decisions
   
   * **Positional-only, like Java.** Java's `formatMessages(MessageRole 
defaultRole, Map<String, String> kwargs)` already keeps the role apart from the 
variables; its Javadoc example uses `{role}`.
   * **Fail on the old call style.** Without the check, an existing 
`format_messages(role=MessageRole.USER, ...)` call would keep running with the 
default role. Rejecting a `MessageRole` value under the `role` keyword turns 
that into an explicit error; a string `role` is a template value.
   * Applied to every implementation: `LocalPrompt`, `MCPPrompt` and the Java 
prompt wrapper.
   
   ### 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. `format_messages(**{"role": "a pirate"})` substitutes `{role}` in text 
and messages prompts.
   2. `format_messages(MessageRole.USER, ...)` sets the role of a text prompt's 
message, as before.
   3. `format_messages(role=MessageRole.USER, ...)` raises `TypeError` naming 
the positional form.
   
   #### Failure behavior
   
   * Old keyword-style callers fail on the first call with a `TypeError`, 
before any message is built.
   
   ### Tests
   
   <!-- How is this change verified? -->
   
   | Contract | `test_prompt.py` |
   |---|---|
   | 1, 2 | `test_role_template_variable_in_text_prompt`, 
`test_role_template_variable_in_messages_prompt` |
   | 3 | `test_message_role_passed_by_keyword_fails` |
   
   `test_mcp.py::test_mcp` now passes the role positionally and passes against 
a local MCP server. Verified locally on main: `flink_agents/api`, `plan/tests` 
and `integrations/mcp` (1951 passed; the 13 failures also fail on main and come 
from optional SDKs not installed locally), with ruff.
   
   ### API
   
   <!-- Does this change touches any public APIs? -->
   
   `Prompt.format_messages` takes `role` positionally only. Calls that pass it 
by keyword raise `TypeError` and must pass it positionally, as in Java. 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 show `format_messages` with a role argument.
   
   ### 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