Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
742725c
加入高危命令黑名单 Add high-risk command blacklist
May 9, 2026
af56da0
GenericAgent Agent System Design Overview
May 10, 2026
65a4227
Merge remote-tracking branch 'upstream/main'
May 11, 2026
d8fa52c
Subagent 集群监控,Subagents Monitor
May 11, 2026
b585296
remove desing overview html
May 11, 2026
0ed6692
Merge remote-tracking branch 'upstream/main'
May 13, 2026
94e2f73
merged from upstream 0513
May 13, 2026
99c9692
skill_learn_from_cases — 案例驱动技能学习 CLI 工具
May 13, 2026
f8a0efa
skill_learn_from_cases — 案例驱动技能学习 CLI 工具 v001
May 13, 2026
1c321db
skill_learn_from_cases — 案例驱动技能学习 CLI 工具 v002
May 13, 2026
bc3c9ea
skill_learn_from_cases — 案例驱动技能学习 CLI 工具 v003
May 14, 2026
3448be6
skill_learn_from_cases — 案例驱动技能学习 CLI 工具 v005
May 14, 2026
c04f9ab
skill_learn_from_cases 案例驱动技能学习 CLI 工具 v006
May 14, 2026
0043612
skill_learn_from_cases 案例驱动技能学习 CLI 工具 v007
May 14, 2026
9a0dfe6
skill\_learn\_from\_cases 案例驱动技能学习 CLI 工具 v008
May 14, 2026
22c30ba
skill_learn_from_cases 案例驱动技能学习 CLI 工具 v009
May 14, 2026
9cc3b22
skill_learn_from_cases v010
May 14, 2026
47d4875
skill_learn_from_cases v 011
May 14, 2026
405145d
earn_skill_from_cases v000
May 15, 2026
41a2c9f
Merge remote-tracking branch 'upstream/main'
May 15, 2026
1de2ae2
fix:[开始空闲自主行动]按钮点击无反应
May 15, 2026
e123390
修复点击[开始空闲自主行动]按钮,无反应问题
May 15, 2026
ec7ae8d
clean fork 0515
May 15, 2026
7e51ab7
clean051502
May 15, 2026
1cad02b
自主行动相关按钮修复
May 15, 2026
1baa23b
Merge remote-tracking branch 'upstream/main'
May 16, 2026
c056de8
learn_skill_from_cases v000
May 16, 2026
2bd6e8c
Merge remote-tracking branch 'upstream/main'
May 20, 2026
f37588f
Merge branch 'main' of github.com:benemorphy/GenericAgent
May 20, 2026
621d3d0
cleaned again
May 20, 2026
591b763
refactor: decouple turn policies into pluggable policy hook chain
May 21, 2026
e81c954
Merge remote-tracking branch 'upstream/main'
May 21, 2026
a08b076
turn policy decoupling
May 21, 2026
2fe6d65
turn policy decoupling
May 21, 2026
097685f
turn policy decoupling
May 21, 2026
43bfc4f
turn policy decoupling
May 21, 2026
3cab8e8
turn policy decoupling
May 21, 2026
c791ea0
decoupling turn policy
May 21, 2026
9d4eabd
decoupling turn policy
May 21, 2026
764d584
decoupling turn policy
May 21, 2026
ed6ae45
decoupling turn policy
May 21, 2026
6950bf2
decoupling turn policy
May 21, 2026
9f367b2
decoupling turn policy
May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from agent_loop import BaseHandler, StepOutcome, json_default
from turn_policy import register_turn_policies
script_dir = os.path.dirname(os.path.abspath(__file__))

def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None, stop_signal=None, maxlen=10000):
Expand Down Expand Up @@ -268,6 +269,8 @@ def __init__(self, parent, last_history=None, cwd='./temp'):
self.history_info = last_history if last_history else []
self.code_stop_signal = []
self._done_hooks = []
# Turn policy hooks - pluggable strategy chain (from turn_policy.py)
register_turn_policies(self)

