看得懂 · 判得准 · 说得清
拿到一段 Agent 代码,先别跑。用笔标注每个变量的输入输出、数据怎么流转、哪里可能炸。
import json def run_agent(task, memory=[]): # 简单的 ReAct 循环 prompt = f"任务:{task}\n历史:{memory}" resp = call_llm(prompt) thought = resp["thought"] action = resp["action"] if action == "search": result = search_web(resp["query"]) memory.append(str(result)) elif action == "done": return resp["answer"] return run_agent(task, memory)
一段 25 行能跑但难读的脚本。目标:拆成职责单一的小函数,并画出数据流箭头。
import csv, json def process(path): rows = [] with open(path) as f: for r in csv.DictReader(f): if r["age"].isdigit() and int(r["age"]) > 0: rows.append({"name": r["name"].strip(), "age": int(r["age"])}) total = sum(x["age"] for x in rows) avg = total / len(rows) if rows else 0 adults = [x for x in rows if x["age"] >= 18] report = { "count": len(rows), "avg_age": round(avg, 1), "adults": len(adults), "names": [x["name"] for x in adults] } out = path.replace(".csv", "_report.json") with open(out, "w") as f: json.dump(report, f, ensure_ascii=False) return out
load_valid_rows(path) -> list:读取并清洗数据calc_stats(rows) -> dict:算总数/均龄/成年人数build_report(rows, stats) -> dict:组装报告save_report(report, path) -> str:写 JSON 文件面对需求,三步走:选对库 → 查准方法签名 → 验证 AI 给的代码是否真的对。
pypdf 或 pdfplumber;核心签名 page.extract_text();注意扫描件无文本层需 OCRpandas 的 df.groupby("部门").sum() + matplotlib 的 plt.bar();验证 AI 是否用了已废弃的 pd.read_excel 旧参数requests.get(url, timeout=10) + 重试用 urllib3.Retry 挂载到 Session;检查 AI 是否漏了 timeout(最常见的坑)「K3/Claude 写代码比你快 100 倍,
但看得懂、判得准的能力,只有自己能长。」