声明:不卖课不引流,纯粹技术分享
公司:字节跳动 | 岗位:AI Agent应用开发 | 时间:2026届校招
面试官看完候选人的Agent项目Demo后,问了一句:
“你的Agent调了三个工具就死循环了,异常处理在哪写的?”
候选人当场愣住了。说实话,大多数做Agent项目的人,压根没想过Agent还会死循环。
👇 考点拆解👇
2026年的面试已经升级为 “Agentic Engineering”实战考核——不再问“Agent是什么”,而是直击 Agent失败时的重试、熔断与自我修正机制。
面试官不是考你AI生成力,而是考你 “控AI不失控”的系统级工程能力。
👇 正确答法👇
| 重试机制 | |
| 熔断器 | |
| 循环检测 | |
| 最大轮数限制 | |
| 兜底输出 |
代码示例(循环检测核心逻辑)
class AgentLoopGuard:def __init__(self, max_rounds=20, max_retries=3, history_window=5):self.max_rounds = max_roundsself.max_retries = max_retriesself.history_window = history_windowself.action_history = []self.tool_failure_count = {}def should_stop(self, round_num: int, action: dict) -> tuple[bool, str]:# 1. 轮数上限检测if round_num >= self.max_rounds:return True, "达到最大轮数上限"# 2. 循环检测:最近N轮是否重复同一工具+同一参数action_key = f"{action.get('tool')}_{action.get('params')}"self.action_history.append(action_key)if len(self.action_history) > self.history_window:self.action_history.pop(0)if len(set(self.action_history)) == 1 and len(self.action_history) == self.history_window:return True, "检测到死循环:重复调用同一工具+同一参数"return False, ""def on_tool_failure(self, tool_name: str) -> tuple[bool, str]:self.tool_failure_count[tool_name] = self.tool_failure_count.get(tool_name, 0) + 1if self.tool_failure_count[tool_name] >= self.max_retries:return True, f"工具{tool_name}连续失败{self.max_retries}次,已熔断"return False, f"重试第{self.tool_failure_count[tool_name]}次"
这道题来自面题鸭——一个“免费+定向专属题”的工具
上传JD截图 → 自动生成15-20道专门针对这个岗位的考题。你投AI Agent岗,它出Agent系统设计的题;你投大模型岗,它出模型推理的题。
夜雨聆风