逐日AI

面试题库

共 328 题,当前筛选 3 题。

标签
还有 125 个标签
#agent-loop2#behavioral2#claude-md2#coding-agent2#consistency2#context-engineering2#context-window2#distributed-systems2#embeddings2#framework-design2#interview-prep2#interview-process2#mcp2#memory2#observability2#orchestration2#prompt-engineering2#provider-abstraction2#rag2#resume2#scalability2#scheduling2#skills2#sse2#streaming2#structured-output2#tool-calling2#agent-basics1#agent-design1#agent-sdk1#agentic-rag1#agents-md1#api-design1#async-task1#auth1#backoff1#bi-encoder1#build-vs-buy1#career1#chunking1#communication1#concurrency1#configuration1#consistent-hashing1#content-safety1#context-assembly1#context-management1#coreference1#cost-accounting1#cost-analysis1#cross-encoder1#data-quality1#encoding1#failure-analysis1#fairness1#few-shot1#ffmpeg1#fine-tuning1#frontend1#global-market1#golden-set1#hooks1#human-in-the-loop1#hybrid-search1#image-generation1#ingestion1#json-schema1#jwt1#langgraph1#long-context1#long-term-memory1#maintenance1#mcp-basics1#media-pipeline1#mental-model1#message-bus1#messages-api1#migration1#model-routing1#moderation1#modularity1#multi-turn1#normalisation1#openai1#operations1#ordering1#overlap1#primitives1#prioritization1#priority-queue1#proactive-messaging1#product-engineering1#project-storytelling1#prompt1#prompt-basics1#prompt-bloat1#prompt-design1#prompt-injection1#prompt-surface1#prompt-techniques1#prompting1#protocol1#query-rewriting1#rag-basics1#rate-limiting1#redis-streams1#reliability1#responses-api1#retrieval1#routing1#sampling1#schema-validation1#scripts1#server-design1#sharding1#similarity1#skill-design1#stakeholder-communication1#star1#state-machine1#system-prompt1#test-set1#token-budget1#tts1#workflow-engine1

30 天从前端工程师到 Agent 工程师

