Skip to content

Commit

Permalink
Add implement of Agent Workspace (include a taskmanager system)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflier committed Dec 11, 2023
1 parent 662aee7 commit 3d00095
Show file tree
Hide file tree
Showing 10 changed files with 812 additions and 67 deletions.
4 changes: 3 additions & 1 deletion doc/promps/Do TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Do (TODO)
目标是结合 角色定义,手头的工具,已知知识 完成一个确定的任务。
完成任务时应使用ReAct的方法:应在给出执行动作前,先自言自语的输出一个计划,然后在动作(这个自言自语会变成TODO Logs)
完成任务时应使用ReAct的方法:应在给出执行动作前,先自言自语的输出一个计划,然后在动作(这个自言自语会变成TODO Logs)


77 changes: 74 additions & 3 deletions doc/promps/Review Task.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,79 @@
# Review (Task/Todo)
# Review Task/Todo
目的是结合已知信息(重点是已经进行操作的记录),对失败的,完成的不好的任务进行思考,尝试给出更好的解决方案
1. 管理学方法:更换负责人
2. 管理学方法:拆分
3. 给出建议(该建议可以在下次一次DO-Check)循环中被使用

## Quick Review
有一些简单的Task是永远不会结束的(比如定时提醒)。此时通过Quick Review来调整这些Task的状态,让其在正确的时间进入Review和DO
## ReviewTasklist
目的是选择一个优先级最高的任务开始工作
(这个流程现在是通过计算的方法,基于优先级排序后,FIFO的处理)

## ReviewTask 对未开始的Task进行首次处理
LLM 结果动作:
- 确认执行人,在非Workflow环境中,执行人就是Agent自己,所以不存在这个选项
- 确认执行时间和过期时间,任务只有在执行时间以后和过期时间以前才有机会执行,无法确认执行时间的可以设置下一次检查时间
- 对任务进行拆分(如何防止无限拆分是个大问题),或则有一些简单任务不允许拆分。
- 判断可以立刻执行任务(将任务当成TODO工作),通过Action进入下一个LLMProcess
- 判断任务超出Agent能力范围,宣告失败

Example:
```markdown
I think hard and try my best to complete TODOs. The types of TODO I can handle include:
- Scheduling, where I will try to contact the relevant personnel of the plan and confirm the details of the schedule with them.
- Schedule reminders, where I will remind relevant personnel before the schedule starts, and collect necessary reference information at the time of reminder.
- I will using the post_msg function to contact relevant personnel and my master lzc.
- Writing documents/letters, using op:'create' to save my work results.

I receive a TODO described in json format, I will handle it according to the following rules:
- Determine whether I have the ability to handle the TODO independently. If not, I will try to break the TODO down into smaller sub-TODOs, or hand it over to someone more suitable that I know.
- I will plan the steps to solve the TODO in combination with known information, and break down the generalized TODO into more specific sub-todos. The title of the sub-todo should contain step number like #1, #2
- Sub-todo must set parent, The maximum depth of sub-todo is 4.
- A specific sub-todo refers to a task that can be completed in one execution within my ability range.
- After each execution, I will decide whether to update the status of the TODO. And use op:'update_todo' to update when necessary.

The result of my planned execution must be directly parsed by `python json.loads`. Here is an example:
{
resp: '$what_did_I_do',
post_msg : [
{
target:'$target_name',
content:'$msg_content'
}
],
op_list: [{
op: 'create_todo',
parent: '$parent_id', # optional
todo: {
title: '#1 sub_todo',
detail: 'this is a sub todo',
creator: 'JarvisPlus',
worker: 'lzc',
due_date: '2019-01-01 14:23:11'
}
},
{
op: 'update_todo',
id: '$todo_id',
state: 'cancel' # pending,cancel
},
{
op: 'write_file',
path: '/todos/$todo_path/.result/$doc_name',
content:'$doc_content'
}
]
}

```

## PlanTask 对已经确认的Task进行执行
根据任务的分类,进入不同的LLM Plan逻辑
简单任务:当作TODO立刻执行
普通任务:拆分TODO


## QuickCheckTask 对处于半确认状态Task进行Quick Review
有一些Task是永远不会结束的(比如定时提醒)。此时通过Quick Review来调整这些Task的状态,让其在正确的时间进入Review和DO


## RetryTask 对未成功的任务进行再次处理
14 changes: 12 additions & 2 deletions rootfs/agents/Jarvis/agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ role_desc = """
Your name is Jarvis, the super personal assistant to the master.
"""

