From b6395c2195c57cb28180e238b4122611251b9d15 Mon Sep 17 00:00:00 2001 From: Liu Zhicong Date: Sun, 31 Dec 2023 00:20:48 -0800 Subject: [PATCH] Fix bugs. --- .pylint => .pylintrc | 0 rootfs/agents/Jarvis/agent.toml | 3 ++- src/aios/agent/agent.py | 37 +++++++++++++++++++++++++++++---- src/aios/agent/llm_process.py | 3 ++- src/aios/agent/workspace.py | 4 ++-- src/aios/proto/agent_task.py | 2 +- 6 files changed, 40 insertions(+), 9 deletions(-) rename .pylint => .pylintrc (100%) diff --git a/.pylint b/.pylintrc similarity index 100% rename from .pylint rename to .pylintrc diff --git a/rootfs/agents/Jarvis/agent.toml b/rootfs/agents/Jarvis/agent.toml index b8c6874..208d49f 100644 --- a/rootfs/agents/Jarvis/agent.toml +++ b/rootfs/agents/Jarvis/agent.toml @@ -58,7 +58,8 @@ process_description=""" 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 answer.' + think:'$think step-by-step to be sure you have the right answer.', + determine : '$determine, summary what you will do', plans:[ #Optional {"todo":"$todo_name","detail":"$todo_detail,"category":"$todo_category"} ... diff --git a/src/aios/agent/agent.py b/src/aios/agent/agent.py index d6a0e73..2b31474 100644 --- a/src/aios/agent/agent.py +++ b/src/aios/agent/agent.py @@ -14,7 +14,7 @@ import sys from ..proto.agent_msg import AgentMsg from ..proto.ai_function import * -from ..proto.agent_task import * +from ..proto.agent_task import AgentTaskState,AgentTask,AgentTodo,AgentTodoResult from ..proto.compute_task import * from .agent_base import * @@ -31,7 +31,7 @@ from ..storage.storage import AIStorage from ..knowledge import * from ..utils import video_utils, image_utils -from ..proto.compute_task import ComputeTaskResult,ComputeTaskResultCode +from ..proto.compute_task import ComputeTaskResult,ComputeTaskResultCode,LLMPrompt,LLMResult logger = logging.getLogger(__name__) @@ -240,6 +240,33 @@ class AIAgent(BaseAIAgent): return await self.llm_process_msg(msg) + async def llm_review_tasklist(self): + llm_process : BaseLLMProcess = self.behaviors.get("review_task") + if llm_process: + if self.prviate_workspace: + tasklist = await self.prviate_workspace.task_mgr.list_task() + if tasklist: + for agent_task in tasklist: + if self.agent_energy <= 0: + break + + if agent_task.state == AgentTaskState.TASK_STATE_WAIT: + input_parms = { + "task":agent_task + } + llm_result : LLMResult = await llm_process.process(input_parms) + if llm_result.state == LLMResultStates.ERROR: + logger.error(f"llm process review_task error:{llm_result.error_str}") + continue + elif llm_result.state == LLMResultStates.IGNORE: + logger.info(f"llm process review_task ignore!") + continue + else: + determine = llm_result.raw_result.get("determine") + logger.info(f"llm process review_task ok!,think is:{determine}") + self.agent_energy -= 1 + + async def _llm_run_todo_list(self, todo_list_type: TodoListType): workspace : WorkspaceEnvironment = self.get_workspace_by_msg(None) @@ -486,8 +513,8 @@ class AIAgent(BaseAIAgent): return - async def think_todo_log(self,todo_log:AgentWorkLog): - pass + #async def think_todo_log(self,todo_log:AgentWorkLog): + # pass @@ -516,6 +543,8 @@ class AIAgent(BaseAIAgent): if self.agent_energy <= 1: continue + await self.llm_review_tasklist() + # complete & check todo #await self._llm_run_todo_list(TodoListType.TO_WORK) diff --git a/src/aios/agent/llm_process.py b/src/aios/agent/llm_process.py index 7b9c638..abed5e0 100644 --- a/src/aios/agent/llm_process.py +++ b/src/aios/agent/llm_process.py @@ -522,7 +522,8 @@ class ReviewTaskProcess(BaseLLMProcess): if await super().load_from_config(config) is False: return False - async def prepare_prompt(self) -> LLMPrompt: + async def prepare_prompt(self,input:Dict) -> LLMPrompt: + agent_task = input.get("task") prompt = LLMPrompt() system_prompt_dict = {} system_prompt_dict["role_description"] = self.role_description diff --git a/src/aios/agent/workspace.py b/src/aios/agent/workspace.py index 0d1d334..37485af 100644 --- a/src/aios/agent/workspace.py +++ b/src/aios/agent/workspace.py @@ -4,7 +4,7 @@ import json import sqlite3 import os import logging -from typing import List +from typing import List, Optional import aiofiles @@ -239,7 +239,7 @@ class LocalAgentTaskManger(AgentTaskManager): # pass - async def list_task(self,filter:dict) -> List[AgentTask]: + async def list_task(self,filter:Optional[dict] = None ) -> List[AgentTask]: directory_path = self.root_path result_list:List[AgentTask] = [] diff --git a/src/aios/proto/agent_task.py b/src/aios/proto/agent_task.py index 0000a61..223e087 100644 --- a/src/aios/proto/agent_task.py +++ b/src/aios/proto/agent_task.py @@ -440,7 +440,7 @@ class AgentTaskManager(ABC): # pass @abstractmethod - async def list_task(self,filter:Optional[dict]) -> List[AgentTask]: + async def list_task(self,filter:Optional[dict] = None) -> List[AgentTask]: pass @abstractmethod