beswarm 0.1.85__py3-none-any.whl → 0.1.87__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.
beswarm/aient/setup.py CHANGED
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
4
4
 
5
5
  setup(
6
6
  name="aient",
7
- version="1.1.32",
7
+ version="1.1.33",
8
8
  description="Aient: The Awakening of Agent.",
9
9
  long_description=Path.open(Path("README.md"), encoding="utf-8").read(),
10
10
  long_description_content_type="text/markdown",
@@ -12,7 +12,7 @@ from pathlib import Path
12
12
 
13
13
  from .base import BaseLLM
14
14
  from ..plugins import PLUGINS, get_tools_result_async, function_call_list, update_tools_config
15
- from ..utils.scripts import safe_get, async_generator_to_sync, parse_function_xml, parse_continuous_json, convert_functions_to_xml
15
+ from ..utils.scripts import safe_get, async_generator_to_sync, parse_function_xml, parse_continuous_json, convert_functions_to_xml, remove_xml_tags_and_content
16
16
  from ..core.request import prepare_request_payload
17
17
  from ..core.response import fetch_response_stream
18
18
 
@@ -465,7 +465,7 @@ class chatgpt(BaseLLM):
465
465
  if isinstance(self.conversation[convo_id][-1]["content"], str) and \
466
466
  "<tool_error>" in self.conversation[convo_id][-1]["content"]:
467
467
  need_function_call = False
468
- full_response = "接下来我需要做什么?"
468
+ full_response = remove_xml_tags_and_content(full_response) + "上面是我的分析,还没有实际行动。\n\n接下来我需要做什么?"
469
469
  else:
470
470
  need_function_call = False
471
471
  if self.print_log:
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import re
2
3
  import json
3
4
  import requests
4
5
  import urllib.parse
@@ -148,6 +149,35 @@ def safe_get(data, *keys, default=None):
148
149
  return default
149
150
  return data
150
151
 
152
+ def remove_xml_tags_and_content(text: str) -> str:
153
+ """
154
+ 删除字符串中所有的XML标签及其包裹的内容。
155
+ 这个函数通过迭代地移除最内层的标签来处理嵌套标签和自闭合标签。
156
+
157
+ Args:
158
+ text: 包含XML标签的输入字符串。
159
+
160
+ Returns:
161
+ 清理掉XML标签和内容后的字符串。
162
+ """
163
+ # 正则表达式匹配成对的标签及其内容(非贪婪模式)以及自闭合标签
164
+ # 捕获组 \1 用于确保开始和结束标签名匹配
165
+ pair_pattern = r'<([a-zA-Z0-9_:]+)\b[^>]*>.*?</\1>'
166
+ self_closing_pattern = r'<[^>/]+/>'
167
+
168
+ cleaned_text = text
169
+ while True:
170
+ # 使用 re.sub 替换所有非重叠的匹配项
171
+ new_text = re.sub(pair_pattern, '', cleaned_text, flags=re.DOTALL)
172
+ new_text = re.sub(self_closing_pattern, '', new_text)
173
+
174
+ # 如果没有更多内容被移除,则退出循环
175
+ if new_text == cleaned_text:
176
+ break
177
+ cleaned_text = new_text
178
+
179
+ return cleaned_text.strip()
180
+
151
181
  import asyncio
152
182
  def async_generator_to_sync(async_gen):
153
183
  """
@@ -919,14 +949,15 @@ if __name__ == "__main__":
919
949
 
920
950
  请提供前两个 `excute_command` 的执行结果。
921
951
  """
922
- test_xml = """
923
- 好的,我现在执行第一步。
924
- <tools>
925
- <list_directory>
926
- <path>/Downloads/GitHub/beswarm/work/test</path>
927
- </list_directory>
928
- </tools>
929
- """
930
- print(parse_function_xml(test_xml))
952
+ # test_xml = """
953
+ # 好的,我现在执行第一步。
954
+ # <tools>
955
+ # <list_directory>
956
+ # <path>/Downloads/GitHub/beswarm/work/test</path>
957
+ # </list_directory>
958
+ # </tools>
959
+ # """
960
+ # print(parse_function_xml(test_xml))
961
+ print(remove_xml_tags_and_content(test_xml))
931
962
 
932
963
  # 运行本文件:python -m beswarm.aient.src.aient.utils.scripts
beswarm/tools/worker.py CHANGED
@@ -29,6 +29,7 @@ async def worker(goal, tools, work_dir, cache_messages=None):
29
29
  str: 当任务成功完成时,返回字符串 "任务已完成"。
30
30
  """
31
31
  start_time = datetime.now()
32
+ finish_flag = 0
32
33
 
33
34
  tools_json = [value for _, value in get_function_call_list(tools).items()]
34
35
  work_agent_system_prompt = worker_system_prompt.format(
@@ -153,8 +154,14 @@ async def worker(goal, tools, work_dir, cache_messages=None):
153
154
 
154
155
  # 检查任务是否完成
155
156
  if "任务已完成" in next_instruction and len(next_instruction) < 10:
156
- print("\n✅ 任务已完成!")
157
- break
157
+ if finish_flag == 0:
158
+ finish_flag = 1
159
+ continue
160
+ elif finish_flag == 1:
161
+ print("\n✅ 任务已完成!")
162
+ break
163
+ else:
164
+ finish_flag = 0
158
165
  if "find_and_click_element" in str(tools_json):
159
166
  next_instruction = await get_current_screen_image_message(next_instruction)
160
167
  result = await work_agent.ask_async(next_instruction)
@@ -174,6 +181,7 @@ async def worker(goal, tools, work_dir, cache_messages=None):
174
181
 
175
182
  async def worker_gen(goal, tools, work_dir, cache_messages=None):
176
183
  start_time = datetime.now()
184
+ finish_flag = 0
177
185
  tools_json = [value for _, value in get_function_call_list(tools).items()]
178
186
  work_agent_system_prompt = worker_system_prompt.format(
179
187
  os_version=platform.platform(),
@@ -300,8 +308,14 @@ async def worker_gen(goal, tools, work_dir, cache_messages=None):
300
308
 
301
309
  # 检查任务是否完成
302
310
  if "任务已完成" in next_instruction and len(next_instruction) < 10:
303
- print("\n✅ 任务已完成!")
304
- break
311
+ if finish_flag == 0:
312
+ finish_flag = 1
313
+ continue
314
+ elif finish_flag == 1:
315
+ print("\n✅ 任务已完成!")
316
+ break
317
+ else:
318
+ finish_flag = 0
305
319
  if "find_and_click_element" in str(tools_json):
306
320
  next_instruction = await get_current_screen_image_message(next_instruction)
307
321
  result = await work_agent.ask_async(next_instruction)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beswarm
3
- Version: 0.1.85
3
+ Version: 0.1.87
4
4
  Summary: MAS
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -2,7 +2,7 @@ beswarm/__init__.py,sha256=HZjUOJtZR5QhMuDbq-wukQQn1VrBusNWai_ysGo-VVI,20
2
2
  beswarm/prompt.py,sha256=1jNxVXjfhb-A8CVHoudRxytV4qDT6FZIIk1NRCCE1Ns,31365
3
3
  beswarm/utils.py,sha256=cOYwuONpNG_dkSYIvdEqQOxRUdIy0Bh9CTYkvKKskdw,2816
4
4
  beswarm/aient/main.py,sha256=SiYAIgQlLJqYusnTVEJOx1WNkSJKMImhgn5aWjfroxg,3814
5
- beswarm/aient/setup.py,sha256=ub3Tx7R0rcvHG9bJy7qp-mDWUjcxJJ3yQm8jpOtx8AY,487
5
+ beswarm/aient/setup.py,sha256=NkFRjOyvZkKzSLI_JMU1fJkQzf7gLfSPGt7nj-JDnpg,487
6
6
  beswarm/aient/src/aient/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
7
7
  beswarm/aient/src/aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
8
8
  beswarm/aient/src/aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
@@ -17,7 +17,7 @@ beswarm/aient/src/aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6U
17
17
  beswarm/aient/src/aient/models/__init__.py,sha256=ouNDNvoBBpIFrLsk09Q_sq23HR0GbLAKfGLIFmfEuXE,219
18
18
  beswarm/aient/src/aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
19
19
  beswarm/aient/src/aient/models/base.py,sha256=z-Z0pJfTN2x0cuwfvu0BdMRY9O-RmLwHEnBIJN1x4Fg,6719
20
- beswarm/aient/src/aient/models/chatgpt.py,sha256=9l6_7QCF4VuOWPGZiroTT-0dg1h_qze5RUQwauDw_A4,46539
20
+ beswarm/aient/src/aient/models/chatgpt.py,sha256=MKCdstV_gTkcf_bT2mmQVDLgK5f4PUUfEO3_WHzahpE,46665
21
21
  beswarm/aient/src/aient/models/claude.py,sha256=JezghW7y0brl4Y5qiSHvnYR5prQCFywX4RViHt39pGI,26037
22
22
  beswarm/aient/src/aient/models/duckduckgo.py,sha256=1l7vYCs9SG5SWPCbcl7q6pCcB5AUF_r-a4l9frz3Ogo,8115
23
23
  beswarm/aient/src/aient/models/gemini.py,sha256=chGLc-8G_DAOxr10HPoOhvVFW1RvMgHd6mt--VyAW98,14730
@@ -39,7 +39,7 @@ beswarm/aient/src/aient/plugins/websearch.py,sha256=FsUxM9GL4AAjmYJ8TS2jSqv4qfCA
39
39
  beswarm/aient/src/aient/plugins/write_file.py,sha256=7spYxloI_aUbeANEQK-oXrGPoBqSfsD7sdfMAWlNxhU,3656
40
40
  beswarm/aient/src/aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  beswarm/aient/src/aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
42
- beswarm/aient/src/aient/utils/scripts.py,sha256=sXS0MrfRDQGAXOHW4BEwz4lUj_ORchdbVRh62XxidZQ,35939
42
+ beswarm/aient/src/aient/utils/scripts.py,sha256=8NJCASleffBsA20E3K7HvChCH6rb-7-Qa_ygXXpEsCE,37051
43
43
  beswarm/aient/test/chatgpt.py,sha256=Hvl7FuDt1c74N5TVBmhErOPvJbJJzA7FNp5VoZM4u30,4957
44
44
  beswarm/aient/test/claude.py,sha256=IyB4qI1eJLwlSfDNSnt2FhbQWYyBighHUjJxEXc3osQ,1095
45
45
  beswarm/aient/test/test.py,sha256=rldnoLQdtRR8IKFSIzTti7eIK2MpPMoi9gL5qD8_K44,29
@@ -128,8 +128,8 @@ beswarm/tools/screenshot.py,sha256=u6t8FCgW5YHJ_Oc4coo8e0F3wTusWE_-H8dFh1rBq9Q,1
128
128
  beswarm/tools/search_arxiv.py,sha256=GpuIOYX8T0iRC-X-hmuR9AUJVn15WWZq864DaoC7BUc,8004
129
129
  beswarm/tools/search_web.py,sha256=B24amOnGHnmdV_6S8bw8O2PdhZRRIDtJjg-wXcfP7dQ,11859
130
130
  beswarm/tools/think.py,sha256=WLw-7jNIsnS6n8MMSYUin_f-BGLENFmnKM2LISEp0co,1760
131
- beswarm/tools/worker.py,sha256=BfaU_iBDN4XrueCWkvBtpgcHva95e9X26T8HVNVDynY,15569
132
- beswarm-0.1.85.dist-info/METADATA,sha256=1Vtaw1TKQI8N3yi1xyqYZH018FvC_xdMaDeaceql9Lk,3553
133
- beswarm-0.1.85.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
134
- beswarm-0.1.85.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
135
- beswarm-0.1.85.dist-info/RECORD,,
131
+ beswarm/tools/worker.py,sha256=VOulEZBEc5nF2RBR9aLYs0vT7WBD-r2mlWH5ueEo4hM,16007
132
+ beswarm-0.1.87.dist-info/METADATA,sha256=CML-RDiBOUvDdvhSn8ITmQevVj4kUkSIB6rroWnThSU,3553
133
+ beswarm-0.1.87.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
134
+ beswarm-0.1.87.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
135
+ beswarm-0.1.87.dist-info/RECORD,,