fix nature language time bugs
This commit is contained in:
+37
-18
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
@@ -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",
|
||||
|
||||
@@ -235,7 +235,6 @@ class AgentTodo:
|
||||
def to_dict(self) -> dict:
|
||||
result = {}
|
||||
result["todo_id"] = self.todo_id
|
||||
result["todo_path"] = self.todo_path
|
||||
result["owner_taskid"] = self.owner_taskid
|
||||
result["title"] = self.title
|
||||
result["detail"] = self.detail
|
||||
@@ -251,9 +250,6 @@ class AgentTodo:
|
||||
#todo_id
|
||||
if json_obj.get("todo_id") is not None:
|
||||
result_obj.todo_id = json_obj.get("todo_id")
|
||||
#todo_path
|
||||
if json_obj.get("todo_path") is not None:
|
||||
result_obj.todo_path = json_obj.get("todo_path")
|
||||
#owner_taskid
|
||||
if json_obj.get("owner_taskid") is not None:
|
||||
result_obj.owner_taskid = json_obj.get("owner_taskid")
|
||||
@@ -288,23 +284,21 @@ class AgentTask:
|
||||
self.worker = None
|
||||
self.createor = None
|
||||
|
||||
# if due_date is none ,means no due date
|
||||
self.due_date = time.time() + 3600 * 24 * 2
|
||||
# 确定的执行时间(执行条件)
|
||||
self.next_do_time = None
|
||||
# 如果next check time设置,说明任务适合在该时间点可能具备执行调教,尝试检查并执行
|
||||
#self.next_check_time = None
|
||||
now = time.time()
|
||||
self.create_time = datetime.fromtimestamp(now).isoformat()
|
||||
# dead line,set by llm
|
||||
self.due_date = None
|
||||
# set by llm
|
||||
self.next_attention_time = None
|
||||
# set by llm
|
||||
self.expiration_time = None
|
||||
|
||||
self.depend_task_ids = []
|
||||
#self.step_todo_ids = []
|
||||
|
||||
self.create_time = time.time()
|
||||
self.done_time = None
|
||||
|
||||
self.last_do_time = None
|
||||
self.last_plan_time = None
|
||||
self.last_check_time = None
|
||||
#self.last_review_time = None
|
||||
self.last_review_time = None
|
||||
|
||||
def is_finish(self) -> bool:
|
||||
if self.state == AgentTaskState.TASK_STATE_DONE:
|
||||
@@ -319,10 +313,14 @@ class AgentTask:
|
||||
if self.state == AgentTaskState.TASK_STATE_FAILED:
|
||||
return True
|
||||
|
||||
if self.due_date:
|
||||
if self.due_date < time.time():
|
||||
self.state = AgentTaskState.TASK_STATE_EXPIRED
|
||||
return True
|
||||
if self.expiration_time:
|
||||
try:
|
||||
expiration_time = datetime.fromisoformat(self.expiration_time).timestamp()
|
||||
if expiration_time < time.time():
|
||||
self.state = AgentTaskState.TASK_STATE_EXPIRED
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(f"invalid expiration_time {self.expiration_time}")
|
||||
|
||||
return False
|
||||
|
||||
@@ -331,8 +329,26 @@ class AgentTask:
|
||||
return True
|
||||
if self.state == AgentTaskState.TASK_STATE_CHECKFAILED:
|
||||
return True
|
||||
if self.next_attention_time:
|
||||
try:
|
||||
next_attention_time = datetime.fromisoformat(self.next_attention_time).timestamp()
|
||||
if next_attention_time >= time.time():
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(f"invalid next_attention_time {self.next_attention_time}")
|
||||
|
||||
return False
|
||||
|
||||
def to_simple_dict(self) -> dict:
|
||||
result = {}
|
||||
result["task_id"] = self.task_id
|
||||
result["title"] = self.title
|
||||
result["priority"] = self.priority
|
||||
result["create_time"] = self.create_time
|
||||
if self.due_date:
|
||||
result["due_date"] = self.due_date
|
||||
return result
|
||||
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
result = {}
|
||||
@@ -341,26 +357,35 @@ class AgentTask:
|
||||
result["detail"] = self.detail
|
||||
result["state"] = self.state.value
|
||||
result["priority"] = self.priority
|
||||
result["tags"] = self.tags
|
||||
result["worker"] = self.worker
|
||||
result["createor"] = self.createor
|
||||
|
||||
if self.tags:
|
||||
result["tags"] = self.tags
|
||||
|
||||
if self.worker:
|
||||
result["worker"] = self.worker
|
||||
|
||||
if self.createor:
|
||||
result["createor"] = self.createor
|
||||
result["create_time"] = self.create_time
|
||||
if self.due_date:
|
||||
result["due_date"] = datetime.fromtimestamp(self.due_date).isoformat()
|
||||
if self.next_do_time:
|
||||
result["next_do_time"] = datetime.fromtimestamp(self.next_do_time).isoformat()
|
||||
result["due_date"] = self.due_date
|
||||
if self.expiration_time:
|
||||
result["expiration_time"] = self.expiration_time
|
||||
|
||||
if self.next_attention_time:
|
||||
result["next_attention_time"] = self.next_attention_time
|
||||
#if self.next_check_time:
|
||||
# result["next_check_time"] = datetime.fromtimestamp(self.next_check_time).isoformat()
|
||||
result["depend_task_ids"] = self.depend_task_ids
|
||||
#result["step_todo_ids"] = self.step_todo_ids
|
||||
result["create_time"] = datetime.fromtimestamp(self.create_time).isoformat()
|
||||
if self.depend_task_ids:
|
||||
if len(self.depend_task_ids) > 0:
|
||||
result["depend_task_ids"] = self.depend_task_ids
|
||||
|
||||
if self.done_time:
|
||||
result["done_time"] = datetime.fromtimestamp(self.done_time).isoformat()
|
||||
if self.last_do_time:
|
||||
result["last_do_time"] = datetime.fromtimestamp(self.last_do_time).isoformat()
|
||||
result["done_time"] = self.done_time
|
||||
if self.last_plan_time:
|
||||
result["last_plan_time"] = datetime.fromtimestamp(self.last_plan_time).isoformat()
|
||||
if self.last_check_time:
|
||||
result["last_check_time"] = datetime.fromtimestamp(self.last_check_time).isoformat()
|
||||
result["last_plan_time"] = self.last_plan_time
|
||||
if self.last_review_time:
|
||||
result["last_review_time"] = self.last_review_time
|
||||
|
||||
return result
|
||||
@classmethod
|
||||
@@ -374,32 +399,15 @@ class AgentTask:
|
||||
result.tags = json_obj.get("tags")
|
||||
result.worker = json_obj.get("worker")
|
||||
result.createor = json_obj.get("createor")
|
||||
due_date = json_obj.get("due_date")
|
||||
if due_date:
|
||||
result.due_date = datetime.fromisoformat(due_date).timestamp()
|
||||
next_do_time = json_obj.get("next_do_time")
|
||||
if next_do_time:
|
||||
result.next_do_time = datetime.fromisoformat(next_do_time).timestamp()
|
||||
#next_check_time = json_obj.get("next_check_time")
|
||||
#if next_check_time:
|
||||
# result.next_check_time = datetime.fromisoformat(next_check_time).timestamp()
|
||||
result.due_date = json_obj.get("due_date")
|
||||
result.next_attention_time = json_obj.get("next_attention_time")
|
||||
result.depend_task_ids = json_obj.get("depend_task_ids")
|
||||
#result.step_todo_ids = json_obj.get("step_todo_ids")
|
||||
create_time = json_obj.get("create_time")
|
||||
if create_time:
|
||||
result.create_time = datetime.fromisoformat(create_time).timestamp()
|
||||
done_time = json_obj.get("done_time")
|
||||
if done_time:
|
||||
result.done_time = datetime.fromisoformat(done_time).timestamp()
|
||||
last_do_time = json_obj.get("last_do_time")
|
||||
if last_do_time:
|
||||
result.last_do_time = datetime.fromisoformat(last_do_time).timestamp()
|
||||
last_plan_time = json_obj.get("last_plan_time")
|
||||
if last_plan_time:
|
||||
result.last_plan_time = datetime.fromisoformat(last_plan_time).timestamp()
|
||||
last_check_time = json_obj.get("last_check_time")
|
||||
if last_check_time:
|
||||
result.last_check_time = datetime.fromisoformat(last_check_time).timestamp()
|
||||
result.expiration_time = json_obj.get("expiration_time")
|
||||
result.create_time = json_obj.get("create_time")
|
||||
result.done_time = json_obj.get("done_time")
|
||||
result.last_plan_time = json_obj.get("last_plan_time")
|
||||
result.last_review_time = json_obj.get("last_review_time")
|
||||
|
||||
if result.task_id is None or result.title is None or result.create_time is None or result.create_time is None:
|
||||
logger.error(f"invalid task {json_obj}")
|
||||
@@ -422,14 +430,12 @@ class AgentTask:
|
||||
result.priority = json_obj.get("priority")
|
||||
if result.priority is None:
|
||||
result.priority = 5
|
||||
|
||||
if json_obj.get("due_date"):
|
||||
result.due_date = json_obj.get("due_date")
|
||||
result.tags = json_obj.get("tags")
|
||||
result.worker = json_obj.get("worker")
|
||||
result.createor = creator
|
||||
due_date = json_obj.get("due_date")
|
||||
if due_date:
|
||||
result.due_date = datetime.fromisoformat(due_date).timestamp()
|
||||
|
||||
|
||||
return result
|
||||
|
||||
# 谁在什么时间做了什么
|
||||
|
||||
Reference in New Issue
Block a user