Add feature: Agent/Role enable_function config.
This commit is contained in:
@@ -2,6 +2,7 @@ instance_id = "Jarvis"
|
|||||||
fullname = "Jarvis"
|
fullname = "Jarvis"
|
||||||
llm_model_name = "gpt-3.5-turbo-16k-0613"
|
llm_model_name = "gpt-3.5-turbo-16k-0613"
|
||||||
max_token_size = 16000
|
max_token_size = 16000
|
||||||
|
#enable_function =["add_event"]
|
||||||
|
|
||||||
[[prompt]]
|
[[prompt]]
|
||||||
role = "system"
|
role = "system"
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ class AIAgentTemplete:
|
|||||||
if self.prompt.load_from_config(config["prompt"]) is False:
|
if self.prompt.load_from_config(config["prompt"]) is False:
|
||||||
logger.error("load prompt from config failed!")
|
logger.error("load prompt from config failed!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -113,6 +114,7 @@ class AIAgent:
|
|||||||
self.unread_msg = Queue() # msg from other agent
|
self.unread_msg = Queue() # msg from other agent
|
||||||
self.owner_env : Environment = None
|
self.owner_env : Environment = None
|
||||||
self.owenr_bus = None
|
self.owenr_bus = None
|
||||||
|
self.enable_function_list = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_templete(cls,templete:AIAgentTemplete, fullname:str):
|
def create_from_templete(cls,templete:AIAgentTemplete, fullname:str):
|
||||||
@@ -150,7 +152,8 @@ class AIAgent:
|
|||||||
self.llm_model_name = config["llm_model_name"]
|
self.llm_model_name = config["llm_model_name"]
|
||||||
if config.get("max_token_size") is not None:
|
if config.get("max_token_size") is not None:
|
||||||
self.max_token_size = config["max_token_size"]
|
self.max_token_size = config["max_token_size"]
|
||||||
|
if config.get("enable_function") is not None:
|
||||||
|
self.enable_function_list = config["enable_function"]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@@ -235,8 +238,15 @@ class AIAgent:
|
|||||||
result_func = []
|
result_func = []
|
||||||
result_len = 0
|
result_len = 0
|
||||||
for inner_func in all_inner_function:
|
for inner_func in all_inner_function:
|
||||||
|
func_name = inner_func.get_name()
|
||||||
|
if self.enable_function_list:
|
||||||
|
if len(self.enable_function_list) > 0:
|
||||||
|
if func_name not in self.enable_function_list:
|
||||||
|
logger.debug(f"ageint {self.agent_id} ignore inner func:{func_name}")
|
||||||
|
continue
|
||||||
|
|
||||||
this_func = {}
|
this_func = {}
|
||||||
this_func["name"] = inner_func.get_name()
|
this_func["name"] = func_name
|
||||||
this_func["description"] = inner_func.get_description()
|
this_func["description"] = inner_func.get_description()
|
||||||
this_func["parameters"] = inner_func.get_parameters()
|
this_func["parameters"] = inner_func.get_parameters()
|
||||||
result_len += len(json.dumps(this_func)) / 4
|
result_len += len(json.dumps(this_func)) / 4
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class AIRole:
|
|||||||
self.prompt : AgentPrompt = None
|
self.prompt : AgentPrompt = None
|
||||||
self.introduce : str = None
|
self.introduce : str = None
|
||||||
self.agent = None
|
self.agent = None
|
||||||
|
self.enable_function_list : list[str] = None
|
||||||
|
|
||||||
def load_from_config(self,config:dict) -> bool:
|
def load_from_config(self,config:dict) -> bool:
|
||||||
name_node = config.get("name")
|
name_node = config.get("name")
|
||||||
@@ -37,6 +38,9 @@ class AIRole:
|
|||||||
intro_node = config.get("intro")
|
intro_node = config.get("intro")
|
||||||
if intro_node is not None:
|
if intro_node is not None:
|
||||||
self.introduce = intro_node
|
self.introduce = intro_node
|
||||||
|
|
||||||
|
if config.get("enable_function") is not None:
|
||||||
|
self.enable_function_list = config["enable_function"]
|
||||||
|
|
||||||
def get_role_id(self) -> str:
|
def get_role_id(self) -> str:
|
||||||
return self.role_id
|
return self.role_id
|
||||||
|
|||||||
@@ -368,15 +368,21 @@ class Workflow:
|
|||||||
old_content = msg.get("content")
|
old_content = msg.get("content")
|
||||||
msg["content"] = old_content.format_map(self.workflow_env)
|
msg["content"] = old_content.format_map(self.workflow_env)
|
||||||
|
|
||||||
def _get_inner_functions(self) -> dict:
|
def _get_inner_functions(self,the_role:AIRole) -> dict:
|
||||||
all_inner_function = self.workflow_env.get_all_ai_functions()
|
all_inner_function = self.workflow_env.get_all_ai_functions()
|
||||||
if all_inner_function is None:
|
if all_inner_function is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
result_func = []
|
result_func = []
|
||||||
for inner_func in all_inner_function:
|
for inner_func in all_inner_function:
|
||||||
|
func_name = inner_func.get_name()
|
||||||
|
if the_role.enable_function_list:
|
||||||
|
if len(the_role.enable_function_list) > 0:
|
||||||
|
if func_name not in the_role.enable_function_list:
|
||||||
|
logger.debug(f"ageint {self.agent_id} ignore inner func:{func_name}")
|
||||||
|
continue
|
||||||
this_func = {}
|
this_func = {}
|
||||||
this_func["name"] = inner_func.get_name()
|
this_func["name"] = func_name
|
||||||
this_func["description"] = inner_func.get_description()
|
this_func["description"] = inner_func.get_description()
|
||||||
this_func["parameters"] = inner_func.get_parameters()
|
this_func["parameters"] = inner_func.get_parameters()
|
||||||
result_func.append(this_func)
|
result_func.append(this_func)
|
||||||
@@ -436,7 +442,7 @@ class Workflow:
|
|||||||
prompt.append(msg_prompt)
|
prompt.append(msg_prompt)
|
||||||
|
|
||||||
self._format_msg_by_env_value(prompt)
|
self._format_msg_by_env_value(prompt)
|
||||||
inner_functions = self._get_inner_functions()
|
inner_functions = self._get_inner_functions(the_role)
|
||||||
|
|
||||||
async def _do_process_msg():
|
async def _do_process_msg():
|
||||||
#TODO: send msg to agent might be better?
|
#TODO: send msg to agent might be better?
|
||||||
|
|||||||
Reference in New Issue
Block a user