Zhuoxi2000 opened a new issue, #1480:
URL: https://github.com/apache/flink-agents/issues/1480

   ### Search before asking
   
   - [x] I searched in the 
[issues](https://github.com/apache/flink-agents/issues) and found nothing 
similar.
   
   ### Description
   
   Python `Prompt.format_messages(role=MessageRole.SYSTEM, **kwargs)` takes the 
message role as a keyword parameter, so a template variable named `role` can 
never reach the template:
   
   - A text prompt fails: `Prompt.from_text("You are 
{role}.").format_messages(role="a pirate")` raises a `ValidationError` for 
`ChatMessage`, because `"a pirate"` is used as the message role.
   - A messages prompt leaves `{role}` unsubstituted: the value is consumed as 
the role argument.
   - `ReActAgent` fails with `TypeError: format_messages() got multiple values 
for keyword argument 'role'` when its input has a `role` field, since it calls 
`format_messages(role=MessageRole.USER, **input)` (`react_agent.py`).
   - A chat model setup's `prompt_args={"role": ...}` reaches 
`format_messages(**prompt_args)` (`chat_model.py`) and hits the first two cases.
   
   Java's `formatMessages(MessageRole defaultRole, Map<String, String> kwargs)` 
keeps the role separate from the variables, and the `Prompt` Javadoc example 
itself uses a `{role}` variable, so only Python is affected.
   
   Expected: `role` is an ordinary template variable, as in Java.
   
   ### How to reproduce
   
   ```python
   from flink_agents.api.chat_message import ChatMessage
   from flink_agents.api.prompts.prompt import Prompt
   
   Prompt.from_text("You are {role}.").format_messages(role="a pirate")
   # ValidationError: 1 validation error for ChatMessage
   
   Prompt.from_messages([ChatMessage.system("You are 
{role}.")]).format_messages(role="a pirate")
   # [system: "You are {role}."]
   ```
   
   ### Version and environment
   
   main at 0f83f4b9, Python 3.11, macOS.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


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