Glean 拾遗
Daily /2026-08-10 / 17 Techniques for Improving Your LLM-Powered App

17 Techniques for Improving Your LLM-Powered App

Source www.aihero.dev Glean’d 2026-08-10 06:00 Read 23 min
AI summary

This guide walks through 17 techniques for improving LLM-powered applications, deliberately ordered from cheapest to most expensive on what the author calls the Staircase of Complexity Hell. It starts with prompt tweaks — role prompting, XML tags, structured outputs, chain-of-thought, multishot, temperature, and tool calling — before moving to system-level patterns: RAG, chunking, agentic loops, parallelization, evaluator-optimizer, LLM routers, and fine-tuning. The core advice: work down the staircase only after simpler options are exhausted. Concrete evidence includes Claude 4.6 returning 400 on prefilling, parallel processing cutting 10-document analysis from ~10s to 2-3s, routers bypassing the common ~30-tool limit per model, and fine-tuned smaller models beating larger ones on specific tasks. Each section names real trade-offs, such as CoT increasing latency and agentic loops adding decision overhead. Useful as a practical checklist for engineers iterating on LLM systems.

Original · 23 min
www.aihero.dev ↗
§ 1

Once you clearly understand your success criteria, have picked your model, and written some basic evals, it's time to start improving your system.

The process of improving your system comes down to two things:

Improving your feedback loop (evals)

Improving the performance of the system itself

We've already looked at how to improve your evals. In this article, I'll give you an overview of the main ways you can improve your system.

当你清楚了自己的成功标准,选好了模型,也写了一些基础评估(evals)之后,就可以开始改进系统了。

改进系统的过程归结为两件事:

改进你的反馈回路(evals)

改进系统本身的性能

我们已经在前面看过如何改进评估。这篇文章里,我会概述改进系统的主要方法。

§ 2

But first, let's talk about the mindset you need to have when improving your system.

We've already seen that improving an AI system is an experimental process. You need to try things out, see what works, and iterate.

Techniques for improving a system range from simple and cheap to complex and expensive. Tweaking a prompt? Cheap. Training a model from scratch? Astonishingly expensive.

I call this the Staircase Of Complexity Hell:

The key is to start at the top of the staircase, and work your way down only when you've exhausted all the simpler options. Simple techniques can provide a huge improvement for a small amount of effort.

This list is ordered from the simplest techniques to the most complex. Start at the top, and work your way down. I've linked to further resources where you can get more details on each technique.

但首先,我们来谈谈改进系统时需要具备的心态。

前面已经说过,改进 AI 系统是一个实验性的过程。你需要不断尝试、看什么有效、再迭代。

改进系统的技术,从简单廉价到复杂昂贵都有。改一改提示词?便宜。从头训练一个模型?贵得惊人。

我把这称为“复杂度地狱阶梯”(Staircase Of Complexity Hell):

关键在于从阶梯的顶端开始,只有在所有更简单的选项都试过之后,才逐级往下走。简单的技术往往能花很小的力气带来巨大的改进。

这份清单按从最简单到最复杂排序。从顶部开始,逐步往下。我附上了进一步资源的链接,你可以从中了解每项技术的更多细节。

§ 3

Problem: You've got to start somewhere.

Solution: Here are some basic tips for improving your prompts:

Be clear, direct, and specific.

Think of the LLM as a brilliant, but very new, employee.

Remember that the LLM has no context on your norms, styles, or guidelines.

Resources

Anthropic's Advice is a useful guide for understanding how to write good prompts.

Anthropic's Prompt Library is a great way to explore good prompts for your use case.

OpenAI's docs on writing clear instructions.

问题:你总得从某个地方开始。

解决方案:以下是改进提示词的一些基本要点:

清晰、直接、具体。

把 LLM 想象成一个很聪明但非常新的员工。

记住,LLM 对你的规范、风格或准则一无所知。

资源

Anthropic 的建议(Advice)是一份很有用的指南,能帮你理解如何写好提示词。

Anthropic 的提示词库(Prompt Library)是探索适合你场景的好提示词的好方法。

OpenAI 关于编写清晰指令的文档。

§ 4

Problem: You want the LLM to behave in a certain way no matter the input.

Solution: Use role-based prompting to get the LLM to adopt a persona.

This could be as diverse as adjusting the tone of voice:

You are a friendly support engineer. Answer in short, plain sentences.

Or even the accent:

You are a concise British copy editor. Keep the answer dry and understated.

Or prime the LLM to talk about a certain topic:

You are an AI engineering coach. Explain tradeoffs in terms of evals, latency, and cost.

This is an extremely common technique, and very cheap to implement. It's usually done in a system prompt.

Resources

My video on System Prompts in Vercel's AI SDK

Anthropic's docs on role-based prompting

