From e035e68c98d1203209157fd3d3e163f696e331fd Mon Sep 17 00:00:00 2001 From: Kailigithub Date: Thu, 28 May 2026 03:14:11 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20ga.py=20=E5=92=8C=20agentm?= =?UTF-8?q?ain.py=20=E4=B8=AD=E5=89=A9=E4=BD=99=E7=9A=84=E8=A3=B8=20except?= =?UTF-8?q?=20=E5=AD=90=E5=8F=A5=EF=BC=8C=E9=99=8D=E4=BD=8E=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E8=8E=B7=E7=B2=92=E5=BA=A6=E8=BF=87=E7=B2=97?= =?UTF-8?q?=E5=B8=A6=E6=9D=A5=E7=9A=84=E6=BD=9C=E5=9C=A8=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E9=A3=8E=E9=99=A9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改内容: - ga.py: 替换 stream_reader、log_memory_access、do_code_run、do_web_execute_js、_check_plan_completion 中的 bare except - agentmain.py: 替换 reload_llmclients 中的 bare except 本地验证:ruff check --select E722 ga.py agentmain.py 通过,语法检查通过 --- agentmain.py | 6 +++--- ga.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/agentmain.py b/agentmain.py index cf1d47c0..9122111d 100644 --- a/agentmain.py +++ b/agentmain.py @@ -59,14 +59,14 @@ def load_llm_sessions(self): mykeys, changed = reload_mykeys() if not changed and hasattr(self, 'llmclients'): return try: oldhistory = self.llmclient.backend.history - except: oldhistory = None + except Exception: oldhistory = None llm_sessions = [] for k, cfg in mykeys.items(): if not any(x in k for x in ['api', 'config', 'cookie']): continue try: if 'mixin' in k: llm_sessions += [{'mixin_cfg': cfg}] elif c := resolve_client(k): llm_sessions += [c] - except: pass + except Exception: pass for i, s in enumerate(llm_sessions): if isinstance(s, dict) and 'mixin_cfg' in s: try: @@ -84,7 +84,7 @@ def next_llm(self, n=-1): lastc = self.llmclient self.llmclient = self.llmclients[self.llm_no] try: self.llmclient.backend.history = lastc.backend.history - except: raise Exception('[ERROR] BAD Mixin config: Check your mykey.py') + except Exception: raise Exception('[ERROR] BAD Mixin config: Check your mykey.py') self.llmclient.last_tools = '' name = self.get_llm_name(model=True) if 'glm' in name or 'minimax' in name or 'kimi' in name: load_tool_schema('_cn') diff --git a/ga.py b/ga.py index 3737059f..b27edf93 100644 --- a/ga.py +++ b/ga.py @@ -48,8 +48,8 @@ def stream_reader(proc, logs): except UnicodeDecodeError: line = line_bytes.decode('gbk', errors='ignore') logs.append(line) try: print(line, end="") - except: pass - except: pass + except Exception: pass + except Exception: pass try: process = subprocess.Popen( @@ -159,7 +159,7 @@ def log_memory_access(path): stats_file = os.path.join(script_dir, 'memory/file_access_stats.json') try: with open(stats_file, 'r', encoding='utf-8') as f: stats = json.load(f) - except: stats = {} + except Exception: stats = {} fname = os.path.basename(path) stats[fname] = {'count': stats.get(fname, {}).get('count', 0) + 1, 'last': datetime.now().strftime('%Y-%m-%d')} with open(stats_file, 'w', encoding='utf-8') as f: json.dump(stats, f, indent=2, ensure_ascii=False) @@ -289,7 +289,7 @@ def do_code_run(self, args, response): code = self._extract_code_block(response, code_type) if not code: return StepOutcome("[Error] Code missing. Must use reply code block or 'script' arg.", next_prompt="\n") try: timeout = int(args.get("timeout", 60)) - except: timeout = 60 + except Exception: timeout = 60 raw_path = os.path.join(self.cwd, args.get("cwd", './')) cwd = os.path.normpath(os.path.abspath(raw_path)) code_cwd = os.path.normpath(self.cwd) @@ -348,10 +348,10 @@ def do_web_execute_js(self, args, response): try: with open(abs_path, 'w', encoding='utf-8') as f: f.write(str(content)) result["js_return"] += f"\n\n[已保存完整内容到 {abs_path}]" - except: result['js_return'] += f"\n\n[保存失败,无法写入文件 {abs_path}]" + except Exception: result['js_return'] += f"\n\n[保存失败,无法写入文件 {abs_path}]" show = smart_format(json.dumps(result, ensure_ascii=False, indent=2, default=json_default), max_str_len=300) try: print("Web Execute JS Result:", show) - except: pass + except Exception: pass yield f"JS 执行结果:\n{show}\n" next_prompt = self._get_anchor_prompt(skip=args.get('_index', 0) > 0) result = json.dumps(result, ensure_ascii=False, default=json_default) @@ -433,7 +433,7 @@ def enter_plan_mode(self, plan_path): def _check_plan_completion(self): if not os.path.isfile(p:=self._in_plan_mode() or ''): return None try: return len(re.findall(r'\[ \]', open(p, encoding='utf-8', errors='replace').read())) - except: return None + except Exception: return None def do_update_working_checkpoint(self, args, response): '''为整个任务设定后续需要临时记忆的重点。''' @@ -544,7 +544,7 @@ def _get_anchor_prompt(self, skip=False): if self.working.get('related_sop'): prompt += f"\n有不清晰的地方请再次读取{self.working.get('related_sop')}" if getattr(self.parent, 'verbose', False): try: print(prompt) - except: pass + except Exception: pass return prompt def turn_end_callback(self, response, tool_calls, tool_results, turn, next_prompt, exit_reason):