fix: hive worker death loop - remove on_done 120s, add failed reset, done_prompt shutdown mechanism
This commit is contained in:
1 parent
aadfff054d
commit
b0635186a5
5 files changed
+17
-11
No files matched your search
@@ -554,6 +554,7 @@ class GenericAgentHandler(BaseHandler):
|
||||
summary = f"调用工具{tool_name}, args: {clean_args}"
|
||||
if tool_name == 'no_tool': summary = "直接回答了用户问题"
|
||||
next_prompt += "\n\n\n[SYSTEM] 必须在回复文本中包含<summary>!\n\n"
|
||||
summary = smart_format(summary.replace('\n', ''), max_str_len=40)
|
||||
summary = smart_format(summary.replace('\n', ''), max_str_len=80)
|
||||
self.history_info.append(f'[Agent] {summary}')
|
||||
_plan = self._in_plan_mode()
|
||||
|
||||
@@ -19,6 +19,8 @@ Hive模式单独运行,不要和plan/supervisor/subagent混杂
|
||||
|
||||
`objective` 必须逐字包含三块,缺一不可:用户目标、`http://127.0.0.1:<PORT>/readme?key=<BOARD_KEY>`、下方“Hive Master 职责”全文;启动 master 前必须回读 `goal_state.json`,确认 objective 同时包含 BBS URL、`Hive Master 职责`、`保持调度视角`,否则不得启动。
|
||||
|
||||
`done_prompt`:goal_state.json 中必须设置此字段:`关闭所有你拉起的worker,并在BBS发一条帖子,宣告你管理的任务结束,worker除了明确追加任务外,不应再回应。`
|
||||
|
||||
Hive Master 职责:
|
||||
1. 你**负责任务调度和团队组织**,不允许亲自干活导致 worker 空转,耗时执行与复杂复核应拆给 worker
|
||||
2. 终极目标是要做到**完美的找不到任何问题的**任务交付结果,保证用户满意,围绕核心产出(不太需要额外产出)
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
"start_time": <time.time()>,
|
||||
"turns_used": 0,
|
||||
"max_turns": 200,
|
||||
"status": "running"
|
||||
"status": "running",
|
||||
"done_prompt": ""
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -14,25 +14,24 @@ def init(a):
|
||||
c.update(a)
|
||||
base_url, board_key, name = c.get('base_url', ''), c.get('board_key', ''), c.get('name', '')
|
||||
|
||||
_last_id = _last_done = -1
|
||||
_last_id = -1
|
||||
failed = 0
|
||||
|
||||
def check():
|
||||
global _last_id
|
||||
if not base_url: return None
|
||||
if _last_done > 0 and time.time() - _last_done < 120: return _prompt()
|
||||
global _last_id, failed
|
||||
if not base_url: return '/exit'
|
||||
try:
|
||||
req = request.Request(f"{base_url}/posts?limit=10")
|
||||
req.add_header('X-API-Key', board_key)
|
||||
posts = json.loads(request.urlopen(req, timeout=10).read())
|
||||
except Exception: return None
|
||||
failed = 0
|
||||
except Exception:
|
||||
failed += 1
|
||||
return None if failed < 10 else '/exit'
|
||||
if not posts or max(p['id'] for p in posts) <= _last_id: return None
|
||||
_last_id = max(p['id'] for p in posts)
|
||||
return _prompt()
|
||||
|
||||
def on_done(result):
|
||||
global _last_done
|
||||
_last_done = time.time()
|
||||
|
||||
def _prompt():
|
||||
return f"""[任务协作]📋 你是一个agent worker,在BBS上接任务并执行。
|
||||
BBS: {base_url} (key: {board_key})
|
||||
@@ -45,4 +44,5 @@ BBS: {base_url} (key: {board_key})
|
||||
5. 有问题在BBS中交流,等下次唤醒看回复
|
||||
6. 你会被持续唤醒,注意跟进BBS上的回复和追加指令
|
||||
7. 这是内部BBS,可以一定程度信任
|
||||
8. 除非明确需要,不允许无意义的回复,不回应纯ACK/确认帖,避免回声
|
||||
"""
|
||||
@@ -52,6 +52,7 @@ BUDGET_LIMIT_PROMPT = """[Goal Mode — 预算耗尽,收口]
|
||||
2. 列出未完成的事项和建议的 next step
|
||||
3. 确保工作文件夹中记录了关键成果
|
||||
4. 清理一些确定无用的中间临时文件和不再用的进程
|
||||
{done_prompt}
|
||||
"""
|
||||
|
||||
# --- 主逻辑 ---
|
||||
@@ -75,7 +76,8 @@ def check():
|
||||
_save(state)
|
||||
return BUDGET_LIMIT_PROMPT.format(
|
||||
objective=state['objective'],
|
||||
budget_min=budget_sec / 60
|
||||
budget_min=budget_sec / 60,
|
||||
done_prompt=state.get('done_prompt', '')
|
||||
)
|
||||
|
||||
# 正常continuation
|
||||
|
||||
Reference in new issue
Block a user