fix bugs.
This commit is contained in:
+13
-4
@@ -384,8 +384,8 @@ class AIAgent(BaseAIAgent):
|
||||
logger.warning(f"agent {self.agent_id} is already wake up!")
|
||||
|
||||
async def _on_timer(self):
|
||||
while True:
|
||||
await asyncio.sleep(5)
|
||||
await asyncio.sleep(5)
|
||||
while True:
|
||||
try:
|
||||
now = time.time()
|
||||
if self.last_recover_time is None:
|
||||
@@ -394,17 +394,23 @@ class AIAgent(BaseAIAgent):
|
||||
if now - self.last_recover_time > 60:
|
||||
self.agent_energy += (now - self.last_recover_time) / 60
|
||||
self.last_recover_time = now
|
||||
logger.info(f"agent {self.agent_id} recover energy to {self.agent_energy}")
|
||||
|
||||
if self.agent_energy <= 1:
|
||||
logger.info(f"agent {self.agent_id} energy is too low!, goto sleep!")
|
||||
continue
|
||||
|
||||
await self.llm_triage_tasklist()
|
||||
task_list:List[AgentTask] = await self.prviate_workspace.task_mgr.list_task()
|
||||
# Get un finished tasks
|
||||
#filter = {}
|
||||
#filter["state"] = AgentTaskState.TASK_STATE_WAIT
|
||||
filter = None
|
||||
task_list:List[AgentTask] = await self.prviate_workspace.task_mgr.list_task(filter)
|
||||
|
||||
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
|
||||
@@ -445,6 +451,9 @@ class AIAgent(BaseAIAgent):
|
||||
logger.error(f"agent {self.agent_id} on timer error:{e},{tb_str}")
|
||||
continue
|
||||
|
||||
# Because the LLM itself is very slow, the accuracy of the system processing task is in minutes.
|
||||
await asyncio.sleep(30)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ class AgentPlanTask(LLMAgentBaseProcess):
|
||||
logger.error(f"execute action failed! {e}")
|
||||
result_str = "execute action failed!,error:" + str(e)
|
||||
|
||||
worklog = AgentWorkLog.create_by_content(agent_task.task_id,"plan",llm_result.resp,self.memory.agent_id)
|
||||
worklog = AgentWorkLog.create_by_content(agent_task.task_id,"tackling",llm_result.resp,self.memory.agent_id)
|
||||
worklog.result = result_str
|
||||
await self.memory.append_worklog(worklog)
|
||||
|
||||
|
||||
@@ -288,8 +288,9 @@ class LocalAgentTaskManger(AgentTaskManager):
|
||||
continue
|
||||
task_item = await self._get_task_by_fullpath(entry.path)
|
||||
if task_item:
|
||||
if task_item.is_finish():
|
||||
continue
|
||||
if filter is None:
|
||||
if task_item.is_finish():
|
||||
continue
|
||||
|
||||
if special_state:
|
||||
if task_item.state != special_state:
|
||||
@@ -516,7 +517,8 @@ class AgentWorkspace:
|
||||
"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"},
|
||||
#"due_date": {"type": "isoformat time string", "description": "optional,confirm task due date"},
|
||||
#"expiration_time": {"type": "isoformat time string", "description": "optional,confirm task expiration time"},
|
||||
"parent": {"type": "string", "description": "optional,parent task id"},
|
||||
})
|
||||
create_task_action = SimpleAIFunction(
|
||||
@@ -573,8 +575,8 @@ class AgentWorkspace:
|
||||
return "confirm task ok"
|
||||
parameters = ParameterDefine.create_parameters({
|
||||
"task_id": {"type": "string", "description": "task id which want to confirm"},
|
||||
"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"},
|
||||
"expiration_time": {"type": "isoformat time string", "description": "optional,confirm task expiration time"},
|
||||
#"due_date": {"type": "isoformat time string", "description": "optional,confirm task due date"},
|
||||
"priority": {"type": "int", "description": "optional,task priority from 1-10"},
|
||||
})
|
||||
|
||||
@@ -325,18 +325,17 @@ class AgentTask:
|
||||
return False
|
||||
|
||||
def can_plan(self) -> bool:
|
||||
if self.state == AgentTaskState.TASK_STATE_CONFIRMED:
|
||||
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}")
|
||||
|
||||
if self.state == AgentTaskState.TASK_STATE_CONFIRMED or self.state == AgentTaskState.TASK_STATE_CHECKFAILED:
|
||||
if self.next_attention_time:
|
||||
try:
|
||||
next_attention_time = datetime.fromisoformat(self.next_attention_time).timestamp()
|
||||
if time.time() >= next_attention_time:
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(f"invalid next_attention_time {self.next_attention_time}")
|
||||
else:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def to_simple_dict(self) -> dict:
|
||||
@@ -344,9 +343,14 @@ class AgentTask:
|
||||
result["task_id"] = self.task_id
|
||||
result["title"] = self.title
|
||||
result["priority"] = self.priority
|
||||
result["detail"] = self.detail
|
||||
result["create_time"] = self.create_time
|
||||
if self.due_date:
|
||||
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
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user