fix nature language time bugs

This commit is contained in:
Liu Zhicong
2024-01-25 01:13:40 -08:00
parent b6094c99d4
commit 9b7ca0b81a
10 changed files with 158 additions and 124 deletions
+37 -18
View File
@@ -99,7 +99,7 @@ class AIAgent(BaseAIAgent):
}
self.todo_prompts = todo_prompts
self.chat_db = None
self.memory_db = None
self.unread_msg = Queue() # msg from other agent
self.owenr_bus = None
@@ -109,7 +109,7 @@ class AIAgent(BaseAIAgent):
self.behaviors:Dict[str,BaseLLMProcess] = {}
async def initial(self,params:Dict = None):
self.memory = AgentMemory(self.agent_id,self.chat_db)
self.memory = AgentMemory(self.agent_id,self.memory_db)
self.prviate_workspace = AgentWorkspace(self.agent_id)
init_params = {}
init_params["memory"] = self.memory
@@ -200,6 +200,7 @@ class AIAgent(BaseAIAgent):
context_info["location"] = "SanJose"
context_info["now"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
context_info["weather"] = "Partly Cloudy, 60°F"
context_info["owner"] = AIStorage.get_instance().get_user_config().get_value("username")
return context_info
@@ -209,7 +210,7 @@ class AIAgent(BaseAIAgent):
need_process = False
session_topic = msg.target + "#" + msg.topic
chatsession = AIChatSession.get_session(self.agent_id,session_topic,self.chat_db)
chatsession = AIChatSession.get_session(self.agent_id,session_topic,self.memory_db)
if msg.mentions is not None:
if self.agent_id in msg.mentions:
need_process = True
@@ -247,20 +248,27 @@ class AIAgent(BaseAIAgent):
filter = {}
filter["state"] = AgentTaskState.TASK_STATE_WAIT
tasklist = await self.prviate_workspace.task_mgr.list_task(filter)
tasklist:List[AgentTask]= await self.prviate_workspace.task_mgr.list_task(filter)
if tasklist:
input_parms = {
"tasklist":tasklist,
"context_info": await self._get_context_info()
}
llm_result : LLMResult = await llm_process.process(input_parms)
if llm_result.state == LLMResultStates.ERROR:
logger.error(f"llm process triage_tasks error:{llm_result.compute_error_str}")
elif llm_result.state == LLMResultStates.IGNORE:
logger.info(f"llm process triage_tasks ignore!")
else:
logger.info(f"llm process triage_tasks ok!,think is:{llm_result.resp}")
self.agent_energy -= 3
if len(tasklist) > 0:
simple_list:List[Dict] = []
for task in tasklist:
simple_list.append(task.to_simple_dict())
input_parms = {
"tasklist":simple_list,
"context_info": await self._get_context_info()
}
llm_result : LLMResult = await llm_process.process(input_parms)
if llm_result.state == LLMResultStates.ERROR:
logger.error(f"llm process triage_tasks error:{llm_result.compute_error_str}")
elif llm_result.state == LLMResultStates.IGNORE:
logger.info(f"llm process triage_tasks ignore!")
else:
logger.info(f"llm process triage_tasks ok!,think is:{llm_result.resp}")
self.agent_energy -= 3
# for agent_task in tasklist:
# if self.agent_energy <= 0:
@@ -354,7 +362,7 @@ class AIAgent(BaseAIAgent):
async def do_self_think(self):
session_id_list = AIChatSession.list_session(self.agent_id,self.chat_db)
session_id_list = AIChatSession.list_session(self.agent_id,self.memory_db)
for session_id in session_id_list:
if self.agent_energy <= 0:
break
@@ -396,10 +404,12 @@ class AIAgent(BaseAIAgent):
for task in task_list:
if self.agent_energy <= 0:
break
task = await self.prviate_workspace.task_mgr.get_task(task.task_id)
if task.can_plan():
# PLAN Task
await self.llm_plan_task(task)
task = await self.prviate_workspace.task_mgr.get_task(task.task_id)
if task.state == AgentTaskState.TASK_STATE_DOING:
# DO or Check Todo
@@ -408,14 +418,23 @@ class AIAgent(BaseAIAgent):
for todo in todolist:
if self.agent_energy <= 0:
break
task = await self.prviate_workspace.task_mgr.get_task(task.task_id)
todo = await self.prviate_workspace.task_mgr.get_todo_by_id(todo.todo_id)
if task.state != AgentTaskState.TASK_STATE_DOING:
break
if todo.state == AgentTodoState.TODO_STATE_WAITING or todo.state == AgentTodoState.TODO_STATE_EXEC_FAILED:
await self.llm_do_todo(todo)
task = await self.prviate_workspace.task_mgr.get_task(task.task_id)
todo = await self.prviate_workspace.task_mgr.get_todo_by_id(todo.todo_id)
if task.state != AgentTaskState.TASK_STATE_DOING:
break
if todo.state == AgentTodoState.TODO_STATE_EXEC_OK:
await self.llm_check_todo(todo)
if can_review:
task.state = AgentTaskState.TASK_STATE_WAITING_REVIEW
task = await self.prviate_workspace.task_mgr.get_task(task.task_id)
if task.state == AgentTaskState.TASK_STATE_WAITING_REVIEW:
await self.llm_review_task(task)
+1
View File
@@ -180,6 +180,7 @@ class AgentMemory:
if contact_id is None:
return None
# TODO : fix this by system config.
if contact_id == "lzc":
return "lzc is your master. Male, 40 years old, Mother tongue is Chinese, senior software engineer."
return None
+3 -7
View File
@@ -38,12 +38,8 @@ class AgentTriageTaskList(LLMAgentBaseProcess):
if task_list is None:
logger.error(f"tasklist not found in input")
return None
task_dict_list = []
for task in task_list:
task_dict_list.append(task.to_dict())
prompt.append_user_message(json.dumps(task_dict_list,ensure_ascii=False))
prompt.append_user_message(json.dumps(task_list,ensure_ascii=False))
system_prompt_dict = self.prepare_role_system_prompt(context_info)
# May all logs is good for Agent Triage Task List?
@@ -89,7 +85,7 @@ class AgentTriageTaskList(LLMAgentBaseProcess):
logger.error(f"execute action failed! {e}")
result_str = "execute action failed!,error:" + str(e)
worklog = AgentWorkLog.create_by_content(self.memory.agent_id,"triage",llm_result.resp,self.memory.agent_id)
worklog = AgentWorkLog.create_by_content("","triage",llm_result.resp,self.memory.agent_id)
worklog.result = result_str
await self.memory.append_worklog(worklog)
+1 -1
View File
@@ -91,7 +91,7 @@ class BaseLLMProcess(ABC):
try:
func_name = inner_func_call_node.get("name")
arguments = json.loads(inner_func_call_node.get("arguments"))
logger.info(f"LLMProcess execute inner func:{func_name} :\n\t {json.dumps(arguments,ensure_ascii=False)}")
logger.info(f"LLMProcess execute inner func:{func_name} :({json.dumps(arguments,ensure_ascii=False)})")
func_node : AIFunction = await self.get_inner_function_for_exec(func_name)
if func_node is None:
+23 -15
View File
@@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
class LocalAgentTaskManger(AgentTaskManager):
def __init__(self, owner_id):
super().__init__()
self.root_path = f"{AIStorage.get_instance().get_myai_dir()}/tasklist/{owner_id}"
self.root_path = f"{AIStorage.get_instance().get_myai_dir()}/workspaces/{owner_id}_workspace"
#self.root_path = os.path.join(workspace, list_type)
if not os.path.exists(self.root_path):
os.makedirs(self.root_path)
@@ -451,7 +451,7 @@ class AgentWorkspace:
return f"post message to {target} failed!"
parameters = ParameterDefine.create_parameters({
"target": {"type": "string", "description": "target agent/contact id"},
"target": {"type": "string", "description": "target agent/contact fullname or telephone or email"},
"topic": {"type": "string", "description": "optional, message topic"},
"message": {"type": "string", "description": "message content"},
})
@@ -513,10 +513,10 @@ class AgentWorkspace:
parent_id = params.get("parent")
return await _workspace.task_mgr.create_task(taskObj,parent_id)
parameters = ParameterDefine.create_parameters({
"title": {"type": "string", "description": "task title"},
"detail": {"type": "string", "description": "task detail(simple task can not be filled)"},
"tags": {"type": "string", "description": "optional,task tags"},
"due_date": {"type": "string", "description": "optional,task due date"},
"title" : {"type": "string", "description": "task title,Simple and clear, try to include the task \ Related personnel \ place \ key conditions \ time element involved in the event"},
"detail" : {"type": "string", "description": "task detail(simple task can not be filled)"},
"priority" : {"type": "int", "description": "task priority from 1-10"},
"due_date" : {"type": "isoformat time string", "description": "task due date"},
"parent": {"type": "string", "description": "optional,parent task id"},
})
create_task_action = SimpleAIFunction(
@@ -528,7 +528,6 @@ class AgentWorkspace:
GlobaToolsLibrary.get_instance().register_tool_function(create_task_action)
async def cancel_task(parameters):
_workspace = parameters.get("_workspace")
if _workspace is None:
@@ -563,19 +562,25 @@ class AgentWorkspace:
return f"task {task_id} not found"
if parameters.get("priority"):
task.priority = parameters.get("priority")
if parameters.get("next_do_date"):
task.next_do_date = parameters.get("next_do_date")
if parameters.get("next_attention_time"):
task.next_attention_time = parameters.get("next_attention_time")
if parameters.get("expiration_time"):
task.expiration_time = parameters.get("expiration_time")
if parameters.get("due_date"):
task.due_date = parameters.get("due_date")
task.state = AgentTaskState.TASK_STATE_CONFIRMED
await _workspace.task_mgr.update_task(task)
return "confirm task ok"
parameters = ParameterDefine.create_parameters({
"task_id": {"type": "string", "description": "task id which want to confirm"},
"next_do_date": {"type": "string", "description": "optional,confirm task next do date"},
"expiration_time": {"type": "isoformat time string", "description": "optional,confirm task expiration time"},
"next_attention_time": {"type": "isoformat time string", "description": "optional,confirm task next attention time"},
#"due_date": {"type": "isoformat time string", "description": "optional,confirm task due date"},
"priority": {"type": "int", "description": "optional,task priority from 1-10"},
})
confirm_task_action = SimpleAIFunction(
"agent.workspace.confirm_task",
"Confirm this task",
"After understanding the content of the task, the importance of the importance of the task, the priority, the deadline, etc.",
confirm_task,
parameters
)
@@ -611,20 +616,23 @@ class AgentWorkspace:
task.priority = parameters.get("priority")
if parameters.get("new_state"):
task.state = AgentTaskState.from_str(parameters.get("new_state"))
if parameters.get("next_do_date"):
task.next_do_date = parameters.get("next_do_date")
if parameters.get("next_attention_time"):
task.next_attention_time = parameters.get("next_attention_time")
if parameters.get("due_date"):
task.due_date = parameters.get("due_date")
if parameters.get("expiration_time"):
task.expiration_time = parameters.get("expiration_time")
await _workspace.task_mgr.update_task(task)
return "update task ok"
parameters = ParameterDefine.create_parameters({
"task_id": {"type": "string", "description": "task id which want to update"},
"new_state": {"type": "string", "description": "optional,new task state: cancel or done"},
"next_do_date": {"type": "string", "description": "optional,confirm task next do date"},
"next_attention_time": {"type": "isoformat time string", "description": "optional,update task next attention time"},
"expiration_time": {"type": "isoformat time string", "description": "optional,update task expiration time"},
"priority": {"type": "int", "description": "optional,task priority from 1-10"},
"title": {"type": "string", "description": "optional, new task title"},
"detail": {"type": "string", "description": "optional, new task detail(simple task can not be filled)"},
"due_date": {"type": "string", "description": "optional,new task due date"},
#"due_date": {"type": "string", "description": "optional,new task due date"},
})
update_task_ai_function = SimpleAIFunction("agent.workspace.update_task",
"update task to new state",