[LLMProcess.message]
[behavior.on_message]
type="LLMAgentMessageProcess"
process_description="""
1. Based on your role, combined with existing information, make a brief and efficient reply.
2. Be mindful of the identity of the person you are chatting with and provide services accordingly based on their status.
3. Understand the intention of the dialogue, while using the necessary reply, use the appropriate, supported ACTION.
4. You are proficient in the languages of various countries and try to communicate with each other's mother tongue.
4. If you feel that there is a potential Task in the dialogue, you can create these tasks through appropriate ACTION. Be careful to query whether there are the same task before creating.Using the query interface is a high -cost behavior.
5. You are proficient in the languages of various countries and try to communicate with each other's mother tongue.
"""

reply_format = """
Expand All @@ -44,4 +45,13 @@ known_info_tips = """
tools_tips = """
"""

#[behavior.self_thinking]

#[behavior.review_task]

#[behavior.do]

#[behavior.check]



4 changes: 2 additions & 2 deletions rootfs/agents/JarvisPlus/agent.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ owner_env = ["knowledge"]
[[work.do]]
role = "system"
content = """
My name is JarvisPlus, I am the master's super personal assistant. I think hard and try my best to complete TODOs.
The types of TODO I can handle include:
My name is JarvisPlus, I am the master's super personal assistant.
I think hard and try my best to complete TODOs. The types of TODO I can handle include:
- Scheduling, where I will try to contact the relevant personnel of the plan and confirm the details of the schedule with them.
- Schedule reminders, where I will remind relevant personnel before the schedule starts, and collect necessary reference information at the time of reminder.
- I will using the post_msg function to contact relevant personnel and my master lzc.
Expand Down
26 changes: 15 additions & 11 deletions src/aios/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,20 @@ def __init__(self) -> None:
self.owenr_bus = None
self.enable_function_list = None

self.llm_process:Dict[str,BaseLLMProcess] = {}
self.memory : AgentMemory = None
self.prviate_workspace : AgentWorkspace = None
self.behaviors:Dict[str,BaseLLMProcess] = {}



async def initial(self,params:Dict = None):
self.memory = AgentMemory(self.agent_id,self.chat_db)

self.prviate_workspace = AgentWorkspace(self.agent_id)
init_params = {}
init_params["memory"] = self.memory
for process_name in self.llm_process.keys():
init_result = await self.llm_process[process_name].initial(init_params)
init_params["workspace"] = self.prviate_workspace
for process_name in self.behaviors.keys():
init_result = await self.behaviors[process_name].initial(init_params)
if init_result is False:
logger.error(f"llm process {process_name} initial failed! initial return False")
return False
Expand Down Expand Up @@ -222,16 +226,16 @@ def load_todo_config(todo_type:str) -> bool:
self.history_len = int(config.get("history_len"))

#load all LLMProcess
self.llm_process = {}
LLMProcess = config.get("LLMProcess")
for process_config_name in LLMProcess.keys():
process_config = LLMProcess[process_config_name]
self.behaviors = {}
behaviors = config.get("behavior")
for process_config_name in behaviors.keys():
process_config = behaviors[process_config_name]
real_config = {}
real_config.update(config)
real_config.update(process_config)
load_result = await LLMProcessLoader.get_instance().load_from_config(real_config)
if load_result:
self.llm_process[process_config_name] = load_result
self.behaviors[process_config_name] = load_result
else:
logger.error(f"load LLMProcess {process_config_name} failed!")
return False
Expand Down Expand Up @@ -337,7 +341,7 @@ async def llm_process_msg(self,msg:AgentMsg) -> AgentMsg:
input_parms = {
"msg":msg
}
msg_process = self.llm_process.get("message")
msg_process = self.behaviors.get("on_message")
llm_result : LLMResult = await msg_process.process(input_parms)
if llm_result.state == LLMResultStates.ERROR:
error_resp = msg.create_error_resp(llm_result.error_str)
Expand Down Expand Up @@ -602,7 +606,7 @@ async def _llm_review_team(self,workspace:WorkspaceEnvironment):
async def _llm_review_unassigned_todos(self,workspace:WorkspaceEnvironment):
pass

async def _llm_read_report(self,report:AgentReport,worksapce:WorkspaceEnvironment):
async def _llm_read_report(self,report,worksapce:WorkspaceEnvironment):
work_summary = worksapce.get_work_summary(self.agent_id)
prompt : LLMPrompt = LLMPrompt()
prompt.append(self.agent_prompt)
Expand Down
Loading

0 comments on commit 3d00095

Please sign in to comment.