Fix bugs
This commit is contained in:
@@ -55,7 +55,16 @@ class Environment:
|
|||||||
self.functions[func.get_name()] = func
|
self.functions[func.get_name()] = func
|
||||||
|
|
||||||
def get_ai_function(self,func_name:str) -> AIFunction:
|
def get_ai_function(self,func_name:str) -> AIFunction:
|
||||||
return self.functions.get(func_name)
|
func = self.functions.get(func_name)
|
||||||
|
if func is not None:
|
||||||
|
return func
|
||||||
|
|
||||||
|
for owner_env in self.owner_env.values():
|
||||||
|
func = owner_env.get_ai_function(func_name)
|
||||||
|
if func is not None:
|
||||||
|
return func
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
#def enable_ai_function(self,func_name:str) -> None:
|
#def enable_ai_function(self,func_name:str) -> None:
|
||||||
# pass
|
# pass
|
||||||
@@ -64,7 +73,11 @@ class Environment:
|
|||||||
# pass
|
# pass
|
||||||
|
|
||||||
def get_all_ai_functions(self) -> List[AIFunction]:
|
def get_all_ai_functions(self) -> List[AIFunction]:
|
||||||
return self.functions.values()
|
func_list = []
|
||||||
|
func_list.extend(self.functions.values())
|
||||||
|
for owner_env in self.owner_env.values():
|
||||||
|
func_list.extend(owner_env.get_all_ai_functions())
|
||||||
|
return func_list
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _do_get_value(self,key:str) -> Optional[str]:
|
def _do_get_value(self,key:str) -> Optional[str]:
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class AIRole:
|
|||||||
self.introduce = intro_node
|
self.introduce = intro_node
|
||||||
|
|
||||||
history_node = config.get("history_len")
|
history_node = config.get("history_len")
|
||||||
if history_node:
|
if history_node is not None:
|
||||||
self.history_len = int(history_node)
|
self.history_len = int(history_node)
|
||||||
|
|
||||||
if config.get("enable_function") is not None:
|
if config.get("enable_function") is not None:
|
||||||
@@ -78,4 +78,3 @@ class AIRoleGroup:
|
|||||||
def get(self,role_name:str) -> AIRole:
|
def get(self,role_name:str) -> AIRole:
|
||||||
return self.roles.get(role_name)
|
return self.roles.get(role_name)
|
||||||
|
|
||||||
|
|
||||||
@@ -254,8 +254,8 @@ class Workflow:
|
|||||||
def check_args(func_item:FunctionItem):
|
def check_args(func_item:FunctionItem):
|
||||||
match func_name:
|
match func_name:
|
||||||
case "send_msg":# sendmsg($target_id,$msg_content)
|
case "send_msg":# sendmsg($target_id,$msg_content)
|
||||||
if len(func_args) != 1:
|
if len(func_item.args) != 1:
|
||||||
logger.error(f"parse sendmsg failed! {func_call}")
|
logger.error(f"parse sendmsg failed! {func_item}")
|
||||||
return False
|
return False
|
||||||
new_msg = AgentMsg()
|
new_msg = AgentMsg()
|
||||||
target_id = func_item.args[0]
|
target_id = func_item.args[0]
|
||||||
@@ -266,8 +266,8 @@ class Workflow:
|
|||||||
is_need_wait = True
|
is_need_wait = True
|
||||||
|
|
||||||
case "post_msg":# postmsg($target_id,$msg_content)
|
case "post_msg":# postmsg($target_id,$msg_content)
|
||||||
if len(func_args) != 1:
|
if len(func_item.args) != 1:
|
||||||
logger.error(f"parse postmsg failed! {func_call}")
|
logger.error(f"parse postmsg failed! {func_item}")
|
||||||
return False
|
return False
|
||||||
new_msg = AgentMsg()
|
new_msg = AgentMsg()
|
||||||
target_id = func_item.args[0]
|
target_id = func_item.args[0]
|
||||||
@@ -381,7 +381,7 @@ class Workflow:
|
|||||||
if the_role.enable_function_list is not None:
|
if the_role.enable_function_list is not None:
|
||||||
if len(the_role.enable_function_list) > 0:
|
if len(the_role.enable_function_list) > 0:
|
||||||
if func_name not in the_role.enable_function_list:
|
if func_name not in the_role.enable_function_list:
|
||||||
logger.debug(f"agent {self.agent_id} ignore inner func:{func_name}")
|
logger.debug(f"agent {the_role.agent.agent_id} ignore inner func:{func_name}")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
@@ -410,6 +410,7 @@ class Workflow:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
result_str = f"execute {func_name} error:{str(e)}"
|
result_str = f"execute {func_name} error:{str(e)}"
|
||||||
logger.error(f"llm execute inner func:{func_name} error:{e}")
|
logger.error(f"llm execute inner func:{func_name} error:{e}")
|
||||||
|
logger.exception(e)
|
||||||
|
|
||||||
|
|
||||||
inner_functions = self._get_inner_functions(the_role)
|
inner_functions = self._get_inner_functions(the_role)
|
||||||
@@ -442,7 +443,7 @@ class Workflow:
|
|||||||
|
|
||||||
|
|
||||||
prompt = AgentPrompt()
|
prompt = AgentPrompt()
|
||||||
prompt.append(the_role.agent.prompt)
|
prompt.append(the_role.agent.agent_prompt)
|
||||||
prompt.append(self.get_workflow_rule_prompt())
|
prompt.append(self.get_workflow_rule_prompt())
|
||||||
prompt.append(the_role.get_prompt())
|
prompt.append(the_role.get_prompt())
|
||||||
# prompt.append(self._get_function_prompt(the_role.get_name()))
|
# prompt.append(self._get_function_prompt(the_role.get_name()))
|
||||||
|
|||||||
Reference in New Issue
Block a user