From c694ece59e3d4220ce47623d5894b261d1817a5d Mon Sep 17 00:00:00 2001 From: Liu Zhicong Date: Thu, 25 Jan 2024 21:48:17 -0800 Subject: [PATCH] fix bugs. --- rootfs/agents/Jarvis/agent.toml | 12 ++++++------ src/aios/agent/agent.py | 17 +++++++++++++---- src/aios/agent/llm_do_task.py | 2 +- src/aios/agent/workspace.py | 10 ++++++---- src/aios/proto/agent_task.py | 28 ++++++++++++++++------------ src/service/aios_shell/aios_shell.py | 3 ++- 6 files changed, 44 insertions(+), 28 deletions(-) diff --git a/rootfs/agents/Jarvis/agent.toml b/rootfs/agents/Jarvis/agent.toml index b16b643..225ac34 100644 --- a/rootfs/agents/Jarvis/agent.toml +++ b/rootfs/agents/Jarvis/agent.toml @@ -8,7 +8,8 @@ enable_timestamp = "true" enable_json_resp = "true" role_desc = """ -Your name is Jarvis, the super personal assistant to the master, The focus of work is the support of the schedule management and schedule affairs. +Your name is Jarvis, the super personal assistant to the master. Help the Master do a good job of schedule.Reminder before the start of the important schedule, and you should bring useful information as much as possible when reminding. +Only clearly specifying the task you completed can be completed independently. """ [behavior.on_message] @@ -72,13 +73,12 @@ context="Your master is {owner}, now in {location}, time: {now}, weather: {weath llm_context.actions.enable = ["agent.workspace.confirm_task","agent.workspace.update_task","agent.workspace.cancel_task","post_message"] [behavior.plan_task] -## 首次处理任务 +## 处理任务 Tackling Task type="AgentPlanTask" -# 是否要加入对任务到期时间的关注? process_description=""" -The input is a task comes from a Tasklist. You need to perform a PLAN. PLAN process on TASK in combination with the known information. +The input is a task comes from a Tasklist. You are Tackling this task. Tackling process in combination with the known information. 1. Carefully think about whether the task is within your ability, and the task other than the scope of ability is directly rejected. (cancel_task). -2. Immediately perform a simple (similar to reminding one category) task. Send a message using post_message, then set the task to complete.(use update_task). +2. Immediately DO a simple (similar to reminding one category) task. Reminds at a reasonable time, Post a message using post_message, then set the task to complete.(use update_task). 3. Plan for non-simple tasks, and generate a TODO list. Every TODO MUST be an independent work with a clear goal. (set_todos) 4. If the task has been dealt with, it means that the task is ultimately completed.You need to analyze the processing report of the entire task and make new plans. """ @@ -86,7 +86,7 @@ The input is a task comes from a Tasklist. You need to perform a PLAN. PLAN proc reply_format = """ The Response must be directly parsed by `python json.loads`. Here is an example: { - think:'$think step-by-step to be sure you have the right plan.', + think:'$thinking step by step to ensure the accurate and efficient processing task.', resp:'$determine, summary what you do' actions: [{ name: '$action_name', diff --git a/src/aios/agent/agent.py b/src/aios/agent/agent.py index e5ffef9..ba3f264 100644 --- a/src/aios/agent/agent.py +++ b/src/aios/agent/agent.py @@ -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) + diff --git a/src/aios/agent/llm_do_task.py b/src/aios/agent/llm_do_task.py index 4d42961..df9cf25 100644 --- a/src/aios/agent/llm_do_task.py +++ b/src/aios/agent/llm_do_task.py @@ -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) diff --git a/src/aios/agent/workspace.py b/src/aios/agent/workspace.py index 81855be..e1cacca 100644 --- a/src/aios/agent/workspace.py +++ b/src/aios/agent/workspace.py @@ -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"}, }) diff --git a/src/aios/proto/agent_task.py b/src/aios/proto/agent_task.py index 43bee19..7ddee87 100644 --- a/src/aios/proto/agent_task.py +++ b/src/aios/proto/agent_task.py @@ -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 diff --git a/src/service/aios_shell/aios_shell.py b/src/service/aios_shell/aios_shell.py index 8e68a7f..a4a33c4 100644 --- a/src/service/aios_shell/aios_shell.py +++ b/src/service/aios_shell/aios_shell.py @@ -19,7 +19,7 @@ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from prompt_toolkit.completion import WordCompleter from prompt_toolkit.styles import Style -from slack_tunnel import SlackTunnel + directory = os.path.dirname(__file__) sys.path.append(directory + '/../../') @@ -46,6 +46,7 @@ from knowledge_manager import KnowledgePipelineManager from tg_tunnel import TelegramTunnel from email_tunnel import EmailTunnel from discord_tunnel import DiscordTunnel +from slack_tunnel import SlackTunnel from common_environment import LocalKnowledgeBase, FilesystemEnvironment, ShellEnvironment, ScanLocalDocument, ParseLocalDocument from compute_node_config import *