D1 LLM API 基础:messages/roles、token、流式、temperature;Agent 到底是什么

  • 什么是 token 和上下文窗口?它们如何影响 Agent 的设计?What are tokens and the context window, and how do they shape agent design?
    国内高频海外高频基础#llm-basics#context

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

    1. 先判断这题问的是「概念」还是「工程后果」。只答定义会被认为没做过工程,必须落到设计影响上。
    2. 从一条因果链推:token 是计费与长度的计量单位 → 窗口是这个单位的上限 → 模型无状态、历史每轮重发 → 成本随轮数增长 → 所以必须做上下文工程。
    3. 关键要点出在「Agent 比聊天更严重」:Agent 在循环里反复调模型,还要把工具返回结果也塞回历史,增长速度快得多。
    4. 结论给出具体手段:滑动窗口、摘要压缩、长期记忆外置到检索系统,并说明各自代价。
    5. 可以预期的追问:窗口没满为什么也要压缩?答案是长上下文会稀释注意力、抬高延迟与成本,不是塞满了才处理。

    How to reason about it · think before answering

    1. First decide whether this asks for definitions or engineering consequences; a definition-only answer reads as inexperienced.
    2. Follow the causal chain: tokens are the unit of billing and length, the window caps that unit, models are stateless so history is resent every turn, cost grows with turns, hence context engineering.
    3. The differentiator is why agents suffer more: a loop calls the model repeatedly and appends tool results back into history.
    4. Close with concrete tactics: sliding window, summarization, externalized long-term memory, and the cost of each.
    5. Expect the follow-up: why compress before the window is full? Long contexts dilute attention and raise latency and cost.

    答题要点

    • token 是模型处理文本的最小单位,大致 1 个汉字 ≈ 1–2 token,1 个英文单词 ≈ 1.3 token
    • 上下文窗口是一次请求里输入 + 输出 token 的上限;超出就要截断或压缩
    • 模型没有记忆,历史必须每轮重新塞进 messages,所以长对话的成本随轮数线性增长
    • Agent 设计因此要做上下文工程:滑动窗口、摘要压缩、把长期记忆外置到检索系统

    Key points

    • A token is the smallest unit the model processes; roughly 1.3 tokens per English word
    • The context window caps input + output tokens per request; beyond it you truncate or compress
    • Models are stateless, so the full history is re-sent every turn and cost grows with length
    • Hence context engineering: sliding windows, summarization, and external long-term memory
  • messages 里的 system / user / assistant 三种角色各起什么作用?为什么要有 system?What do the system / user / assistant roles do, and why does system exist?
    国内高频海外高频基础#llm-basics#prompt

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

    1. 题眼在后半句「为什么要有 system」——前半句是送分,后半句才是区分度所在。
    2. 先说清三者构成一段可被模型续写的完整文本,角色是给这段文本打的结构化标记。
    3. 再回答「为什么」:如果把规则写进 user,它就只是对话里的一句话,会被后续几十轮对话稀释;放进 system 才能保持稳定权重,且便于产品侧统一管控、单独灰度。
    4. 补一条生产视角:真实的 system prompt 通常是模板拼出来的——人设 + 工具说明 + 记忆片段 + 当前时间,而不是一个写死的字符串。
    5. 常见追问:能不能把 system 放在最后?可以但不推荐,多数模型对靠前的指令更敏感,且会破坏缓存前缀。

    How to reason about it · think before answering

    1. The discriminating half is 'why does system exist'; the first half is a warm-up.
    2. Explain that the three roles are structural markers over one continuous text the model continues.
    3. Then the why: rules placed in user are just another turn and get diluted over dozens of turns; system keeps stable weight and can be governed centrally.
    4. Add production nuance: a real system prompt is templated — persona plus tool docs plus memory plus runtime facts.
    5. Likely follow-up: can system go last? Possible but unwise — models weight earlier instructions more and it breaks prompt-cache prefixes.

    答题要点

    • system 设定身份、边界与输出格式,通常放在最前面,权重高于普通对话
    • user 是用户输入,assistant 是模型历史回复,两者交替构成对话记录
    • 把规则放 system 而不是 user,是为了让规则不被后续对话冲淡,也便于产品统一管控
    • 生产里 system prompt 往往由模板拼接:人设 + 工具说明 + 记忆 + 当前时间等动态信息

    Key points

    • system sets identity, constraints and output format; it sits first and carries more weight
    • user is the human turn, assistant is the model's prior replies; they alternate
    • Rules live in system so they are not diluted by later turns and can be controlled centrally
    • In production the system prompt is templated: persona + tool docs + memory + runtime facts
  • temperature 和 top_p 分别控制什么?什么场景用 0,什么场景用 0.7?What do temperature and top_p control, and when would you use 0 versus 0.7?
    海外高频基础#llm-basics#sampling

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

    1. 先说清两者作用在同一个地方——模型算出的下一个 token 概率分布——但作用方式不同,这是区分度所在。
    2. temperature 是缩放整个分布:越低越尖锐、越确定;top_p 是截断——只保留累计概率达到 p 的那一小圈候选再采样。
    3. 由此推出实践建议:一般只调其中一个,两个同时调会互相干扰,出了问题分不清是谁造成的。
    4. 选值不按「创意程度」凭感觉,按「这一步的输出要不要可复现」来定:工具参数、分类判断、结构化输出必须可复现,用 0。
    5. 补一句 Agent 视角:Agent 的规划与工具调用环节几乎都用低温,只有最终面向用户的自然语言回复才考虑调高。

    How to reason about it · think before answering

    1. Establish that both act on the same next-token distribution but in different ways — that is the discriminator.
    2. temperature rescales the whole distribution; top_p truncates it to the smallest set reaching cumulative probability p.
    3. Hence the practical rule: tune one, not both, or you cannot attribute a regression.
    4. Choose by reproducibility, not by vibes: tool arguments, classification and structured output must be reproducible, so use 0.
    5. Add the agent angle: planning and tool-calling steps stay cold; only the final user-facing prose warrants higher values.

    答题要点

    • temperature 缩放下一个 token 的概率分布:越低越确定,越高越随机
    • top_p 只从累计概率达到 p 的候选里采样,是另一种截断随机性的方式;一般只调其中一个
    • 结构化输出、工具参数、分类判断用 0 或接近 0,保证可复现
    • 创意写作、头脑风暴用 0.7–1.0;生产 Agent 的规划步骤通常也偏低温

    Key points

    • temperature rescales the next-token distribution: lower is more deterministic, higher more random
    • top_p samples only from the smallest set whose cumulative probability reaches p; tune one, not both
    • Use ~0 for structured output, tool arguments and classification to keep results reproducible
    • Use 0.7–1.0 for creative writing; planning steps in production agents usually stay low