Sxnan opened a new issue, #284: URL: https://github.com/apache/flink-agents/issues/284
### Search before asking - [x] I searched in the [issues](https://github.com/apache/flink-agents/issues) and found nothing similar. ### Description We see the following exception when the Tongyi model uses a tool: ``` --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) Cell In[2], line 1 ----> 1 run_flink_agent_demo() File ~/work/repo/vvp-ai/flink_agent_demo.py:51, in run_flink_agent_demo() 48 print("š Executing pipeline...") 49 print("=" * 60) ---> 51 env.execute() 53 print("\nšÆ Execution Results:") 54 print("=" * 60) File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/runtime/local_execution_environment.py:131, in LocalExecutionEnvironment.execute(self) 129 self.__executed = True 130 for input in self.__input: --> 131 self.__runner.run(**input) 132 outputs = self.__runner.get_outputs() 133 for output in outputs: File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/runtime/local_runner.py:251, in LocalRunner.run(self, **data) 249 logger.info("key: %s, performing action: %s", key, action.name) 250 context.action_name = action.name --> 251 func_result = action.exec(event, context) 252 if isinstance(func_result, Generator): 253 try: File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/plan/function.py:217, in PythonFunction.__call__(self, *args, **kwargs) 194 def __call__(self, *args: Tuple[Any, ...], **kwargs: Dict[str, Any]) -> Any: 195 """Execute the stored function with provided arguments. 196 197 Lazily loads the function from its module and qualified name if not already (...) 215 resolve the method from the corresponding class. 216 """ --> 217 return self.__get_func()(*args, **kwargs) File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/plan/actions/chat_model_action.py:153, in process_chat_request_or_tool_response(event, ctx) 142 tool_call_context[initial_request_id].append( 143 ChatMessage( 144 role=MessageRole.TOOL, (...) 149 ) 150 ) 151 short_term_memory.set(_TOOL_CALL_CONTEXT, tool_call_context) --> 153 chat( 154 initial_request_id=initial_request_id, 155 model=model, 156 messages=tool_call_context[initial_request_id], 157 ctx=ctx, 158 ) File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/plan/actions/chat_model_action.py:55, in chat(initial_request_id, model, messages, ctx) 50 chat_model = cast( 51 "BaseChatModelSetup", ctx.get_resource(model, ResourceType.CHAT_MODEL) 52 ) 54 # TODO: support async execution of chat. ---> 55 response = chat_model.chat(messages) 56 short_term_memory = ctx.short_term_memory 58 # generate tool request event according tool calls in response File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/api/chat_models/chat_model.py:207, in BaseChatModelSetup.chat(self, messages, **kwargs) 205 merged_kwargs = self.model_kwargs.copy() 206 merged_kwargs.update(kwargs) --> 207 return connection.chat(messages, tools=tools, **merged_kwargs) File ~/work/repo/vvp-ai/.venv/lib/python3.11/site-packages/flink_agents/integrations/chat_models/tongyi_chat_model.py:128, in TongyiChatModelConnection.chat(self, messages, tools, **kwargs) 126 if getattr(response, "status_code", 200) != 200: 127 msg = f"DashScope call failed: {getattr(response, 'message', 'unknown error')}" --> 128 raise RuntimeError(msg) 130 choice = response.output["choices"][0] 131 response_message: Dict[str, Any] = choice["message"] RuntimeError: DashScope call failed: <400> InternalError.Algo.InvalidParameter: messages with role "tool" must be a response to a preceeding message with "tool_calls". ``` ### How to reproduce Run the quickstart example with a Tongyi model ### Version and environment Flink Agents 0.1.0 Flink 1.20.3 ### Are you willing to submit a PR? - [ ] 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]