OpenAI's docs on asking the model to adopt a persona

问题:你希望 LLM 无论收到什么输入,都以某种特定方式行事。

解决方案:使用角色提示(role-based prompting),让 LLM 采纳一个角色。

这可以像调整语气一样多样:

你是一位友好的支持工程师。用简短、平实的句子回答。

甚至可以调整腔调:

你是一位简洁的英国文字编辑。回答保持干练、克制。

或者引导 LLM 谈论某个特定主题:

你是一位 AI 工程教练。用评估、延迟和成本来解释各种权衡。

这是一种非常常见且实现成本极低的技术,通常放在系统提示词(system prompt)中完成。

资源

我在 Vercel AI SDK 中关于系统提示词的视频

Anthropic 关于角色提示的文档

OpenAI 关于让模型采纳角色的文档

§ 5

XML Tags On The Input

Problem: You want to pass multiple pieces of information to the LLM in a single prompt.

Solution: Use XML tags.

XML tags can help provide delimiters for different parts of the prompt.

An example from Anthropic's docs is a financial report:

<source>2025 annual report</source>

<document_content>Revenue increased 18% year over year...</document_content>

<source>Q1 investor update</source>

<document_content>Gross margin improved after infrastructure costs fell...</document_content>

Using only the documents above, summarize the main business risks.

XML Tags On The Output

Problem: You want the LLM to respond with multiple different outputs.

Solution: Tell the LLM to respond with different outputs based on the XML tags.

You can also tell your LLM to respond with different outputs based on the XML tags in the prompt. This can give you more control over the structure of the response.

You may want the LLM to review an article for you. You may want it to provide a <summary>, a <critique>, and <recommended_changes>.

Review this article and respond using this exact structure:

<summary>One paragraph summary</summary>

<critique>What is unclear or unsupported</critique>

<recommended_changes>Concrete edits to make next</recommended_changes>

This technique was popularised by Anthropic, but most models also support it.

Resources

Anthropic's docs on using XML tags in your prompts

OpenAI's docs mention using XML tags as delimiters

输入侧使用 XML 标签

问题:你想在单个提示词中向 LLM 传递多条信息。

解决方案:使用 XML 标签。

XML 标签可以为提示词的不同部分提供分隔符。

Anthropic 文档中的一个例子是财务报告:

<source>2025 annual report</source>

<document_content>Revenue increased 18% year over year...</document_content>

<source>Q1 investor update</source>

<document_content>Gross margin improved after infrastructure costs fell...</document_content>

仅使用上面的文档,总结主要业务风险。

输出侧使用 XML 标签

问题:你希望 LLM 返回多个不同的输出。

解决方案:让 LLM 根据 XML 标签返回不同输出。

你也可以让 LLM 根据提示词中的 XML 标签返回不同的输出,这样可以更好地控制回复的结构。

比如你可能希望 LLM 帮你审阅一篇文章,提供 <summary>、<critique> 和 <recommended_changes>。

审阅这篇文章,并使用以下确切结构回复:

<summary>一段总结</summary>

<critique>哪些地方不清楚或缺乏依据</critique>

<recommended_changes>接下来要做的具体修改</recommended_changes>

这项技术由 Anthropic 推广开来,但大多数模型也支持。

资源

Anthropic 关于在提示词中使用 XML 标签的文档

OpenAI 文档提到使用 XML 标签作为分隔符

§ 6

Problem: You want to tightly constrain the text that comes back from the LLM, such as asking it to reply with JSON or a single word.

Solution: Use structured outputs or explicit format instructions.

Older versions of Claude supported "prefilling" the assistant message to steer the response format. As of Claude 4.6, prefilling returns a 400 error. The modern alternatives are better:

Structured Outputs (recommended): Most LLM providers now support structured output schemas that guarantee the response matches a specific JSON shape. With the Vercel AI SDK, use generateObject or streamObject:

