beswarm 0.2.41__py3-none-any.whl → 0.2.43__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of beswarm might be problematic. Click here for more details.

beswarm/agents/planact.py CHANGED
@@ -124,10 +124,10 @@ class InstructionAgent(BaseAgent):
124
124
 
125
125
  self.broker.publish({"status": "new_message", "result": "\n🤖 指令智能体:\n" + raw_response}, self.status_topic)
126
126
 
127
- self.last_instruction = raw_response
128
127
  instruction = extract_xml_content(raw_response, "instructions")
129
128
  if instruction:
130
129
  if len(message["conversation"]) == 1:
130
+ instruction = re.sub(r'^<task_complete>([\D\d\s]+)<\/task_complete>$', '', instruction, flags=re.MULTILINE)
131
131
  instruction = (
132
132
  "任务描述:\n"
133
133
  f"<goal>{self.goal}</goal>\n\n"
@@ -145,9 +145,11 @@ class InstructionAgent(BaseAgent):
145
145
  f"{instruction}"
146
146
  )
147
147
  self.broker.publish({"instruction": instruction, "conversation": message["conversation"]}, self.publish_topic)
148
+ self.last_instruction = None
148
149
  else:
149
150
  self.logger.error("\n❌ 指令智能体生成的指令不符合要求,正在重新生成。")
150
151
  self.broker.publish(message, self.error_topic)
152
+ self.last_instruction = raw_response
151
153
 
152
154
 
153
155
  class WorkerAgent(BaseAgent):
beswarm/prompt.py CHANGED
@@ -106,7 +106,7 @@ instruction_system_prompt = """
106
106
  所有回复必须使用中文。
107
107
  运行工作智能体的系统信息:{os_version}
108
108
  你的工作目录为:{workspace_path},请在指令中使用绝对路径。所有操作必须基于工作目录。
109
- 禁止在工作目录之外进行任何操作。你当前运行目录不一定就是工作目录。禁止默认你当前就在工作目录。
109
+ 除了任务目标里面明确提到的目录,禁止在工作目录之外进行任何操作。你当前运行目录不一定就是工作目录。禁止默认你当前就在工作目录。
110
110
 
111
111
  当前时间:{current_time}
112
112
 
beswarm/tools/subtasks.py CHANGED
@@ -67,27 +67,68 @@ def get_all_tasks_status():
67
67
  return task_manager.tasks_cache
68
68
 
69
69
  @register_tool()
70
- async def get_task_result():
70
+ async def get_task_result(reduce: bool = False):
71
71
  """
72
- 等待并获取子任务的执行结果。如果需要等待子任务完成,请使用这个工具。一旦有任务完成,会自动获取结果。如果调用时没有任务完成,会等待直到有任务完成。
72
+ 等待并获取子任务的执行结果。
73
+
74
+ 如果 `reduce` 为 `False`(默认),此工具会等待并返回任何一个子任务完成的结果。
75
+ 一旦有任务完成,它会立即获取并返回该任务的结果。如果调用时没有任务完成,它会阻塞并等待。
76
+
77
+ 如果 `reduce` 为 `True`,此工具会进入“规约”模式,等待 **所有** 正在运行或待处理的子任务都执行完毕后,
78
+ 才将所有任务的结果汇总并返回。这在子任务之间无依赖、可以完全并行执行的场景下非常有用,
79
+ 可以避免为了获取每个任务的结果而进行多次轮询,从而节省token。
80
+
81
+ 警告:当子任务之间存在依赖关系,或者需要根据一个任务的结果来决定下一步操作时,**禁止** 使用 `reduce=True`。
82
+
83
+ Args:
84
+ reduce (bool, optional): 是否启用规约模式。默认为 `False`。
73
85
 
74
86
  Returns:
