diff --git a/agentmain.py b/agentmain.py index d8cab8cf0..4f7bf175d 100644 --- a/agentmain.py +++ b/agentmain.py @@ -306,6 +306,7 @@ def _hub_put(t): if task: print(f'[Reflect] triggered: {task[:80]}') if (_ln := getattr(mod, 'LLM', None)): agent.next_llm(next((i for i, b in enumerate(agent.llmclients) if not isinstance(b, dict) and b.backend.name == _ln), agent.llm_no)) + if getattr(mod, 'FRESH_CONTEXT', False): from frontends.continue_cmd import reset_conversation; reset_conversation(agent, snapshot=False) dq = agent.put_task(task, source='reflect') try: while 'done' not in (item := dq.get(timeout=2200)): pass diff --git a/frontends/continue_cmd.py b/frontends/continue_cmd.py index 3e926c11c..3f5ec1f2e 100644 --- a/frontends/continue_cmd.py +++ b/frontends/continue_cmd.py @@ -471,13 +471,13 @@ def _snapshot_current_log(pid=None): return snapshot -def reset_conversation(agent, message='🆕 已开启新对话,当前上下文已清空'): +def reset_conversation(agent, message='🆕 已开启新对话,当前上下文已清空', snapshot=True): """Abort current work and clear all known frontend-visible conversation state.""" try: agent.abort() except Exception: pass - _snapshot_current_log() + if snapshot: _snapshot_current_log() if hasattr(agent, 'history'): agent.history = [] for client in _agent_clients(agent): diff --git a/reflect/scheduler.py b/reflect/scheduler.py index a3ca622d3..d79367518 100644 --- a/reflect/scheduler.py +++ b/reflect/scheduler.py @@ -10,6 +10,7 @@ INTERVAL = 120 ONCE = False +FRESH_CONTEXT = True _dir = os.path.dirname(os.path.abspath(__file__)) TASKS = os.path.join(_dir, '../sche_tasks')