fix workflow bug.

This commit is contained in:
Liu Zhicong
2023-09-27 00:13:34 -07:00
parent 943d0e3916
commit 594901df90
2 changed files with 19 additions and 25 deletions
+2 -2
View File
@@ -19,8 +19,8 @@ fullname = "Ada Zhang"
agent="math_teacher"
[[roles."小学老师".prompt]]
role="system"
content="""现在时间是:{now}你在学校任职,担任小学老师。学校由 小学老师、初中老师、高中老师、教导处主任 组成。
你的任何处理结果,都要用下面方式汇报给给教导处主任
content="""你在学校任职,担任小学老师。学校由 小学老师、初中老师、高中老师、教导处主任 组成。
你的任何处理结果,都要用下面方式汇报给给教导处主任,并根据教导处主任的指示,产生最终回复
```
##/send_msg 教导处主任
处理结果
+15 -21
View File
@@ -191,19 +191,19 @@ class Workflow:
else:
return result_str
async def _process_msg(self,msg:AgentMsg):
async def _process_msg(self,msg:AgentMsg) -> AgentMsg:
real_target = msg.target.split(".")[0]
targets = self._parse_msg_target(msg.target)
if len(targets) > 1:
return await self._forword_msg(targets,msg)
#0 we don't support workflow join a group right now, this cloud be a feture in future
if msg.mentions is not None:
logger.warn(f"workflow {self.workflow_id} recv a group chat message,not support ignore!")
return None
error_resp = msg.create_error_resp(f"workflow {self.workflow_id} recv a group chat message,not support ignore!")
return error_resp
#1. workflow start process message
final_result = None
# this is workflow's group_chat session
session_topic = msg.sender + "#" + msg.topic
chatsesssion = AIChatSession.get_session(self.workflow_id,session_topic,self.db_file)
@@ -233,8 +233,10 @@ class Workflow:
logger.error(f"input_filter return None for :{msg.body}")
return None
logger.error(f"{self.workflow_id}:no role can process this msg:{msg.body}")
return final_result
err_str = f"{self.workflow_id}:no role can process this msg:{msg.body}"
logger.error(err_str)
error_resp = msg.create_error_resp(err_str)
return error_resp
@classmethod
def prase_llm_result(cls,llm_result_str:str)->LLMResult:
@@ -432,7 +434,7 @@ class Workflow:
def _is_in_same_workflow(self,msg) -> bool:
pass
async def role_process_msg(self,msg:AgentMsg,the_role:AIRole,workflow_chat_session:AIChatSession):
async def role_process_msg(self,msg:AgentMsg,the_role:AIRole,workflow_chat_session:AIChatSession) -> AgentMsg:
msg.target = the_role.get_role_id()
@@ -473,7 +475,7 @@ class Workflow:
error_resp = msg.create_error_resp(result_str)
return error_resp
result = Workflow.prase_llm_result(result_str)
result : LLMResult = Workflow.prase_llm_result(result_str)
for postmsg in result.post_msgs:
postmsg.prev_msg_id = msg.get_msg_id()
# might be craete a new msg.topic for this postmsg
@@ -507,14 +509,13 @@ class Workflow:
#await self.get_bus().resp_message(resp_msg)
return resp_msg
case "waiting":
# TODO: Use role:"function" would be better
for sendmsg in result.send_msgs:
target = sendmsg.target
sendmsg.topic = msg.topic
sendmsg.prev_msg_id = msg.get_msg_id()
send_resp = await self.role_send_msg(sendmsg,the_role,workflow_chat_session)
if send_resp is not None:
result_prompt_str += f"\n{target} response is :{send_resp.body}"
result_prompt_str += f"\n# {target} response is : \n{send_resp.body}"
if not self._is_in_same_workflow(sendmsg):
role_sesion = AIChatSession.get_session(the_role.get_role_id(),f"{sendmsg.target}#{sendmsg.topic}",self.db_file)
@@ -524,21 +525,14 @@ class Workflow:
# message will be saved in role.process_message
pass
for call in result.calls:
action_msg = msg.create_action_msg(call[0],call[1],call_result,the_role.get_role_id)
call_result = await self.role_call(call,the_role)
if call_result is not None:
result_prompt_str += f"\ncall {call[0]} result is :{call_result}"
#save action
action_msg.result_str = call_result
workflow_chat_session.append(action_msg)
this_llm_resp_prompt = AgentPrompt()
this_llm_resp_prompt.messages = [{"role":"assistant","content":result_str}]
prompt.append(this_llm_resp_prompt)
result_prompt = AgentPrompt()
result_prompt.messages = [{"role":"user","content":result_prompt_str}]
prompt.append(result_prompt)
r = await _do_process_msg()
return r
return await _do_process_msg()
return await _do_process_msg()