diff --git a/dbgpt/agent/core/action/base.py b/dbgpt/agent/core/action/base.py index 50b36af45..04733a13a 100644 --- a/dbgpt/agent/core/action/base.py +++ b/dbgpt/agent/core/action/base.py @@ -165,9 +165,9 @@ class Action(ABC, Generic[T]): json_format_data = json.dumps( self._create_example(self.out_model_type), indent=2, ensure_ascii=False ) - return f"""Please reply in the following json format: - {json_format_data} - Make sure the reply content only has correct json and can be parsed by Python json.loads.""" # noqa: E501 + return f"""Please reply strictly in the following json format: + {json_format_data} + Make sure the reply content only has the correct json.""" # noqa: E501 def _ai_message_2_json(self, ai_message: str) -> JsonMessageType: json_objects = find_json_objects(ai_message) diff --git a/dbgpt/serve/agent/agents/controller.py b/dbgpt/serve/agent/agents/controller.py index 78c63f711..02a5df7f1 100644 --- a/dbgpt/serve/agent/agents/controller.py +++ b/dbgpt/serve/agent/agents/controller.py @@ -189,7 +189,8 @@ class MultiAgents(BaseComponent, ABC): history_messages = gpts_messages last_message = gpts_messages[-1] message_round = last_message.rounds + 1 - from dbgpt.ant.agent.agents.app_start_assisant_agent import ( + + from dbgpt.serve.agent.agents.expand.app_start_assisant_agent import ( StartAppAssistantAgent, ) diff --git a/dbgpt/serve/agent/agents/expand/actions/app_link_action.py b/dbgpt/serve/agent/agents/expand/actions/app_link_action.py index 00ad8e8e6..51c851529 100644 --- a/dbgpt/serve/agent/agents/expand/actions/app_link_action.py +++ b/dbgpt/serve/agent/agents/expand/actions/app_link_action.py @@ -54,64 +54,39 @@ class LinkAppAction(Action[LinkAppInput]): content=ai_message, have_retry=False, ) - # version: int = 1, - version = kwargs.get("version", 1) - if version == 1: - if not param.app_code or len(param.app_code) <= 0: - return ActionOutput( - is_exe_success=False, - content="这个问题没有找到合适的解决方案", - view="这个问题没有找到合适的解决方案", - ) - else: - app_link_param = { - "app_code": param.app_code, - "app_name": param.app_name, - "app_desc": "", - "app_logo": "", - "status": "TODO", - } - return ActionOutput( - is_exe_success=True, - content=json.dumps(model_to_dict(param), ensure_ascii=False), - view=await self.render_protocal.display(content=app_link_param), - ) + if not param.app_code or len(param.app_code) <= 0: + app_link_param = { + "app_code": "Personal assistant", + "app_name": "Personal assistant", + "app_desc": "", + "app_logo": "", + "status": "TODO", + } + + from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent + + return ActionOutput( + is_exe_success=True, + content=json.dumps(app_link_param, ensure_ascii=False), + view=await self.render_protocal.display(content=app_link_param), + next_speakers=[SummaryAssistantAgent().role], + ) else: - if not param.app_code or len(param.app_code) <= 0: - app_link_param = { - "app_code": "Personal assistant", - "app_name": "Personal assistant", - "app_desc": "", - "app_logo": "", - "status": "TODO", - } + app_link_param = { + "app_code": param.app_code, + "app_name": param.app_name, + "app_desc": "", + "app_logo": "", + "status": "TODO", + } - from dbgpt.agent.expand.summary_assistant_agent import ( - SummaryAssistantAgent, - ) + from dbgpt.serve.agent.agents.expand.app_start_assisant_agent import ( + StartAppAssistantAgent, + ) - return ActionOutput( - is_exe_success=True, - content=json.dumps(app_link_param, ensure_ascii=False), - view=await self.render_protocal.display(content=app_link_param), - next_speakers=[SummaryAssistantAgent().role], - ) - else: - app_link_param = { - "app_code": param.app_code, - "app_name": param.app_name, - "app_desc": "", - "app_logo": "", - "status": "TODO", - } - - from dbgpt.serve.agent.agents.expand.app_start_assisant_agent import ( - StartAppAssistantAgent, - ) - - return ActionOutput( - is_exe_success=True, - content=json.dumps(model_to_dict(param), ensure_ascii=False), - view=await self.render_protocal.display(content=app_link_param), - next_speakers=[StartAppAssistantAgent().role], - ) + return ActionOutput( + is_exe_success=True, + content=json.dumps(model_to_dict(param), ensure_ascii=False), + view=await self.render_protocal.display(content=app_link_param), + next_speakers=[StartAppAssistantAgent().role], + ) diff --git a/dbgpt/serve/agent/agents/expand/actions/app_start_action.py b/dbgpt/serve/agent/agents/expand/actions/app_start_action.py index 4ee311685..1910a6f6f 100644 --- a/dbgpt/serve/agent/agents/expand/actions/app_start_action.py +++ b/dbgpt/serve/agent/agents/expand/actions/app_start_action.py @@ -22,6 +22,10 @@ class LinkAppInput(BaseModel): ..., description="The name of selected app.", ) + app_desc: Optional[str] = Field( + ..., + description="The new user input.", + ) class StartAppAction(Action[LinkAppInput]): @@ -45,7 +49,6 @@ class StartAppAction(Action[LinkAppInput]): need_vis_render: bool = True, **kwargs, ) -> ActionOutput: - user_input = kwargs.get("user_input") conv_id = kwargs.get("conv_id") paren_agent = kwargs.get("paren_agent") init_message_rounds = kwargs.get("init_message_rounds") @@ -58,7 +61,7 @@ class StartAppAction(Action[LinkAppInput]): is_exe_success=False, content="The requested correctly structured answer could not be found.", ) - + new_user_input = param.app_desc try: gpts_dao = GptsAppDao() gpts_app: GptsApp = gpts_dao.app_detail(param.app_code) @@ -72,7 +75,7 @@ class StartAppAction(Action[LinkAppInput]): if TeamMode.NATIVE_APP.value == gpts_app.team_mode: return ActionOutput( is_exe_success=False, - content="ai_message", + content=ai_message, view="[DBGPT Warning] Native application connection startup is not supported for the time being.", have_retry=False, ) @@ -80,7 +83,7 @@ class StartAppAction(Action[LinkAppInput]): from dbgpt.serve.agent.agents.controller import multi_agents await multi_agents.agent_team_chat_new( - user_input, + new_user_input, conv_id, gpts_app, paren_agent.memory, diff --git a/dbgpt/serve/agent/agents/expand/actions/intent_recognition_action.py b/dbgpt/serve/agent/agents/expand/actions/intent_recognition_action.py index 7f93023e3..993d361d4 100644 --- a/dbgpt/serve/agent/agents/expand/actions/intent_recognition_action.py +++ b/dbgpt/serve/agent/agents/expand/actions/intent_recognition_action.py @@ -57,7 +57,10 @@ class IntentRecognitionAction(Action[IntentRecognitionInput]): out_put_schema = { "intent": "[The recognized intent is placed here]", "app_code": "[App code in selected intent]", - "slots": "If the intent has a defined slot attribute, the slot attribute and value are output here", + "slots": { + "attribute name 1": "[The value of the slot attribute 1 in intent define]", + "attribute name 2": "[The value of the slot attribute 2 in intent define]", + }, "ask_user": "If you want the user to supplement slot data, ask the user a question", "user_input": "[Complete instructions generated based on intent and slot]", } @@ -70,6 +73,18 @@ class IntentRecognitionAction(Action[IntentRecognitionInput]): {json.dumps(out_put_schema, indent=2, ensure_ascii=False)} 确保输出只有json,且可以被python json.loads加载.""" + def _get_default_next_speakers(self): + next_speakers = [] + from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent + + next_speakers.append(SummaryAssistantAgent().role) + + from dbgpt.agent.expand.simple_assistant_agent import SimpleAssistantAgent + + next_speakers.append(SimpleAssistantAgent().role) + + return next_speakers + async def run( self, ai_message: str, @@ -78,6 +93,7 @@ class IntentRecognitionAction(Action[IntentRecognitionInput]): need_vis_render: bool = True, **kwargs, ) -> ActionOutput: + next_speakers = self._get_default_next_speakers() try: intent: IntentRecognitionInput = self._input_convert( ai_message, IntentRecognitionInput @@ -88,51 +104,38 @@ class IntentRecognitionAction(Action[IntentRecognitionInput]): is_exe_success=False, content="Error:The answer is not output in the required format.", have_retry=True, + next_speakers=next_speakers, ) # Check whether the message is complete and whether additional information needs to be provided to the user if intent.slots: for key, value in intent.slots.items(): if not value or len(value) <= 0: + logger.info("slots check, need additional information!") return ActionOutput( is_exe_success=False, content=json.dumps(intent.to_dict(), ensure_ascii=False), view=intent.ask_user if intent.ask_user else ai_message, have_retry=False, ask_user=True, + next_speakers=next_speakers, ) next_speakers = [] - if not intent.app_code or len(intent.app_code) <= 0: - from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent - - next_speakers.append(SummaryAssistantAgent().role) - - from dbgpt.agent.expand.simple_assistant_agent import SimpleAssistantAgent - - next_speakers.append(SimpleAssistantAgent().role) - - app_link_param = { - "app_code": "Personal assistant", - "app_name": "Personal assistant", - "app_desc": "", - "app_logo": "", - "status": "TODO", - } - else: + if intent.app_code and len(intent.app_code) > 0: from dbgpt.serve.agent.agents.expand.app_start_assisant_agent import ( StartAppAssistantAgent, ) next_speakers = [StartAppAssistantAgent().role] - app_link_param = { - "app_code": intent.app_code, - "app_name": intent.intent, - "app_desc": intent.user_input, - "app_logo": "", - "status": "TODO", - } + app_link_param = { + "app_code": intent.app_code, + "app_name": intent.intent, + "app_desc": intent.user_input, + "app_logo": "", + "status": "TODO", + } return ActionOutput( is_exe_success=True, content=json.dumps(app_link_param, ensure_ascii=False), diff --git a/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py b/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py index f6862a570..697f10696 100644 --- a/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py +++ b/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py @@ -42,21 +42,12 @@ class LinkAppAssistantAgent(ConversableAgent): key="dbgpt_ant_agent_agents_app_link_assistant_agent_profile_desc", ), ) - version: int = 2 stream_out: bool = False def __init__(self, **kwargs): super().__init__(**kwargs) self._init_actions([LinkAppAction]) - def prepare_act_param( - self, - recive_message: Optional[Dict], - sender: Agent, - rely_messages: Optional[List[Dict]] = None, - ) -> Optional[Dict]: - return {"version": self.version} - agent_manage = get_agent_manager() agent_manage.register_agent(LinkAppAssistantAgent) diff --git a/dbgpt/serve/agent/agents/expand/intent_recognition_agent.py b/dbgpt/serve/agent/agents/expand/intent_recognition_agent.py index 855de55e2..a33a7bbc5 100644 --- a/dbgpt/serve/agent/agents/expand/intent_recognition_agent.py +++ b/dbgpt/serve/agent/agents/expand/intent_recognition_agent.py @@ -45,13 +45,11 @@ CONSTRAINTS_EN = [ "to supplement the missing slot data.", ] CONSTRAINTS_ZH = [ - "根据用户输入信息,从给出的意图定义中进行选择匹配,无法匹配到任何意图'intent'和'app_code'都输出为空, 不要自行生成意图和槽位属性.", - "匹配选择到的意图没有定义槽位属性,确保输出json中也不要包含'slots'属性." - "从用户输入和历史对话信息中提取意图定义中槽位属性的值,如果无法获取到槽位属性对应的目标信息,则槽位值输出空.", + "根据用户输入信息,从给出的意图定义中进行选择匹配,无法匹配到任何意图'intent'和'app_code'都输出为空,不要输出任何未定义的意图.", + "请确保按意图定义输出槽位属性,不要自行创造任何槽位属性,如果意图定义没有槽位属性,则确保槽位输出位空" + "从用户输入和历史对话信息中提取意图定义中槽位属性的值,如果无法获取到槽位属性的值,则确保槽位值输出空,不要在槽位值里输出提示或者描述信息,不要出现类似'用户未提供'这样的内容.", "槽位值提取时请注意只获取有效值部分,不要填入辅助描述或定语", - "确保意图定义的槽位属性不管是否获取到值,都要输出全部定义给出的槽位属性,没有找到值的输出槽位名和空值.", - "请确保如果用户问题中未提供意图槽位定义的内容,则槽位值必须为空,不要在槽位值里填‘用户未提供’这类无效信息.", - "如果用户问题内容提取的信息和匹配到的意图槽位无法完全对应,则生成新的问题向用户提问,提示用户补充缺少的槽位数据.", + "如果无法收集到完整的意图定义的槽位属性的值,主动像用户发起提示,提醒用户补充缺槽位数据.", ] RETRY_CONSTRAINTS_EN = [