Browse Source

Update message_reply_agent: output multimodal message

StrayWarrior 3 months ago
parent
commit
348a385417
1 changed files with 13 additions and 10 deletions
  1. 13 10
      pqai_agent/agents/message_reply_agent.py

+ 13 - 10
pqai_agent/agents/message_reply_agent.py

@@ -79,10 +79,10 @@ QUERY_PROMPT_TEMPLATE = """现在,请以客服的角色分析以下会话并
 注意对话信息的格式为: [角色][时间][消息类型]对话内容
 注意分析客服和用户当前的社交阶段,先确立对话的目的。
 注意一定要分析对话信息中的时间,避免和当前时间段不符的内容!注意一定要结合历史的对话情况进行分析和问候方式的选择!
-使用message_notify_user发送最终的回复内容,调用时不要传入除了回复内容外的其它任何信息
+请调用output_multimodal_message工具发送最终的消息,如果有多条消息需要发送,可以多次调用output_multimodal_message,请务必保证所有内容都通过output_multimodal_message发出
 请注意这是微信聊天,如果用户使用了表情包,请使用analyse_image描述表情包,并分析其含义和情绪,如果要回复请尽量用简短的emoji或文字进行回复。
-如果用户连续2次以上感到疑惑,请先发送<人工介入>,后接你认为需要人工介入的原因。如果判断对话可自然结束、无需再回复用户,请发送<结束>。如果用户表现出强烈的负向情绪、要求不再对话,请发送<负向情绪结束>。
-以上特殊消息的发送请使用message_notify_user。
+特殊情况:如果用户连续2次以上感到疑惑,请先发送<人工介入>,后接你认为需要人工介入的原因。如果判断对话可自然结束、无需再回复用户,请发送<结束>。如果用户表现出强烈的负向情绪、要求不再对话,请发送<负向情绪结束>。
+以上特殊消息的发送请使用message_notify_user。
 Now, start to process your task. Please think step by step.
  """
 
@@ -101,14 +101,15 @@ class MessageReplyAgent(SimpleOpenAICompatibleChatAgent):
         ])
         super().__init__(model, system_prompt, tools, generate_cfg, max_run_step)
 
-    def generate_message(self, context: Dict, dialogue_history: List[Dict]) -> str:
+    def generate_message(self, context: Dict, dialogue_history: List[Dict]) -> List[Dict]:
         formatted_dialogue = MessageReplyAgent.compose_dialogue(dialogue_history)
         query = QUERY_PROMPT_TEMPLATE.format(**context, dialogue_history=formatted_dialogue)
         self.run(query)
-        for tool_call in reversed(self.tool_call_records):
-            if tool_call['name'] == MessageNotifier.message_notify_user.__name__:
-                return tool_call['arguments']['message']
-        return ''
+        result = []
+        for tool_call in self.tool_call_records:
+            if tool_call['name'] == MessageNotifier.output_multimodal_message.__name__:
+                result.append(tool_call['arguments']['message'])
+        return result
 
     @staticmethod
     def compose_dialogue(dialogue: List[Dict]) -> str:
@@ -130,6 +131,8 @@ class DummyMessageReplyAgent(MessageReplyAgent):
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
 
-    def generate_message(self, context: Dict, dialogue_history: List[Dict]) -> str:
+    def generate_message(self, context: Dict, dialogue_history: List[Dict]) -> List[Dict]:
         logger.debug(f"DummyMessageReplyAgent.generate_message called, context: {context}")
-        return "测试消息: {agent_name} -> {nickname}".format(**context)
+        result = [{"type": "text", "content": "测试消息: {agent_name} -> {nickname}".format(**context)},
+                  {"type": "image", "content": "https://example.com/test_image.jpg"}]
+        return result