beswarm 0.2.16__py3-none-any.whl → 0.2.17__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/tools/worker.py +18 -22
- {beswarm-0.2.16.dist-info → beswarm-0.2.17.dist-info}/METADATA +1 -1
- {beswarm-0.2.16.dist-info → beswarm-0.2.17.dist-info}/RECORD +5 -5
- {beswarm-0.2.16.dist-info → beswarm-0.2.17.dist-info}/WHEEL +0 -0
- {beswarm-0.2.16.dist-info → beswarm-0.2.17.dist-info}/top_level.txt +0 -0
beswarm/tools/worker.py
CHANGED
@@ -46,9 +46,15 @@ async def worker(goal, tools, work_dir, cache_messages=None):
|
|
46
46
|
Returns:
|
47
47
|
str: 当任务成功完成时,返回字符串 "任务已完成"。
|
48
48
|
"""
|
49
|
+
cache_dir = Path(work_dir) / ".beswarm"
|
50
|
+
cache_dir.mkdir(exist_ok=True)
|
51
|
+
cache_file = cache_dir / "work_agent_conversation_history.json"
|
52
|
+
if not cache_file.exists():
|
53
|
+
cache_file.write_text("[]", encoding="utf-8")
|
54
|
+
|
49
55
|
DEBUG = os.getenv("DEBUG", "false").lower() in ("true", "1", "t", "yes")
|
50
56
|
if DEBUG:
|
51
|
-
log_file = open(
|
57
|
+
log_file = open(cache_dir / "history.log", "a", encoding="utf-8")
|
52
58
|
log_file.write(f"========== {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ==========\n")
|
53
59
|
original_stdout = sys.stdout
|
54
60
|
original_stderr = sys.stderr
|
@@ -94,11 +100,7 @@ async def worker(goal, tools, work_dir, cache_messages=None):
|
|
94
100
|
}
|
95
101
|
if cache_messages:
|
96
102
|
if isinstance(cache_messages, bool) and cache_messages == True:
|
97
|
-
cache_messages =
|
98
|
-
cache_file_path = Path(work_dir) / ".beswarm" / "work_agent_conversation_history.json"
|
99
|
-
if cache_file_path.exists():
|
100
|
-
with cache_file_path.open("r", encoding="utf-8") as f:
|
101
|
-
cache_messages = json.load(f)
|
103
|
+
cache_messages = json.loads(cache_file.read_text(encoding="utf-8"))
|
102
104
|
if cache_messages and isinstance(cache_messages, list) and len(cache_messages) > 1:
|
103
105
|
old_goal = extract_xml_content(cache_messages[1]["content"], "goal")
|
104
106
|
if old_goal.strip() != goal.strip():
|
@@ -144,11 +146,7 @@ async def worker(goal, tools, work_dir, cache_messages=None):
|
|
144
146
|
instruction_agent = chatgpt(**instruction_agent_config)
|
145
147
|
conversation_history = copy.deepcopy(work_agent.conversation["default"])
|
146
148
|
|
147
|
-
|
148
|
-
os.makedirs(cache_dir, exist_ok=True)
|
149
|
-
cache_file = os.path.join(cache_dir, "work_agent_conversation_history.json")
|
150
|
-
with open(cache_file, "w", encoding="utf-8") as f:
|
151
|
-
f.write(json.dumps(conversation_history, ensure_ascii=False, indent=4))
|
149
|
+
cache_file.write_text(json.dumps(conversation_history, ensure_ascii=False, indent=4), encoding="utf-8")
|
152
150
|
|
153
151
|
work_agent_system_prompt = conversation_history.pop(0)
|
154
152
|
if conversation_history:
|
@@ -248,9 +246,15 @@ async def worker(goal, tools, work_dir, cache_messages=None):
|
|
248
246
|
return "任务已完成"
|
249
247
|
|
250
248
|
async def worker_gen(goal, tools, work_dir, cache_messages=None):
|
249
|
+
cache_dir = Path(work_dir) / ".beswarm"
|
250
|
+
cache_dir.mkdir(exist_ok=True)
|
251
|
+
cache_file = cache_dir / "work_agent_conversation_history.json"
|
252
|
+
if not cache_file.exists():
|
253
|
+
cache_file.write_text("[]", encoding="utf-8")
|
254
|
+
|
251
255
|
DEBUG = os.getenv("DEBUG", "false").lower() in ("true", "1", "t", "yes")
|
252
256
|
if DEBUG:
|
253
|
-
log_file = open(
|
257
|
+
log_file = open(cache_dir / "history.log", "a", encoding="utf-8")
|
254
258
|
log_file.write(f"========== {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} ==========\n")
|
255
259
|
original_stdout = sys.stdout
|
256
260
|
original_stderr = sys.stderr
|
@@ -296,11 +300,7 @@ async def worker_gen(goal, tools, work_dir, cache_messages=None):
|
|
296
300
|
}
|
297
301
|
if cache_messages:
|
298
302
|
if isinstance(cache_messages, bool) and cache_messages == True:
|
299
|
-
cache_messages =
|
300
|
-
cache_file_path = Path(work_dir) / ".beswarm" / "work_agent_conversation_history.json"
|
301
|
-
if cache_file_path.exists():
|
302
|
-
with cache_file_path.open("r", encoding="utf-8") as f:
|
303
|
-
cache_messages = json.load(f)
|
303
|
+
cache_messages = json.loads(cache_file.read_text(encoding="utf-8"))
|
304
304
|
if cache_messages and isinstance(cache_messages, list) and len(cache_messages) > 1:
|
305
305
|
old_goal = extract_xml_content(cache_messages[1]["content"], "goal")
|
306
306
|
if old_goal.strip() != goal.strip():
|
@@ -346,11 +346,7 @@ async def worker_gen(goal, tools, work_dir, cache_messages=None):
|
|
346
346
|
instruction_agent = chatgpt(**instruction_agent_config)
|
347
347
|
conversation_history = copy.deepcopy(work_agent.conversation["default"])
|
348
348
|
|
349
|
-
|
350
|
-
os.makedirs(cache_dir, exist_ok=True)
|
351
|
-
cache_file = os.path.join(cache_dir, "work_agent_conversation_history.json")
|
352
|
-
with open(cache_file, "w", encoding="utf-8") as f:
|
353
|
-
f.write(json.dumps(conversation_history, ensure_ascii=False, indent=4))
|
349
|
+
cache_file.write_text(json.dumps(conversation_history, ensure_ascii=False, indent=4), encoding="utf-8")
|
354
350
|
|
355
351
|
work_agent_system_prompt = conversation_history.pop(0)
|
356
352
|
if conversation_history:
|
@@ -134,8 +134,8 @@ beswarm/tools/request_input.py,sha256=gXNAJPOJektMqxJVyzNTFOeMQ7xUkO-wWMYH-r2Rdw
|
|
134
134
|
beswarm/tools/screenshot.py,sha256=u6t8FCgW5YHJ_Oc4coo8e0F3wTusWE_-H8dFh1rBq9Q,1011
|
135
135
|
beswarm/tools/search_arxiv.py,sha256=caVIUOzMhFu-r_gVgJZrH2EO9xI5iV_qLAg0b3Ie9Xg,8095
|
136
136
|
beswarm/tools/search_web.py,sha256=w0T0aCqOVlb6Of5hn_TtpnrGXo6bMtw2aKZdkrYjycI,12069
|
137
|
-
beswarm/tools/worker.py,sha256=
|
138
|
-
beswarm-0.2.
|
139
|
-
beswarm-0.2.
|
140
|
-
beswarm-0.2.
|
141
|
-
beswarm-0.2.
|
137
|
+
beswarm/tools/worker.py,sha256=ywjD0TUVLzcrVQbVhQuNwtagca0sAuZwSjnKCVb3R6g,23027
|
138
|
+
beswarm-0.2.17.dist-info/METADATA,sha256=PcWMP5H6J2h5o-EjQLL2ENjS4VCldPzrSvdTyghV_Ko,3847
|
139
|
+
beswarm-0.2.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
140
|
+
beswarm-0.2.17.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
|
141
|
+
beswarm-0.2.17.dist-info/RECORD,,
|
File without changes
|
File without changes
|