面试题库
共 328 题,当前筛选 2 题。
课程全部30 天从前端工程师到 Agent 工程师5 天提示词工程零基础Claude 高效使用:从对话到 Claude CodeCodex 与 OpenAI Agents SDK 高效使用7 天 MCP:把工具接进任何 Agent7 天 Agent Skills:把经验做成可复用能力5 天上下文工程14 天 RAG:从检索到可信回答14 天用 Agent 搭一条 AI 短剧生产线
标签
全部#prompt-caching2#evaluation13#cost11#reliability11#agent-skills7#security6#idempotency5#streaming5#system-design5#prompt-injection4#architecture3#observability3
还有 126 个标签收起标签
#agent-loop2#api-design2#chunking2#cost-tradeoff2#debugging2#distributed-systems2#error-handling2#hybrid-search2#llm-as-judge2#multi-agent2#multi-hop2#oauth2#operations2#pipeline-design2#rag2#recall2#retrospective2#retry2#scheduling2#sse2#tool-permissions2#trade-offs2#access-control1#agentic-rag1#agents-sdk1#analytics1#architecture-review1#behavioral1#budget-control1#caching1#cancellation1#checkpointing1#circuit-breaker1#citation-verification1#client1#client-integration1#coding-agent1#compaction1#compliance1#concurrency1#confused-deputy1#context-engineering1#contextual-retrieval1#copyright1#correctness1#cost-control1#customer-support1#data-quality1#database1#deployment1#distribution1#embedding-migration1#error-propagation1#escalation1#evidence1#faithfulness1#fallback1#feedback-loop1#fencing-token1#filter-pushdown1#filtering1#framework-design1#graph-rag1#guardrails1#handoff1#image-generation1#integration1#iterative-scan1#json-parsing1#labeling1#latency1#latency-budget1#least-privilege1#long-context1#long-session1#long-term-memory1#mcp1#message-bus1#methodology1#model-migration1#multi-tenancy1#notifications1#ocr1#offline-testing1#project-storytelling1#protocol-versions1#quality1#query-rewriting1#rate-limiting1#reconnect1#refusal1#replay1#reproducibility1#rerank1#resume1#retrieval1#risk-assessment1#rollout1#routing1#runtime1#safety1#scaling1#self-introduction1#split-brain1#state-management1#state-persistence1#statelessness1#stdio-transport1#storytelling1#subagent1#subagents1#subscriptions1#test-strategy1#thresholds1#timezone1#token-accounting1#tool-design1#tool-schema1#tools1#trust-boundary1#ux1#verification1#versioning1#workflow-design1#workflow-engine1#zero-downtime1
5 天上下文工程
D5 度量与调优:token 账单、上下文利用率、失败模式排查与综合面试专题
怎么给一个 Agent 算一次任务的 token 账单?哪些部分是可以被缓存掉的?How do you compute the token bill for one agent task, and which parts can be cached away?
国内高频海外高频深入#token-accounting#prompt-caching分析过程 · 先想清楚再作答
- 这题的第一个坑在「一次任务」四个字。很多人报的是单次请求的输入量,那是称重不是账单——模型没有记忆,每一轮都要把前面全部重发,账单是整场会话每轮输入的累加值。
- 怎么拆:按四块各自的增长方式分别求和。稳定前缀(系统提示加工具定义)每轮原样重发,乘轮数;对话历史线性增长,是等差数列求和;工具结果阶梯增长,按调用次数与每次体积估。举个量级:一个 20 轮的客服任务,最后一轮单次输入 11256,整场累加是 133502,差了将近 12 倍。
- 再谈缓存。可缓存的是稳定前缀这一段,顺序是工具定义、系统提示、消息,改前面的会让后面全部失效。经济学是写入约 1.25 倍原价(一小时存活期约 2 倍)、命中约 0.1 倍,所以 20 轮的前缀从 20 次全价变成一次写入加十九次命中,能便宜八成以上。
- 结论要带上那条门槛:前缀必须达到模型的最小可缓存长度才生效,达不到既不报错也不告警。这直接导致一个反直觉现象——把系统提示精简掉一半,token 数降了,账单反而可能涨,因为前缀掉到门槛以下、缓存静默失效。
- 可预期的追问:那还该不该精简?该,但要同时报两个数——不含缓存的 token 降幅与含缓存的等效开销降幅,并检查前缀有没有跨过门槛。跨过了就把稳定的引用内容放回前缀抬回去,或者换一个门槛更低的模型。
How to reason about it · think before answering
- The first trap is the phrase one task. Many people quote a single request's input size, which is a weight reading, not a bill. Stateless models resend everything each turn, so the bill is the sum of every turn's input.
- Sum the four buckets by their growth patterns. The stable prefix (system prompt plus tool definitions) is resent verbatim, so multiply by turn count. History grows linearly, so it is an arithmetic series. Tool results grow in steps, so estimate calls times size. For scale: a twenty-turn support task whose final request is 11256 tokens totals 133502 across the session, nearly twelve times larger.
- Then caching. The cacheable part is the stable prefix, ordered tools, system, messages, where editing anything earlier invalidates everything after. Writes cost about 1.25 times base (about 2 times for a one-hour lifetime) and hits about 0.1 times, so twenty full-price prefixes become one write plus nineteen hits, an eighty percent saving.
- State the threshold: the prefix must reach the model's minimum cacheable length or caching silently does nothing. That produces the counterintuitive result where halving your system prompt lowers token count but raises the bill, because the prefix fell below the threshold.
- Expect the follow-up on whether to trim anyway. Yes, but report two numbers: the raw token reduction and the cache-adjusted effective reduction, and check whether the prefix crossed the threshold. If it did, add stable reference content back into the prefix or move to a model with a lower threshold.
答题要点
- 账单是整场会话每轮输入的累加值,不是最后一次请求的输入量。
- 按四块的增长方式分别求和:前缀乘轮数、历史等差求和、工具结果按调用次数估。
- 可缓存的是稳定前缀,顺序是工具定义、系统提示、消息,改前面会让后面全失效。
- 写入约 1.25 倍、命中约 0.1 倍;但前缀必须达到最小可缓存长度,否则静默失效。
- 所以精简可能让 token 降而账单涨,必须同时报含缓存与不含缓存两个口径。
Key points
- The bill is the sum of every turn's input across the session, not the last request's size.
- Sum by growth pattern: prefix times turns, history as an arithmetic series, tool results by call count.
- The cacheable part is the stable prefix ordered tools, system, messages; editing earlier segments invalidates later ones.
- Writes cost about 1.25 times base and hits about 0.1 times, but only above the model's minimum cacheable length, which fails silently.
- So trimming can lower tokens while raising cost; always report both cached and uncached figures.
14 天 RAG:从检索到可信回答
D11 高级索引:父子文档、摘要索引、上下文检索,以及树状聚合与图检索的取舍
上下文检索要给每个块调一次模型,这笔一次性成本怎么估?有哪些办法能压下来?Contextual retrieval needs one model call per chunk. How do you estimate that one-off cost, and what levers bring it down?
国内高频海外高频深入#contextual-retrieval#prompt-caching#cost分析过程 · 先想清楚再作答
- 这题考的是你有没有真的算过账。只会说『用提示词缓存就便宜了』属于听过没做过——面试官会追问缓存到底省在哪一项上。
- 先把成本拆开:一次性 = 每块的输入 + 输出 + 全量 embedding;每次查询 = 块头在重排和上下文里各被读一遍。**这两笔要分开记**,因为它们随业务量的增长方式完全不同。
- 一次性那笔的主项是『同一篇文档被重复读了多少遍』。一篇切成 n 块就要读 n 遍,这是成本的大头。提示词缓存省的正是这一项:把整篇放在提示词最前面并标记为可缓存,第一块付一次缓存写入,后面 n-1 块只付缓存读取,而读取价通常比输入价低一个数量级。
- 顺序不能反:缓存按前缀匹配,整篇必须在前、块内容在后。把变化的块放前面,前缀次次都变,缓存一次都不会命中——这是最常见的翻车点。
- 我们的实测:30 篇、134 块,不开缓存输入 103017 token,开缓存后拆成写入 17340 加读取 60137,一次性成本降约 29%。**块切得越碎这个比例越高**,因为重复读的次数更多。
- 结论反直觉但很实用:一次性那笔是小钱,摊到 217 次查询就降到每次查询成本的一成以下;真正的长期账是每次查询多出来的那几十个 token(我们量到 +12.3%)。所以压成本的第一优先级不是压建索引,而是让块头别进上下文、别过长、别对全库无差别地生成。
- 最后一条是加分项:花这笔钱之前先确认你的评估环境**测得出**收益。我们的离线环境里向量路对召回的独立贡献实测为 0,所以它根本没法回答『块头对向量侧有没有用』——在这种环境里做的 A/B 会给你一个看起来有数字支撑的错误结论。
How to reason about it · think before answering
- This checks whether you have actually done the arithmetic. Saying 'prompt caching makes it cheap' without knowing which line item it touches is a tell.
- Split the bill first: one-off = per-chunk input + output + full re-embedding; per-query = the header read twice, once by the reranker and once in the context. Keep them separate, because they scale with completely different things.
- The dominant term on the one-off side is how many times the same document is re-read. A doc split into n chunks is read n times. Prompt caching attacks exactly that: put the whole document first and mark it cacheable, pay a cache write once, then cache reads for the remaining n-1, typically an order of magnitude cheaper than input.
- Order matters. Caching is prefix-matched, so the document must come first and the chunk after. Put the varying part first and the prefix changes every call — zero cache hits. This is the most common way people get it wrong.
- Our measurement: 30 docs, 134 chunks. Without caching, 103017 input tokens; with caching, 17340 written plus 60137 read, cutting the one-off cost by roughly 29%. The finer the chunks, the bigger the saving, because re-reads multiply.
- The counter-intuitive part is the useful part: the one-off cost amortizes below 10% of per-query cost after about 217 queries. The lasting bill is the extra tokens every query carries (we measured +12.3%). So the first lever is not cheaper index building — it is keeping the header out of the context, keeping it short, and not generating it for the whole corpus indiscriminately.
- A bonus point: before spending any of it, confirm your evaluation setup can actually detect the benefit. In our offline harness the vector route contributed exactly zero unique answer documents, so it cannot answer whether headers help embeddings at all — an A/B run there hands you a wrong conclusion that looks numerically supported.
答题要点
- 把账拆成一次性(每块的输入输出 + 全量 embedding)和每次查询(块头在重排与上下文里各读一遍)两笔。
- 一次性的大头是同一篇被重复读 n 遍;提示词缓存把它压成一次写入加 n-1 次读取。
- 缓存按前缀匹配,整篇必须放在提示词最前面,块内容在后,顺序反了一次都不会命中。
- 实测 30 篇 134 块,一次性成本降约 29%,块越碎省得越多。
- 长期账在每次查询:块头别进上下文、控制长度、只对真正需要的文档生成。
Key points
- Split into one-off (per-chunk input/output plus re-embedding) and per-query (header read by both reranker and generator).
- The one-off is dominated by re-reading each document n times; caching turns that into one write plus n-1 reads.
- Caching is prefix-matched: the full document must come first, the chunk after, or you get zero hits.
- Measured on 30 docs / 134 chunks, caching cut the one-off cost by about 29%, and finer chunks save more.
- The lasting cost is per query: keep headers out of the context window, keep them short, and generate them selectively.