Refactor the Action/Function components, and refactor the basic architecture of Agent Task/Todo.

This commit is contained in:
Liu Zhicong
2023-12-17 18:23:40 -08:00
parent 3d00095650
commit 29594c0319
41 changed files with 2687 additions and 1108 deletions
@@ -28,7 +28,6 @@ class AgentManager:
self.agent_templete_env : PackageEnv = None
self.agent_env : PackageEnv = None
self.db_path : str = None
self.environments: dict = {}
self.loaded_agent_instance : Dict[str,BaseAIAgent] = None
async def initial(self) -> None:
@@ -50,16 +49,6 @@ class AgentManager:
async def scan_all_agent(self)->None:
pass
def register_environment(self, env_id: str, init_env) -> None:
self.environments[env_id] = init_env
def init_environment(self, env_id: str, workspace: str):
if env_id not in self.environments:
logger.error(f"env {env_id} not found!")
return
return self.environments[env_id](workspace)
async def is_exist(self,agent_id:str) -> bool:
the_aget = await self.get(agent_id)
if the_aget:
@@ -123,28 +112,6 @@ class AgentManager:
config_data = await config_file.read()
config = toml.loads(config_data)
result_agent = AIAgent()
workspace = config.get("workspace", config.get("instance_id"))
workspace = WorkspaceEnvironment(workspace)
config["workspace"] = workspace
if "owner_env" in config:
owner_env = config["owner_env"]
def init_env(env_config: str):
_, ext = os.path.splitext(env_config)
if ext == ".py":
env_path = os.path.join(agent_media.full_path, env_config)
env = runpy.run_path(env_path)["init"](None, workspace.root_path)
else:
env = self.init_environment(env_config, workspace.root_path)
workspace.add_env(env)
if isinstance(owner_env, list):
for env in owner_env:
init_env(env)
else:
init_env(owner_env)
if await result_agent.load_from_config(config) is False:
logger.error(f"load agent from {agent_media} failed!")
@@ -279,7 +279,7 @@ class LocalKnowledgeBase(CompositeEnvironment):
meta = self.learning_cache.get(full_path)
meta.update(op)
self.add_ai_operation(SimpleAIOperation(
self.add_ai_operation(SimpleAIAction(
op="learn",
description="update knowledge llm summary",
func_handler=learn,
@@ -3,7 +3,7 @@ import os
import aiofiles
from typing import Any,List,Dict
import chardet
from aios import SimpleAIOperation
from aios import SimpleAIAction
from aios import SimpleEnvironment
class FilesystemEnvironment(SimpleEnvironment):
@@ -19,7 +19,7 @@ class FilesystemEnvironment(SimpleEnvironment):
if is_append is None:
is_append = False
return await self.write(op["path"],op["content"],is_append)
self.add_ai_operation(SimpleAIOperation(
self.add_ai_operation(SimpleAIAction(
op="write",
description="write file",
func_handler=write,
@@ -27,7 +27,7 @@ class FilesystemEnvironment(SimpleEnvironment):
async def delete(op):
return await self.delete(op["path"])
self.add_ai_operation(SimpleAIOperation(
self.add_ai_operation(SimpleAIAction(
op="delete",
description="delete path",
func_handler=delete,
@@ -35,7 +35,7 @@ class FilesystemEnvironment(SimpleEnvironment):
async def rename(op):
return await self.move(op["path"],op["new_name"])
self.add_ai_operation(SimpleAIOperation(
self.add_ai_operation(SimpleAIAction(
op="rename",
description="rename path",
func_handler=rename,
+11 -19
View File
@@ -1,29 +1,21 @@
import os
from typing import Any,List,Dict
from aios import AgentMsg,AgentTodo,LLMPrompt
from aios import SimpleAIFunction, SimpleAIOperation
from aios import SimpleAIFunction
from aios import SimpleEnvironment
from aios import GlobaToolsLibrary,ParameterDefine
class ShellEnvironment(SimpleEnvironment):
def __init__(self, workspace: str) -> None:
super().__init__(workspace)
def __init__(self) -> None:
super().__init__("shell")
operator_param = {
"command": "command will execute",
}
self.add_ai_function(SimpleAIFunction("shell_exec",
@classmethod
def register_global_functions(cls):
operator_param = ParameterDefine.create_parameters({"command":"command will execute"})
GlobaToolsLibrary.get_instance().register_tool_function(SimpleAIFunction("system.shell.exec",
"execute shell command in linux bash",
self.shell_exec,operator_param))
#run_code_param = {
# "pycode": "python code will execute",
#}
#self.add_ai_function(SimpleAIFunction("run_code",
# "execute python code",
# self.run_code,run_code_param))
async def shell_exec(self,command:str) -> str:
ShellEnvironment.shell_exec,operator_param))
@staticmethod
async def shell_exec(command:str) -> str:
import asyncio.subprocess
process = await asyncio.create_subprocess_shell(
command,