75
- str: 子任务的执行结果。
87
+ str:
88
+ - 当 `reduce=False` 时,返回单个子任务的执行结果。
89
+ - 当 `reduce=True` 时,返回一个包含所有任务最终状态和结果的汇总字符串。
76
90
  """
77
- running_tasks_num = len([task_id for task_id, task in task_manager.tasks_cache.items() if task_id != "root_path" and task.get("status") in ["PENDING", "RUNNING"]])
78
- if running_tasks_num == 0:
79
- return "All tasks are finished."
80
- task_id, status, result = await task_manager.get_next_result()
91
+ def get_running_tasks_count():
92
+ return len([
93
+ task_id for task_id, task in task_manager.tasks_cache.items()
94
+ if task_id != "root_path" and task.get("status") in ["PENDING", "RUNNING"]
95
+ ])
81
96
 
82
- unfinished_tasks = [task_id for task_id, task in task_manager.tasks_cache.items() if task_id != "root_path" and task.get("status") != "DONE"]
83
- text = "".join([
84
- f"Task ID: {task_id}\n",
85
- f"Status: {status.value}\n",
86
- f"Result: {result}\n\n",
87
- f"There are {len(unfinished_tasks)} unfinished tasks, unfinished task ids: {unfinished_tasks[:5]} ..." if unfinished_tasks else "All tasks are finished.",
88
- ])
97
+ if get_running_tasks_count() == 0:
98
+ return "All tasks are finished."
89
99
 
90
- return text
100
+ if not reduce:
101
+ # 默认行为:获取下一个完成的任务结果
102
+ task_id, status, result = await task_manager.get_next_result()
103
+
104
+ unfinished_tasks = [tid for tid, task in task_manager.tasks_cache.items() if tid != "root_path" and task.get("status") not in ["DONE", "ERROR"]]
105
+ text = "".join([
106
+ f"Task ID: {task_id}\n",
107
+ f"Status: {status.value}\n",
108
+ f"Result: {result}\n\n",
109
+ f"There are {len(unfinished_tasks)} unfinished tasks, unfinished task ids: {unfinished_tasks[:5]} ..." if unfinished_tasks else "All tasks are finished.",
110
+ ])
111
+ return text
112
+ else:
113
+ # 规约模式:等待所有任务完成
114
+ while get_running_tasks_count() > 0:
115
+ await task_manager.get_next_result()
116
+
117
+ # 收集所有任务的结果
118
+ all_results = []
119
+ for task_id, task in task_manager.tasks_cache.items():
120
+ if task_id == "root_path":
121
+ continue
122
+
123
+ status = task.get('status', 'UNKNOWN')
124
+ result = task.get('result', 'No result available')
125
+ all_results.append(
126
+ f"Task ID: {task_id}\nStatus: {status}\nResult: {result}"
127
+ )
128
+
129
+ summary = f"All {len(all_results)} subtasks have been completed.\n\n"
130
+ summary += "\n\n".join(all_results)
131
+ return summary
91
132
 
92
133
  import os
93
134
  import csv
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beswarm
3
- Version: 0.2.41
3
+ Version: 0.2.43
4
4
  Summary: MAS
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -1,11 +1,11 @@
1
1
  beswarm/__init__.py,sha256=HZjUOJtZR5QhMuDbq-wukQQn1VrBusNWai_ysGo-VVI,20
2
2
  beswarm/broker.py,sha256=RtnQZVbhf25acUHahNBiaS5FGxcrj0rhBhkon9gFY_M,9873
3
3
  beswarm/core.py,sha256=_J_LPc0HZFQTLGHy021OMEh2WbsjL_hc6jxd2engpyY,216
4
- beswarm/prompt.py,sha256=5JMfOuXWHscsaeDzwBn223mj9N85eAQdOHXQZk7zeWE,32238
4
+ beswarm/prompt.py,sha256=n0a1a6NThIxAYSkisg1sEKjvz2w0tozpKL4BIplaAkI,32286
5
5
  beswarm/taskmanager.py,sha256=_v1lNHu9WpKK2ial22hvEVPzMJBUiaKTSUbXOxpEYlU,12119
6
6
  beswarm/utils.py,sha256=S9jEtht0hTZbjZ2Hk24p4Ip41R69BogOkYS6fgPKY2Y,8219
7
7
  beswarm/agents/chatgroup.py,sha256=4QTjTjssFDvS2kI5A58TdN92BWjL-XaNzrcd36pTQGQ,11939
8
- beswarm/agents/planact.py,sha256=BFUbz_e1PxZ-_Z6eYRhqejidmWTFo1CI1JWxFV6nTWo,17299
8
+ beswarm/agents/planact.py,sha256=NyZankMtcivZBvIj_EYCTlQky_E1J8q6D0B2WK9RMlc,17468
9
9
  beswarm/aient/main.py,sha256=SiYAIgQlLJqYusnTVEJOx1WNkSJKMImhgn5aWjfroxg,3814
10
10
  beswarm/aient/setup.py,sha256=Mq1M05mT9_UYBK2jk5mP_sLxKQAolcuh8PYXexfj-XU,487
11
11
  beswarm/aient/src/aient/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
@@ -140,10 +140,10 @@ beswarm/tools/request_input.py,sha256=gXNAJPOJektMqxJVyzNTFOeMQ7xUkO-wWMYH-r2Rdw
140
140
  beswarm/tools/screenshot.py,sha256=u6t8FCgW5YHJ_Oc4coo8e0F3wTusWE_-H8dFh1rBq9Q,1011
141
141
  beswarm/tools/search_arxiv.py,sha256=8naYRvmELQryMIcCCBHebIEzNJ8_YivXamM4fzGG3Dk,10754
142
142
  beswarm/tools/search_web.py,sha256=LhgXOSHL9fwxg5T2AAOV4TTJkcJVLogsfRJW2faPvDE,16147
143
- beswarm/tools/subtasks.py,sha256=8RmDhpyjDI3vhwfVhh6HQZIv-OZ0mI3e27zS3FnF09E,7881
143
+ beswarm/tools/subtasks.py,sha256=KCXFzwvxiyX48TF8EAyzucO29PanSAaT5D14TD3GXqQ,9670
144
144
  beswarm/tools/worker.py,sha256=auoAEeg8U_Q59dlyM2nv9cAJIWG3PuR8oy7Bp2cM2S0,1993
145
145
  beswarm/tools/write_csv.py,sha256=-r5OghcvjCg00hY0YQbp6u31VIJLrgaqDIvczAFoqDE,1470
146
- beswarm-0.2.41.dist-info/METADATA,sha256=OBUu8wl3eJH4n5s4lV9NLisFY6LsQBPK8O7zON4Arf4,3878
147
- beswarm-0.2.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
148
- beswarm-0.2.41.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
149
- beswarm-0.2.41.dist-info/RECORD,,
146
+ beswarm-0.2.43.dist-info/METADATA,sha256=qoj6R5aqa7sqxtwaRwDtAvpU0qV453VQ56yis9GO4m4,3878
147
+ beswarm-0.2.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
148
+ beswarm-0.2.43.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
149
+ beswarm-0.2.43.dist-info/RECORD,,