diff --git a/dbgpt/agent/core/memory/gpts/gpts_memory.py b/dbgpt/agent/core/memory/gpts/gpts_memory.py index 876413b6e..e779efafd 100644 --- a/dbgpt/agent/core/memory/gpts/gpts_memory.py +++ b/dbgpt/agent/core/memory/gpts/gpts_memory.py @@ -305,8 +305,14 @@ class GptsMemory: none_goal_count = 1 for message in messages: - if message.sender == "AppLink" or message.receiver == "AppLink": - if message.sender == "AppLink" and message.receiver == "AppLauncher": + if ( + message.sender == "Intent Recognition Expert" + or message.receiver == "Intent Recognition Expert" + ): + if ( + message.sender == "Intent Recognition Expert" + and message.receiver == "AppLauncher" + ): app_link_message = message if message.receiver != "Human": continue @@ -316,10 +322,6 @@ class GptsMemory: app_lanucher_message = message continue - # if len(app_link_message) <= 0: - # count = count + 1 - # if count == 1: - # continue current_gogal = message.current_goal last_goal = next(reversed(temp_group)) if temp_group else None diff --git a/dbgpt/agent/expand/data_scientist_agent.py b/dbgpt/agent/expand/data_scientist_agent.py index ddd04f278..d63dc2a52 100644 --- a/dbgpt/agent/expand/data_scientist_agent.py +++ b/dbgpt/agent/expand/data_scientist_agent.py @@ -69,7 +69,7 @@ class DataScientistAgent(ConversableAgent): ), ) - max_retry_count: int = 3 + max_retry_count: int = 5 language: str = "zh" def __init__(self, **kwargs): diff --git a/dbgpt/core/awel/flow/base.py b/dbgpt/core/awel/flow/base.py index fb60538ba..cd8d9f78e 100644 --- a/dbgpt/core/awel/flow/base.py +++ b/dbgpt/core/awel/flow/base.py @@ -505,6 +505,8 @@ class Parameter(TypeMetadata, Serializable): ): # Resource type can have multiple parameters. resource_id = view_value + if resource_id not in resources: + return {self.name: None} resource_metadata = resources[resource_id] # Check the type. resource_type = _get_type_cls(resource_metadata.type_cls) diff --git a/dbgpt/serve/agent/agents/expand/actions/app_link_action.py b/dbgpt/serve/agent/agents/expand/actions/app_link_action.py new file mode 100644 index 000000000..00ad8e8e6 --- /dev/null +++ b/dbgpt/serve/agent/agents/expand/actions/app_link_action.py @@ -0,0 +1,117 @@ +import json +import logging +from typing import Any, Dict, List, Optional, Union + +from dbgpt._private.pydantic import BaseModel, Field, model_to_dict +from dbgpt.agent import Action, ActionOutput, AgentResource, ResourceType +from dbgpt.vis.tags.vis_app_link import Vis, VisAppLink + +logger = logging.getLogger(__name__) + + +class LinkAppInput(BaseModel): + app_code: Optional[str] = Field( + ..., + description="The code of selected app.", + ) + app_name: Optional[str] = Field( + ..., + description="The name of selected app.", + ) + + +class LinkAppAction(Action[LinkAppInput]): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self._render_protocal = VisAppLink() + + @property + def resource_need(self) -> Optional[ResourceType]: + return ResourceType.Knowledge + + @property + def render_protocal(self) -> Optional[Vis]: + return self._render_protocal + + @property + def out_model_type(self): + return LinkAppInput + + async def run( + self, + ai_message: str, + resource: Optional[AgentResource] = None, + rely_action_out: Optional[ActionOutput] = None, + need_vis_render: bool = True, + **kwargs, + ) -> ActionOutput: + try: + param: LinkAppInput = self._input_convert(ai_message, LinkAppInput) + except Exception as e: + logger.warning(str(e)) + return ActionOutput( + is_exe_success=False, + 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), + ) + 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", + } + + 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: + 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], + ) 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 4665c3d76..4ee311685 100644 --- a/dbgpt/serve/agent/agents/expand/actions/app_start_action.py +++ b/dbgpt/serve/agent/agents/expand/actions/app_start_action.py @@ -1,6 +1,7 @@ import logging from typing import Optional +from dbgpt._private.pydantic import BaseModel, Field, model_to_dict from dbgpt.agent import Action, ActionOutput, AgentResource from dbgpt.serve.agent.agents.expand.actions.intent_recognition_action import ( IntentRecognitionInput, @@ -12,7 +13,18 @@ from dbgpt.vis.tags.vis_plugin import Vis, VisPlugin logger = logging.getLogger(__name__) -class StartAppAction(Action[IntentRecognitionInput]): +class LinkAppInput(BaseModel): + app_code: Optional[str] = Field( + ..., + description="The code of selected app.", + ) + app_name: Optional[str] = Field( + ..., + description="The name of selected app.", + ) + + +class StartAppAction(Action[LinkAppInput]): def __init__(self, **kwargs): super().__init__(**kwargs) self._render_protocal = VisPlugin() @@ -39,9 +51,7 @@ class StartAppAction(Action[IntentRecognitionInput]): init_message_rounds = kwargs.get("init_message_rounds") try: - param: IntentRecognitionInput = self._input_convert( - ai_message, IntentRecognitionInput - ) + param: LinkAppInput = self._input_convert(ai_message, LinkAppInput) except Exception as e: logger.exception(str(e)) return ActionOutput( @@ -56,7 +66,7 @@ class StartAppAction(Action[IntentRecognitionInput]): return ActionOutput( is_exe_success=False, content=ai_message, - view=f"[DBGPT Warning] Intent definition application cannot be found [{param.app_code}]{param.intent}", + view=f"[DBGPT Warning] Intent definition application cannot be found [{param.app_code}]{param.app_name}", have_retry=False, ) if TeamMode.NATIVE_APP.value == gpts_app.team_mode: 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 b37010a7e..f86ac6fb8 100644 --- a/dbgpt/serve/agent/agents/expand/actions/intent_recognition_action.py +++ b/dbgpt/serve/agent/agents/expand/actions/intent_recognition_action.py @@ -67,11 +67,11 @@ class IntentRecognitionAction(Action[IntentRecognitionInput]): if self.language == "en": return f"""Please reply in the following json format: {json.dumps(out_put_schema, indent=2, ensure_ascii=False)} - Make sure the reply content only has correct json and can be parsed by Python json.loads.""" # noqa: E501 + Make sure the output is only json and can be parsed by Python json.loads.""" # noqa: E501 else: return f"""请按如下JSON格式输出: {json.dumps(out_put_schema, indent=2, ensure_ascii=False)} - 确保只输出json,且可以被python json.loads加载.""" + 确保输出只有json,且可以被python json.loads加载.""" async def run( self, @@ -105,15 +105,40 @@ class IntentRecognitionAction(Action[IntentRecognitionInput]): ask_user=True, ) - app_link_param = { - "app_code": intent.app_code, - "app_name": intent.intent, - "app_desc": intent.user_input, - "app_logo": "", - "status": "TODO", - } + 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: + 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", + } + return ActionOutput( is_exe_success=True, - content=json.dumps(intent.to_dict(), ensure_ascii=False), + content=json.dumps(app_link_param, ensure_ascii=False), view=await self.render_protocal.display(content=app_link_param), + next_speakers=next_speakers, ) diff --git a/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py b/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py new file mode 100644 index 000000000..f6862a570 --- /dev/null +++ b/dbgpt/serve/agent/agents/expand/app_link_assisant_agent.py @@ -0,0 +1,62 @@ +import logging +from typing import Dict, List, Optional + +from dbgpt.agent import Agent, ConversableAgent, get_agent_manager +from dbgpt.agent.core.profile import DynConfig, ProfileConfig +from dbgpt.serve.agent.agents.expand.actions.app_link_action import LinkAppAction + +logger = logging.getLogger() + + +class LinkAppAssistantAgent(ConversableAgent): + profile: ProfileConfig = ProfileConfig( + name=DynConfig( + "dbgpt", + category="agent", + key="dbgpt_ant_agent_agents_app_link_assistant_agent_profile_name", + ), + role=DynConfig( + "App Selector", + category="agent", + key="dbgpt_ant_agent_agents_app_link_assistant_agent_profile_role", + ), + goal=DynConfig( + "根据用户的问题和提供的应用信息,选择一个合适的应用来解决和回答用户的问题,并提取用户输入的关键信息到应用意图的槽位中。", + category="agent", + key="dbgpt_ant_agent_agents_app_link_assistant_agent_profile_goal", + ), + constraints=DynConfig( + [ + "请一步一步思考参为用户问题选择一个最匹配的应用来进行用户问题回答,可参考给出示例的应用选择逻辑.", + "请阅读用户问题,确定问题所属领域和问题意图,按领域和意图匹配应用,如果用户问题意图缺少操作类应用需要的参数,优先使用咨询类型应用,有明确操作目标才使用操作类应用.", + "仅选择可回答问题的应用即可,不要直接回答用户问题.", + "如果用户的问题和提供的所有应用全都不相关,则应用code和name都输出为空", + "注意应用意图定义中如果有槽位信息,再次阅读理解用户输入信息,将对应的内容填入对应槽位参数定义中.", + ], + category="agent", + key="dbgpt_ant_agent_agents_app_link_assistant_agent_profile_constraints", + ), + desc=DynConfig( + "根据用户问题匹配合适的应用来进行回答.", + category="agent", + 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 ddf56117b..8a3d77800 100644 --- a/dbgpt/serve/agent/agents/expand/intent_recognition_agent.py +++ b/dbgpt/serve/agent/agents/expand/intent_recognition_agent.py @@ -9,11 +9,11 @@ from dbgpt.serve.agent.agents.expand.actions.intent_recognition_action import ( logger = logging.getLogger() GOAL_EN = ( - "Understand the user input information, select an intention that best matches " - "the user input from the intention definition of the known information, and " - "extract the information and output the complete intention information as required." + "Understand the user input information, select an intention that best matches the " + "user input from the intention definition of the known information, and output the " + "intention information as required." ) -GOAL_ZH = "理解用户输入信息,从已知信息的意图定义中选择一个和用户输入最匹配的意图,并按要求提取信息输出完整意图信息." +GOAL_ZH = "理解用户输入信息,从已知信息的意图定义中选择一个和用户输入最匹配的意图,并按要求输出意图信息." RETRY_GOAL_EN = ( "Read the content of the recent messages provided by the following users, " @@ -24,8 +24,10 @@ RETRY_GOAL_EN = ( RETRY_GOAL_ZH = "阅读下面用户提供的最近消息内容,并把当前用户输入信息提取补充到最近消息中的意图信息里,并返回补充后的意图信息。" CONSTRAINTS_EN = [ - "Strictly define the output based on the given intent. Do not generate the intent and slot " - "attributes by yourself. If the intent does not define a slot, the output should not include the slot.", + "Strictly define the output based on the given intention. Do not generate intention and slots " + "attributes by yourself. ", + "The intent selected by the match does not have a slot attribute defined, so ensure that the " + "output does not contain slot information either.", "Extract the value of the slot attribute in the intent definition from user input and historical " "dialogue information. If the target information corresponding to the slot attribute cannot be " "obtained, the slot value output is empty.", @@ -42,7 +44,8 @@ CONSTRAINTS_EN = [ "to supplement the missing slot data.", ] CONSTRAINTS_ZH = [ - "严格根给出的意图定义输出,不要自行生成意图和槽位属性,意图没有定义槽位则输出也不应该包含槽位.", + "严格根给出的意图定义输出,不要自行生成意图和槽位属性", + "匹配选择到的意图没有定义槽位属性,确保输出也不要包含槽位信息." "从用户输入和历史对话信息中提取意图定义中槽位属性的值,如果无法获取到槽位属性对应的目标信息,则槽位值输出空.", "槽位值提取时请注意只获取有效值部分,不要填入辅助描述或定语", "确保意图定义的槽位属性不管是否获取到值,都要输出全部定义给出的槽位属性,没有找到值的输出槽位名和空值.", @@ -115,6 +118,7 @@ class IntentRecognitionAgent(ConversableAgent): ) stream_out: bool = False + language: str = "zh" def __init__(self, **kwargs): super().__init__(**kwargs) diff --git a/web_new/client/api/user/index.ts b/web_new/client/api/user/index.ts index 2d522ee1f..dde420b9c 100644 --- a/web_new/client/api/user/index.ts +++ b/web_new/client/api/user/index.ts @@ -9,5 +9,5 @@ interface Props { * 查询管理员列表 */ export const queryAdminList = (data: Props) => { - return GET(`/api/v1/users`, data); + return []; };