const result = await generateObject({

sentiment: z.enum(['positive', 'neutral', 'negative']),

prompt: 'Classify this customer feedback...',

System prompt instructions: For simpler constraints, tell the model what format you want in the system prompt:

Reply with exactly one of these labels: bug, feature-request, billing, or other.

Do not include any explanation.

Both approaches are more reliable than prefilling ever was. Structured outputs give you type-safe, validated responses. System prompt instructions work when you need flexible text output in a specific shape.

Resources:

Anthropic: Structured Outputs

Vercel AI SDK: generateObject

问题:你想严格约束 LLM 返回的文本,比如要求它回复 JSON 或一个单词。

解决方案:使用结构化输出(structured outputs)或显式格式指令。

旧版 Claude 支持通过“预填充”(prefilling)助手消息来引导回复格式。从 Claude 4.6 开始,预填充会返回 400 错误。现代替代方案更好:

结构化输出(推荐):大多数 LLM 提供商现在都支持结构化输出 schema,保证响应符合特定的 JSON 结构。在 Vercel AI SDK 中,使用 generateObject 或 streamObject:

const result = await generateObject({

sentiment: z.enum(['positive', 'neutral', 'negative']),

prompt: 'Classify this customer feedback...',

系统提示词指令:对于更简单的约束,直接在系统提示词中告诉模型你想要的格式:

只回复以下标签之一:bug、feature-request、billing 或 other。

不要包含任何解释。

这两种方法都比预填充更可靠。结构化输出给你类型安全、经过校验的响应;系统提示词指令则适合需要特定形状的灵活文本输出。

资源:

Anthropic:结构化输出

Vercel AI SDK:generateObject

§ 7

Problem: You want the LLM to return structured data instead of text.

Solution: Use structured outputs.

Structured outputs are a way to get the LLM to return data in a structured format, like JSON. Most LLM providers support providing a JSON schema description of the output you want.

The Vercel AI SDK is a particularly good toolset for this.

Resources

Anthropic's Docs on JSON mode

问题:你希望 LLM 返回结构化数据而不是文本。

解决方案:使用结构化输出。

结构化输出是一种让 LLM 以结构化格式(如 JSON)返回数据的方式。大多数 LLM 提供商都支持提供 JSON schema 来描述你想要的输出。

Vercel AI SDK 在这方面尤其好用。

资源

Anthropic 关于 JSON 模式的文档

§ 8

Problem: The LLM is not doing well enough at complex, multi-step reasoning tasks, like coding or math problems.

Solution: Prompt the LLM to reason through the problem using chain-of-thought (CoT) prompting.

Chain-of-thought prompting encourages the LLM to break down problems step-by-step, leading to more accurate and nuanced outputs. This technique is particularly effective for tasks that require complex reasoning, analysis, or problem-solving.

There are three main approaches to chain-of-thought prompting, from simplest to most complex:

Basic CoT: Simply include "Think step-by-step" in your prompt. While simple, this lacks guidance on how to think.

Guided CoT: Outline specific steps for the LLM to follow in its thinking process.

Structured CoT: Use XML tags like <thinking> and <answer> to separate reasoning from the final answer.

Chain-of-thought prompting trades speed for quality. The LLM must process and output its reasoning steps, so the response time gets longer. This matters most in real-time applications - a chatbot needs quick responses, while a code reviewer can take longer for detailed analysis.

Resources

Anthropic's docs on chain-of-thought prompting

OpenAI's advice on giving the model time to think before coming to a conclusion

问题:LLM 在复杂的多步推理任务(如编程或数学题)上表现不够好。

解决方案:使用链式思考(chain-of-thought, CoT)提示,让 LLM 逐步推理。

链式思考提示鼓励 LLM 把问题一步步拆解,从而得到更准确、更细腻的输出。这项技术对于需要复杂推理、分析或问题解决的任务尤其有效。

链式思考提示主要有三种方式,从最简单到最复杂:

基础 CoT:只需在提示词中加上“一步步思考”(Think step-by-step)。虽然简单,但缺乏对思考方式的引导。

引导式 CoT:为 LLM 的思考过程列出具体步骤。

结构化 CoT:使用 <thinking> 和 <answer> 等 XML 标签,把推理过程和最终答案分开。

链式思考是用速度换质量。LLM 必须处理和输出推理步骤,因此响应时间会更长。这在实时应用中最为关键——聊天机器人需要快速响应,而代码审查员则可以花更长时间做详细分析。

资源

Anthropic 关于链式思考提示的文档

OpenAI 关于在得出结论前给模型时间思考的建议

§ 9

Problem: The LLM needs to understand a specific pattern or format but isn't getting it from a single example.

Solution: Provide multiple examples to help the LLM understand the pattern.

Multishot prompting can achieve results similar to fine-tuning, but without the cost and complexity of training a new model. It works by showing the model examples of what you want it to do.

It's straightforward - provide a few examples of input and output, and the model learns the pattern. No training data or compute resources needed.

Here's a practical example for writing product descriptions:

Write product descriptions in this style.

Input: Noise-canceling headphones

Output: Sink into your work with soft over-ear cushions and active noise cancellation that quiets the room around you. Great for deep focus, travel, and calls that need fewer distractions.

Output: Move from sitting to standing in seconds with a sturdy desk that keeps your monitor, keyboard, and coffee exactly where you need them. Built for long workdays without locking you into one posture.

Output: Light foam, breathable mesh, and a grippy sole make these shoes feel quick without beating up your feet. Perfect for daily miles, recovery runs, and the walk home after.

After seeing these examples, the model learns to write product descriptions with sensory language and focus on benefits. If you then give it "Input: Coffee maker", it will generate a similar style description.

Multishot prompting contrasts with zero-shot prompting, where you just describe what you want without examples.

Resources

Anthropic's docs on multishot prompting

OpenAI's docs on providing examples

问题:LLM 需要理解某个特定模式或格式,但只给一个示例还不够。

解决方案:提供多个示例,帮助 LLM 理解模式。

多示例提示(multishot prompting)可以达到与微调类似的效果,却不需要训练新模型的成本和复杂性。它的原理是向模型展示你希望它做什么的示例。

方法很直接——给出一些输入和输出的示例,模型就能学会模式。不需要训练数据或计算资源。

下面是一个写产品描述的实用例子:

用这种风格写产品描述。

输入:降噪耳机

输出:柔软的耳罩式衬垫加上主动降噪,让你沉浸在专注工作中,周围房间安静下来。非常适合深度专注、旅行以及需要减少干扰的通话。

输出:一张稳固的桌子,几秒钟内从坐姿切换到站姿,显示器、键盘和咖啡都放在你需要的位置。专为长时间工作而设计,不会让你固定在一个姿势上。

输出:轻质泡沫、透气网面和抓地力强的鞋底让这双鞋感觉轻快,又不会让双脚受累。适合日常跑步、恢复跑和走回家的路。

看到这些示例后,模型就学会了用感官语言、围绕好处来写产品描述。这时你再给它“输入:咖啡机”,它就会生成类似风格的描述。

多示例提示与零样本提示(zero-shot prompting)相对,后者只是描述你想要什么,不给示例。

资源

Anthropic 关于多示例提示的文档

OpenAI 关于提供示例的文档

§ 10

Problem: The LLM's outputs are either too deterministic (boring) or too random (unreliable).

Solution: Adjust the temperature parameter to control the randomness of outputs.

You can pass a temperature parameter to the LLM. This controls how random or deterministic the LLM's outputs are.

Think of temperature as your creativity dial. When you're writing code or need precise facts, you'll want to specify 0.0-0.3 - this makes the model stick to the most likely outputs. For general chat or creative writing, a medium setting of 0.4-0.7 gives you a nice balance. And when you're brainstorming or need fresh ideas, bump it up to 0.8-1.2.

Higher temperature means more interesting outputs, but might produce more hallucinations. My general suggestion is to start conservative and dial it up only when you need more variety.

Either way, it's a relatively cheap technique to try.

Resources

OpenAI's API Reference explains how temperature affects token sampling

问题:LLM 的输出要么过于确定(无聊),要么过于随机(不可靠)。

解决方案:调整 temperature 参数,控制输出的随机性。

你可以向 LLM 传入 temperature 参数,它控制输出的随机程度或确定程度。

把 temperature 想成你的创意旋钮。写代码或需要精确事实时,设到 0.0-0.3——让模型坚持最可能的输出。普通聊天或创意写作时,中档 0.4-0.7 能取得不错的平衡。头脑风暴或需要新鲜点子时,再调到 0.8-1.2。

温度越高,输出越有趣,但也可能产生更多幻觉。我的总体建议是从保守开始,只有在需要更多变化时再调高。

无论如何,这都是一个相对便宜、值得一试的技术。

资源

OpenAI API 参考解释了 temperature 如何影响 token 采样

§ 11

Problem: LLMs are limited to text generation and can't directly interact with external systems or perform actions in the world.

Solution: Give the LLM access to specific functions or tools it can call to extend its capabilities beyond text generation.

Tool calling bridges the gap between an LLM's internal capabilities and the external world. It allows LLMs to perform actions like making API calls, accessing databases, or manipulating files. The LLM describes what it wants to do, and the system executes the appropriate tool with the specified parameters.

This pattern is particularly useful when you need your LLM to interact with external services, perform system operations, or access data that isn't in its training data. It's a fundamental building block for creating more capable AI applications.

You can learn how to implement this pattern using Vercel's AI SDK in my tutorial.

Resources

Anthropic's docs on tool calling

OpenAI's docs on function calling

问题:LLM 只能生成文本,无法直接与外部系统交互或在现实世界中执行操作。

解决方案:给 LLM 提供它可以调用的特定函数或工具,把能力扩展到文本生成之外。

工具调用(tool calling)弥合了 LLM 内部能力与外部世界之间的差距。它让 LLM 可以执行 API 调用、访问数据库或操作文件等操作。LLM 描述它想做什么,系统用指定的参数执行相应的工具。

当你需要 LLM 与外部服务交互、执行系统操作或访问训练数据中没有的数据时,这种模式尤其有用。它是构建更强大 AI 应用的基础构件。

你可以在我的教程中学习如何用 Vercel 的 AI SDK 实现这种模式。

资源

Anthropic 关于工具调用的文档

OpenAI 关于函数调用的文档

§ 12

Problem: A single LLM call isn't sufficient to complete a complex task.

Solution: Break down the task into multiple LLM calls that build on each other.

When you need to perform multiple specialized operations on the same input, trying to do everything in a single prompt often leads to subpar results. Each operation might need different expertise and focus.

This is where LLM call chaining comes in. Instead of asking one prompt to do everything, you break the task into specialized steps. Each prompt focuses on one aspect of the task, and its output becomes the input for the next prompt in the chain.

Take code analysis and fix generation as an example. The first prompt acts as a code analyzer, identifying and categorizing issues in the code. It provides context for each issue, creating a structured analysis.

The second prompt then uses this analysis to generate targeted fixes, building on the first prompt's insights. This separation of concerns allows each prompt to be optimized for its specific task, leading to better results than trying to do both operations in a single prompt.

This pattern can be applied to many other scenarios:

First analyze a document's structure, then generate a summary

First identify key points in a debate, then craft a balanced response

First extract facts from research, then write a layperson explanation

First identify bugs in code, then generate fixes for each one

Resources

Anthropic's docs on prompt chaining

UPDATE: OpenAI has removed their guide on using inner-monologue

问题:单次 LLM 调用不足以完成复杂任务。

解决方案:把任务拆成多次相互衔接的 LLM 调用。

当你需要对同一输入执行多个专业操作时,试图用一个提示词完成所有事情,结果往往不理想。每个操作可能需要不同的专长和侧重点。

这就是 LLM 调用链(LLM call chaining)的用武之地。你不用让一个提示词包办一切,而是把任务拆成专门的步骤,每个提示词专注任务的一个方面,其输出成为链中下一个提示词的输入。

以代码分析和修复生成为例。第一个提示词扮演代码分析器,识别并归类代码中的问题,为每个问题提供上下文,形成结构化分析。

第二个提示词再利用这份分析生成针对性的修复,建立在第一个提示词的洞察之上。这种关注点分离让每个提示词都能针对自己的任务进行优化,比在一个提示词里同时做两件事效果更好。

这种模式还可以应用到很多其他场景:

先分析文档结构,再生成摘要

先找出辩论中的关键论点,再写出平衡的回应

先从研究中提取事实,再写一版通俗易懂的解释

先识别代码中的 bug,再为每个 bug 生成修复

资源

Anthropic 关于提示词链的文档

更新:OpenAI 已移除关于使用 inner-monologue 的指南

§ 13

Problem: Your LLM is making up facts because it can't access the information it needs.

Solution: Give it access to real data through retrieval augmented generation.

RAG is a powerful technique for grounding your LLM's responses in actual data and reducing hallucinations. Every LLM has a cutoff date for its training data - it can't know about events or information after that date. Instead of relying on what it learned during training, it can look up fresh information as needed.

You've got two main ways to feed data to your LLM. Web search gives you access to current information and public knowledge. Company databases and documentation let you tap into private, domain-specific information. This is particularly useful when you need answers about your company's internal processes or want to ensure your LLM's responses are up-to-date.

RAG shouldn't be your first port of call when building an LLM application. It adds significant complexity to your system - you need to manage data sources, handle retrieval, and ensure your context windows stay within limits.

Resources

OpenAI's article on RAG and semantic search. There is also a section in their official docs.

问题:LLM 因为无法访问所需信息而在编造事实。

解决方案:通过检索增强生成(RAG)让它访问真实数据。

RAG 是一种强大的技术,能把 LLM 的回复锚定在实际数据上,减少幻觉。每个 LLM 都有训练数据的截止日期——它无法知道截止日期之后的事件或信息。与其只依赖训练时学到的内容,它可以在需要时查找最新信息。

给 LLM 喂数据主要有两种方式。网络搜索让你获得当前信息和公共知识;公司数据库和文档则可以接入私有的、领域特定的信息。当你需要回答公司内部流程相关的问题,或希望确保 LLM 的回复是最新的时,这尤其有用。

构建 LLM 应用时,RAG 不应该是你的首选。它会显著增加系统复杂性——你需要管理数据源、处理检索,并确保上下文窗口不超限。

资源

OpenAI 关于 RAG 和语义搜索的文章。他们的官方文档中也有相关章节。

§ 14

Problem: The information you want to retrieve is too large to fit in the context window.

Solution: Break down the information into smaller, manageable chunks.

Chunking is a fundamental technique in RAG systems that breaks down large documents into smaller, more manageable pieces. The goal is to create chunks that are both semantically meaningful and small enough to fit within your model's context window.

The complexity of chunking comes from the many ways you can split content. Here are the main approaches:

Token-based: Splits content based on token count, ensuring you stay within model limits

Character-based: Splits by character count, useful for raw text processing

Sentence-based: Preserves natural language boundaries

Paragraph-based: Maintains larger semantic units

Semantic boundaries: Uses embeddings to find natural break points

Document-structure: Respects document formatting (headers, sections, etc.)

After chunking, you'll need to find the most relevant chunks for each query. Here are the main ways to do this:

BM25: A traditional search algorithm that finds exact word matches, great for technical terms and error codes

Embeddings: Converts text into vectors to find semantically similar chunks

Hybrid Search: Combines BM25 and embeddings for better results

LLM Reranking: Uses another LLM to carefully read and rank chunks by relevance

Each approach has its strengths - BM25 excels at exact matches, while embeddings capture meaning. Many systems combine multiple approaches for the best results.

Resources

Pinecone's guide on chunking strategies

Anthropic's research on contextual retrieval

Research paper on evaluating chunking strategies

问题:你想检索的信息太大,放不进上下文窗口。

解决方案:把信息拆成更小、更易管理的块。

分块(chunking)是 RAG 系统中的一项基础技术,它把大文档拆成更小、更易处理的部分。目标是创建既在语义上有意义、又小到能放进模型上下文窗口的块。

分块的复杂性在于切分内容的方式有很多种。以下是主要方法:

基于 token:按 token 数量切分,确保不超出模型限制

基于字符:按字符数切分,适合原始文本处理

基于句子:保留自然语言的边界

基于段落:维持更大的语义单元

语义边界:用 embedding 找到自然的断点

文档结构:尊重文档格式(标题、章节等)

分块之后,你需要为每个查询找到最相关的块。主要方式有:

BM25:传统搜索算法,能精确匹配词语,适合技术术语和错误码

Embeddings:把文本转换成向量,寻找语义相似的块

混合检索(Hybrid Search):结合 BM25 和 embeddings,效果更好

LLM 重排(LLM Reranking):用另一个 LLM 仔细阅读并按相关性对块排序

每种方法各有优势——BM25 擅长精确匹配,embeddings 则能捕捉语义。很多系统会把多种方法结合起来以获得最佳效果。

资源

Pinecone 关于分块策略的指南

Anthropic 关于上下文检索的研究

评估分块策略的研究论文

§ 15

Problem: LLM call chaining is too rigid for complex tasks. It requires predefined steps and stopping points, making it unsuitable for open-ended problems where the number of steps is unpredictable.

Solution: Pass control to an autonomous agent that can plan, execute, and adapt based on environmental feedback.

LLM call chaining uses predefined steps and stopping points, which limits its ability to handle unpredictable tasks. Agentic loops hand more control to the LLM - letting it decide when to stop based on task progress. The agent learns when to stop through real-world feedback.

The resulting system is more powerful because it adapts to unpredictable paths. Instead of following predefined steps, it learns and adjusts based on each interaction. This makes it effective for complex problems where the solution isn't known in advance.

This autonomy comes with a cost - increased latency from decision-making at each step. The LLM must evaluate the current state and choose the best path forward. This makes agentic loops slower than LLM call chaining, but more capable of handling complex tasks.

This pattern works well for:

Complex code modifications across multiple files

Research tasks requiring multiple information sources

Customer support scenarios with unpredictable paths

Data analysis requiring multiple processing steps

Resources

Anthropic's Article on building effective agents

问题:LLM 调用链对于复杂任务来说太死板了。它需要预定义步骤和停止点,因此不适合步骤数不可预测的开放式问题。

解决方案:把控制权交给一个自主 Agent,让它根据环境反馈规划、执行和调整。

LLM 调用链使用预定义步骤和停止点,这限制了它处理不可预测任务的能力。智能体循环(agentic loops)则把更多控制权交给 LLM——让它根据任务进度决定何时停止。Agent 通过真实世界反馈学会何时停止。

由此产生的系统更强大,因为它能适应不可预测的路径。它不再遵循预定义步骤,而是在每次交互中学习和调整。这让它很适合解决那些事先不知道答案的复杂问题。

这种自主性是有代价的——每一步决策都会增加延迟。LLM 必须评估当前状态并选择最佳前进路径。这使得智能体循环比 LLM 调用链更慢,但更能胜任复杂任务。

这种模式适合以下场景:

跨多个文件的复杂代码修改

需要多个信息源的研究任务

路径不可预测的客户支持场景

需要多个处理步骤的数据分析

资源

Anthropic 关于构建高效 Agent 的文章

§ 16

Problem: Your LLM-powered system is taking too long because it processes tasks one at a time, creating unnecessary delays.

Solution: Run multiple LLM calls in parallel to handle independent tasks simultaneously, dramatically reducing total processing time.

There are only two ways to make a system faster: do less work, or do more work at the same time. When you need to process multiple tasks independently, running LLM calls in parallel can dramatically improve performance.

You can parallelize when tasks are independent and don't rely on each other's results:

Analyzing multiple documents

Generating different variations of content

Processing multiple user queries simultaneously

You cannot parallelize when tasks must happen in sequence:

When each step depends on the previous one's output

When maintaining strict order is crucial for the final result

The performance benefits are significant. A system processing 10 documents sequentially might take 10 seconds, while parallel processing could complete in just 2-3 seconds. You should always be looking for opportunities to parallelize - even in systems that seem sequential, there might be independent components that can be processed concurrently.

Resources

Anthropic's Article on building effective agents mentions parallelizing LLM calls

OpenAI's docs include a section on parallelizing LLM calls

问题:你的 LLM 应用因为逐个处理任务而耗时过长,造成不必要的延迟。

解决方案:并行运行多个 LLM 调用,同时处理独立任务,大幅缩短总处理时间。

让系统变快只有两种方式:少做工作,或者在同一时间做更多工作。当需要独立处理多个任务时,并行运行 LLM 调用可以显著提升性能。

当任务相互独立、不依赖彼此结果时,你可以并行化:

分析多份文档

生成不同版本的内容

同时处理多个用户查询

当任务必须按顺序执行时,你不能并行化:

每一步依赖前一步的输出时

最终结果要求严格保持顺序时

性能收益非常可观。一个系统顺序处理 10 份文档可能需要 10 秒,而并行处理可能只需 2-3 秒。你应该时刻寻找并行化的机会——即使是看起来像顺序执行的系统,也可能存在可以并发处理的独立组件。

资源

Anthropic 关于构建高效 Agent 的文章提到了并行化 LLM 调用

OpenAI 文档中有关于并行化 LLM 调用的章节

§ 17

Problem: Your LLM's responses aren't meeting the quality standards you need, even after multiple attempts.

Solution: Create an automated loop where one LLM generates responses while another evaluates and provides feedback for improvement.

The evaluator-optimizer workflow creates a self-improving system where two LLMs work together. The first LLM generates responses, while the second evaluates them against specific criteria. This evaluation feeds back into the generation process, creating a continuous improvement loop.

This pattern is particularly effective when you have clear evaluation criteria and when iterative refinement provides measurable value. You'll know it's a good fit when human feedback demonstrably improves LLM responses, and when an LLM can provide similar quality feedback.

The pattern excels in scenarios like literary translation, where an evaluator LLM can catch nuanced meaning that the translator might miss initially. It's also powerful for complex search tasks requiring multiple rounds of searching and analysis, where the evaluator decides if further searches are needed.

Resources

Anthropic's Article on building effective agents mentions the Evaluator-Optimizer pattern

问题:即使尝试多次,你的 LLM 回复仍然达不到所需的质量标准。

解决方案:创建一个自动化循环,让一个 LLM 生成回复,另一个 LLM 评估并提供改进反馈。

评估器-优化器(evaluator-optimizer)工作流创建了一个自我改进的系统,两个 LLM 协同工作。第一个 LLM 生成回复,第二个根据特定标准评估。评估结果反馈到生成过程,形成持续改进的循环。

当你拥有清晰的评估标准,并且迭代改进能带来可衡量的价值时,这种模式尤其有效。当人工反馈确实能改进 LLM 回复,且 LLM 也能提供类似质量的反馈时,就说明它很适合。

这种模式在文学翻译等场景中表现出色,评估 LLM 能捕捉译者最初可能忽略的微妙含义。它也很适合需要多轮搜索和分析的复杂搜索任务,由评估者决定是否还需要进一步搜索。

资源

Anthropic 关于构建高效 Agent 的文章提到了评估器-优化器模式

§ 18

Problem: Different types of queries need different handling strategies.

Solution: Use an LLM to route queries to the most appropriate handler.

LLM routers act as intelligent dispatchers, analyzing each query and sending it to the right specialized handler.

The router first analyzes each query to determine its type and complexity. A customer service system might classify queries into these categories:

Based on this classification, the router connects the query to the appropriate handler with its specific set of instructions and capabilities.

This routing approach delivers several key advantages. It improves accuracy by ensuring each query is handled by the most suitable specialized system. And it allows each specialized LLM to focus on its specific domain, similar to how LLM chaining breaks down complex tasks into specialized steps.

It also solves a fundamental limitation of LLMs - most models can only handle a limited number of tools (often 30 or fewer). By routing queries to specialized handlers, you can create a system that effectively handles an unlimited number of tools, as each handler only needs access to its relevant subset.

However, adding an LLM router introduces an additional sequential step that increases latency, as each query must first be analyzed before being routed to the appropriate handler.

Resources

Anthropic's Article on building effective agents mentions LLM routers

UPDATE: OpenAI has removed their documentation on intent classification

问题:不同类型的查询需要不同的处理策略。

解决方案:用 LLM 把查询路由到最合适的处理器。

LLM 路由器(LLM routers)就像智能调度员,分析每个查询并把它送到正确的专门处理器。

路由器首先分析每个查询,判断其类型和复杂度。客服系统可能会把查询分成以下几类:

基于这个分类,路由器再把查询连接到具有相应指令和能力的处理器。

这种路由方式有几个关键优势。它通过确保每个查询都由最合适的专门系统处理来提高准确性;同时让每个专门 LLM 专注于自己的领域,就像 LLM 链把复杂任务拆成专门步骤一样。

它还解决了 LLM 的一个根本限制——大多数模型只能处理有限数量的工具(通常不超过 30 个)。通过把查询路由到专门处理器,你可以构建一个实际上能处理无限数量工具的系统,因为每个处理器只需要访问自己相关的那部分工具。

不过,增加 LLM 路由器会引入一个额外的顺序步骤,增加延迟,因为每个查询在路由到合适处理器之前都必须先经过分析。

资源

Anthropic 关于构建高效 Agent 的文章提到了 LLM 路由器

更新:OpenAI 已移除关于意图分类的文档

§ 19

Problem: Your LLM's outputs need to match specific quality requirements that simpler techniques can't achieve.

Solution: Fine-tune a base model on your specific data to improve its performance for your use case.

Fine-tuning lets you adapt existing models to your specific needs. You can start with a relatively small dataset of high-quality examples that demonstrate exactly the kind of output you want - whether that's matching your brand voice, handling specialized terminology, or maintaining consistent formatting. A fine-tuned smaller model can often outperform larger, more expensive models on your specific task.

Fine-tuning sits between pre-training and prompt engineering in terms of cost and complexity. While it's an order of magnitude cheaper than training a model from scratch, each fine-tuning run will incur additional costs. There's also a risk of overfitting to specific model versions, which can make it harder to transition to newer, better models in the future.

The best time to consider fine-tuning is when you have a working system that's already using simpler techniques. You've validated your use case, gathered real-world data, and identified specific areas where the model's performance needs improvement. Fine-tuning then becomes an optimization step to push your system's performance even further.

Resources

OpenAI has a section in their docs on fine-tuning.

Anthropic's fine-tuning guide provides detailed requirements and best practices.

问题:你的 LLM 输出需要满足更简单技术无法达到的特定质量要求。

解决方案:在你的特定数据上微调基础模型,针对你的用例提升性能。

微调(fine-tuning)让你把现有模型调整到自己的特定需求。你可以从一小批高质量示例开始,这些示例精确展示你想要的输出——无论是匹配品牌语气、处理专业术语,还是保持一致的格式。在你的特定任务上,一个微调过的小模型往往能胜过更大、更贵的模型。

在成本和复杂度上,微调介于预训练和提示工程之间。虽然比从头训练模型便宜一个数量级,但每次微调运行都会产生额外成本。此外还有对特定模型版本过拟合的风险,这会让未来迁移到更新、更好的模型变得更难。

考虑微调的最佳时机,是你已经有一个用更简单技术构建、正在运行的系统。你已经验证了用例,收集了真实数据,并找到了模型性能需要改进的具体环节。此时微调就成为一个优化步骤,把系统性能再推进一步。

资源

OpenAI 的文档中有微调相关章节。

Anthropic 的微调指南提供了详细的要求和最佳实践。

§ 20

The field of AI engineering moves at an astonishing pace. Every week brings new models, techniques, and tools promising to revolutionize how we build AI systems. It's impossible to keep up with everything, but you don't need to.

Each new AI development needs to earn its place in your system. Ask yourself: "Does this make things simpler or more complex? Is it solving a real problem?" The most valuable developments reduce costs, improve performance, or make your system more maintainable.

The next big thing in AI will come and go, but simplicity remains a reliable guide. Experiment with new techniques using your own evals - test them against your specific use case and success criteria. Focus on developments that help you build more effective systems with less complexity.

AI 工程领域的发展速度快得惊人。每周都有新的模型、技术和工具,号称要彻底改变我们构建 AI 系统的方式。你不可能全部跟上,但也不需要。

每一项新的 AI 进展,都要在系统里挣得自己的位置。问问自己:“这让事情变得更简单还是更复杂?它真的在解决一个真实问题吗?”最有价值的进展会降低成本、提升性能,或让系统更易维护。

AI 界的“下一件大事”来了又走,但简洁始终是可靠的指南。用你自己的评估去实验新技术——对照你的具体用例和成功标准去测试。把注意力放在那些能帮你用更少复杂度构建更高效系统的进展上。

Open source ↗