逐日AI

面试题库

共 328 题,当前筛选 2 题。

5 天上下文工程

D1 上下文是最稀缺的资源:窗口、注意力衰减与成本,从提示词工程走到上下文工程

  • 窗口越来越大了,为什么不能把所有可能有用的资料都塞进去?Context windows keep growing. Why not just put everything potentially relevant into the prompt?
    国内高频海外高频进阶#context-rot#attention-budget#cost

    分析过程 · 先想清楚再作答

    1. 这题的题眼是「你知不知道窗口是容量、注意力是预算」。只回答「太贵了」的人会被判成没做过工程,因为成本是三笔账里最容易想到、也最不致命的一笔。
    2. 怎么拆:分成能力和代价两条线。能力这条线要点出上下文腐烂——随着上下文变长,模型准确回忆其中信息的能力会下降,根源在于 Transformer 里 n 个 token 有 n 平方级别的两两关系,注意力被摊薄;而且训练语料里长序列本来就少,处理长距离依赖的参数不够多。
    3. 关键是要强调它是一条缓坡不是一道悬崖:没有哪个长度会突然崩掉,每多塞一千个不相干的 token,正确率就低一点点。这个措辞能立刻区分读过一手材料的人。
    4. 代价这条线给三笔账:钱(模型无状态,每轮全量重发,总输入是累加值不是最后那次的值)、延迟(首字返回变慢)、正确率(无关内容稀释注意力)。第三笔最贵,因为它不会报错,只会给出看起来合理但违反了约束的回答。
    5. 可预期的追问:那你怎么判断某段内容该不该加?给一条可执行的判据——说不出它会改变模型哪一个具体决定,就不该加。

    How to reason about it · think before answering

    1. The hinge is whether you treat the window as capacity or attention as a budget. Answering only with cost reads as inexperience, since cost is the easiest and least dangerous of the three bills.
    2. Split into capability and cost. On capability, name context rot: recall accuracy degrades as context grows, rooted in the n-squared pairwise relationships a transformer maintains over n tokens, plus the fact that long-range parameters are underrepresented in training.
    3. Stress that this is a gradient, not a cliff. No specific length breaks; every thousand irrelevant tokens shaves a little accuracy. That phrasing distinguishes people who read primary sources.
    4. On cost, give three bills: money (the model is stateless, so every turn resends everything and the total is cumulative, not the last call), latency (slower time to first token), and accuracy (irrelevant content dilutes attention). The third is worst because it never raises an error, it just returns a plausible answer that violates a stated constraint.
    5. Expect the follow-up: how do you decide whether a given chunk earns its place? Give an operational test: if you cannot name the specific decision it changes, it does not go in.

    答题要点

    • 窗口是容量,注意力是预算;容量够不代表模型用得好。
    • 上下文腐烂:上下文越长,准确回忆的能力越差,是渐进的性能梯度而不是一道悬崖。
    • 三笔账:钱(每轮全量重发,成本是累加值)、延迟、正确率。
    • 正确率那一笔最危险,因为它不报错,只会给出看似合理却违反约束的回答。
    • 判据:说不出这段内容会改变哪一个具体决定,就不该放进去。

    Key points

    • The window is capacity; attention is the budget. Fitting is not the same as being used well.
    • Context rot: recall degrades as context grows, as a gradient rather than a hard cliff.
    • Three bills: money (stateless models resend everything each turn, so cost is cumulative), latency, and accuracy.
    • Accuracy is the dangerous one because it fails silently with plausible answers that break stated constraints.
    • Test: if you cannot name the specific decision a chunk changes, leave it out.

D4 长时程会话:压缩、笔记与记忆文件、子代理隔离与交接摘要

  • 子代理为什么只回传摘要而不回传全过程?主代理该怎么写交接要求?Why does a subagent return only a summary instead of its full transcript, and how should the lead agent specify the handoff?
    国内高频海外高频深入#subagents#handoff#cost

    分析过程 · 先想清楚再作答

    1. 这题在考架构意图。答「为了省 token」只对了一半,而且是次要的那一半——子代理架构整体上是更贵的,不是更省的。
    2. 怎么拆:先说清目的。子代理隔离买的不是省钱,是主线上下文的干净。子代理可以在自己独立的窗口里烧掉几万 token 反复探索,主线只多了一两千 token 的浓缩结论,中间过程一个字都没进主线。这是关注点分离在上下文层面的落地。
    3. 把代价摆出来,这是最能体现做过工程的地方:Agent 类应用本来就比聊天多用约 4 倍 token,多 Agent 系统约 15 倍。所以适用面很窄——探索量大但产出能浓缩、子任务彼此独立可并行、主线确实不需要看中间过程,三条缺一就该退回压缩。
    4. 结论给交接契约:三段式(已定结论、待办事项、硬约束),且每条结论必须带来源标识(文件路径、订单号、URL)。原因是没有标识的结论不可复查,主线只能全盘相信或全盘重做;带标识之后主线可以只对存疑的那条做定点核实。硬约束那一段没有也要写「无」,不能省略,否则主线分不清是没有还是忘了写。
    5. 可预期的追问:主代理自己的计划怎么办?也该写到窗口外面。长任务后期一旦触发截断或压缩,最先丢的往往就是最初那份计划,而它恰恰最不该丢。

    How to reason about it · think before answering

    1. This tests architectural intent. Saying it saves tokens is only half right, and the lesser half: multi-agent setups are more expensive overall, not cheaper.
    2. State the purpose. Subagent isolation buys a clean main context, not a smaller bill. A subagent can burn tens of thousands of tokens exploring in its own window while the main thread gains only a condensed result of one or two thousand tokens. It is separation of concerns applied to context.
    3. Put the cost on the table, which is where engineering experience shows: agentic applications use roughly four times the tokens of chat, and multi-agent systems roughly fifteen times. So the fit is narrow: heavy exploration with a condensable result, independent parallelizable subtasks, and a main thread that genuinely does not need the intermediate steps. Missing any one, fall back to compaction.
    4. Conclusion: specify a handoff contract of three sections (settled conclusions, open items, hard constraints), with every conclusion carrying a source identifier such as a file path, order id, or URL. Without identifiers the main thread can only trust everything or redo everything; with them it can spot-check the one claim it doubts. Require the constraints section even when empty, or the main thread cannot tell absent from forgotten.
    5. Expect the follow-up about the lead agent's own plan: write it outside the window too, since truncation or compaction late in a long task tends to eat the original plan first.

    答题要点

    • 隔离买的是主线上下文的干净,不是省钱;多 Agent 整体更贵。
    • 代价数量级:Agent 约为聊天的 4 倍 token,多 Agent 约 15 倍。
    • 适用三条:探索量大且产出可浓缩、子任务独立可并行、主线不需要中间过程;缺一就退回压缩。
    • 交接契约三段式,每条结论必须带来源标识,硬约束段即使为空也要显式写「无」。
    • 主代理自己的计划也要写到窗口外,长任务里它最容易被截断或压缩吃掉。

    Key points

    • Isolation buys a clean main context, not savings; multi-agent is more expensive overall.
    • Magnitudes: agents use about four times chat tokens, multi-agent about fifteen times.
    • Fits when exploration is heavy but condensable, subtasks are independent and parallel, and the main thread does not need intermediate steps.
    • Handoff contract in three sections, every conclusion carrying a source identifier, and an explicit none when constraints are empty.
    • Persist the lead agent's plan outside the window, since it is the first casualty of truncation late in long tasks.