def _get_abs_path(self, path):
if not path: return ""
Expand Down Expand Up @@ -543,7 +546,7 @@ def _get_anchor_prompt(self, skip=False):
try: print(prompt)
except: pass
return prompt

def turn_end_callback(self, response, tool_calls, tool_results, turn, next_prompt, exit_reason):
_c = re.sub(r'```.*?```|<thinking>.*?</thinking>', '', response.content, flags=re.DOTALL)
rsumm = re.search(r"<summary>(.*?)</summary>", _c, re.DOTALL)
Expand All @@ -559,15 +562,9 @@ def turn_end_callback(self, response, tool_calls, tool_results, turn, next_promp
self.history_info.append(f'[Agent] {summary}')
_plan = self._in_plan_mode()

if turn % 75 == 0 and (not _plan):
next_prompt += f"\n\n[DANGER] 已连续执行第 {turn} 轮。必须总结情况进行ask_user,不允许继续重试。"
elif turn % 7 == 0:
next_prompt += f"\n\n[DANGER] 已连续执行第 {turn} 轮。禁止无效重试。若无有效进展,必须切换策略:1. 探测物理边界 2. 请求用户协助。如有需要,可调用 update_working_checkpoint 保存关键上下文。"
elif turn % 10 == 0: next_prompt += get_global_memory()

if _plan and turn >= 10 and turn % 5 == 0:
next_prompt = f"[Plan Hint] 正在计划模式。必须 file_read({_plan}) 确认当前步骤,回复开头引用:📌 当前步骤:...\n\n" + next_prompt
if _plan and turn >= 120: next_prompt += f"\n\n[DANGER] Plan模式已运行 {turn} 轮,已达上限。必须 ask_user 汇报进度并确认是否继续。"
# Policy hook chain - each policy returns "" or a string to append
for policy in self._turn_policies:
next_prompt += policy(turn, _plan, next_prompt) or ""

injkeyinfo = consume_file(self.parent.task_dir, '_keyinfo')
injprompt = consume_file(self.parent.task_dir, '_intervene')
Expand Down
61 changes: 61 additions & 0 deletions turn_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

import os

def policy_danger_ask_user(turn, _plan, next_prompt):
"""每75轮强制ask_user(非plan模式)"""
if turn % 75 == 0 and (not _plan):
return (
"\n\n[DANGER] 已连续执行第 " + str(turn) + " 轮。"
"必须总结情况进行ask_user,不允许继续重试。"
)
return ""


def policy_danger_retry(turn, _plan, next_prompt):
"""每7轮禁止无效重试"""
if turn % 7 == 0:
return (
"\n\n[DANGER] 已连续执行第 " + str(turn) + " 轮。禁止无效重试。"
"若无有效进展,必须切换策略:1. 探测物理边界 "
"2. 请求用户协助。如有需要,可调用 update_working_checkpoint "
"保存关键上下文。"
)
return ""


def policy_inject_memory(turn, _plan, next_prompt):
"""每10轮注入全局记忆"""
if turn % 10 == 0:
from ga import get_global_memory
return get_global_memory()
return ""


def policy_plan_limit(turn, _plan, next_prompt):
"""Plan模式上限检测"""
if _plan and turn >= 10 and turn % 5 == 0 and turn <= 110:
return (
"[Plan Hint] 正在计划模式。必须 file_read(" + str(_plan) + ") "
"确认当前步骤,回复开头引用:当前步骤:...\n\n"
)
if _plan and turn >= 120:
return (
"\n\n[DANGER] Plan模式已运行 " + str(turn) + " 轮,已达上限。"
"必须 ask_user 汇报进度并确认是否继续。"
)
return ""

# Default turn policies that ship with the agent
DEFAULT_TURN_POLICIES = [
policy_danger_ask_user,
policy_danger_retry,
policy_inject_memory,
policy_plan_limit,
]

def register_turn_policies(handler, policies=None):
"""Register turn policies onto a GenericAgentHandler instance.
"""
if policies is None:
policies = DEFAULT_TURN_POLICIES
handler._turn_policies = list(policies)