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