add new aciton in planning

This commit is contained in:
heroding77
2023-12-16 23:24:25 +08:00
parent 16a93370f5
commit 0ee6641f73
3 changed files with 27 additions and 11 deletions

View File

@@ -122,13 +122,29 @@ class PlanningModule(BaseAgent):
# 构建动作图和动作拓扑排序
self.create_action_graph(decompose_json)
self.topological_sort()
for _, node in self.action_node.items():
print(node)
# for _, node in self.action_node.items():
# print(node)
def replan_task(self, reasoning, ):
# 重新计划新的任务
pass
def add_task(self, new_action):
# 将新的动作加入到动作图中
self.create_action_graph(new_action)
# 更新拓扑排序
self.topological_sort()
def update_action(self, action, code=None, return_val=None, status=False):
# 更新动作节点信息
if code:
self.action_node[action].code = code
if return_val:
self.action_node[action].return_val = return_val
self.action_node[action].status = status
# Send decompse task prompt to LLM and get task list
def decompose_task_format_message(self, task, action_list, working_dir, files_and_folders):
sys_prompt = self.prompt['_LINUX_SYSTEM_TASK_DECOMPOSE_PROMPT']
@@ -162,12 +178,15 @@ class PlanningModule(BaseAgent):
def topological_sort(self):
graph = defaultdict(list)
for node, dependencies in self.action_graph.items():
graph.setdefault(node, [])
for dependent in dependencies:
graph[dependent].append(node)
# If the current node has not been executed, put it in the dependency graph.
if not self.action_node[node].status:
graph.setdefault(node, [])
for dependent in dependencies:
# If the dependencies of the current node have not been executed, put them in the dependency graph.
if not self.action_node[dependent].status:
graph[dependent].append(node)
in_degree = {node: 0 for node in graph}
print(in_degree)
# Count in-degree for each node
for node in graph:
for dependent in graph[node]:

View File

@@ -4,6 +4,7 @@ class ActionNode:
self.description = description
self.code = None
self.return_val = None
self.status = False
def __str__(self):
return f"name: {self.name} \n description: {self.description} \n code: {self.code} \n return: {self.return_val}"
return f"name: {self.name} \n description: {self.description} \n code: {self.code} \n return: {self.return_val} \n status: {self.status}"

View File

@@ -1,4 +0,0 @@
/home/heroding/桌面/Jarvis/working_dir/document/4.txt
/home/heroding/桌面/Jarvis/working_dir/document/3.txt
/home/heroding/桌面/Jarvis/working_dir/document/1.txt
/home/heroding/桌面/Jarvis/working_dir/document/2.txt