LangChain探讨智能体检索的上下文工程
AI 总结
LangChain 博客分析智能体在有限上下文窗口中进行检索时的三类问题:搜索效率低、一次返回过多上下文,以及引入无关或过时信息。文章以 Deep Agents 为例,介绍先搜索后读取、分页读取文件、将超大结果转存到文件、委派子智能体阅读,以及根据检索来源核验依据等方法。
深度见解
这些方法为控制智能体上下文提供了具体实践,包括先搜索后读取、以路径代替完整内容、让子智能体处理噪声较大的检索工作,以及对照预期来源验证答案。
Key Takeaways
- Agents work with a limited context window, and information retrieval breaks in three ways: inefficient searching, too much context at once, and irrelevant or stale context.
- The Deep Agents harness keeps searches small out of the box. The built-in filesystem tools search before they read: glob matches file names, grep finds matching lines, and read_file reads a page at a time. Oversized tool results are offloaded: the full result is saved to files, but the agent gets just the path and a preview.
- For custom search tools (like RAG), use "retrieve, offload, delegate": save results to files, return the paths, and let subagents read them. The main agent only sees what's relevant.
Imagine you’re taking an open book exam: you technically have all the answers, but somehow that makes it even harder to find the right one.
- Where do you even start searching?
- When do you know that your sources are correct?
- How do you optimize your time so that you don’t blow all your energy on redundant searches?