beswarm 0.2.42__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/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.42
3
+ Version: 0.2.43
4
4
  Summary: MAS
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -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.42.dist-info/METADATA,sha256=76D76l0hTy9sKoCemriewCdrY6hqypBlnGi3X793tgo,3878
147
- beswarm-0.2.42.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
148
- beswarm-0.2.42.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
149
- beswarm-0.2.42.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,,