
TL;DR摘要
Agents need context to perform tasks. Context engineering is the art and science of filling the context window with just the right information at each step of an agent’s trajectory. In this post, we break down some common strategies — write, select, compress, and isolate — for context engineering by reviewing various popular agents and papers. We then explain how LangGraph is designed to support them! 智能体(Agents)需要上下文来执行任务。上下文工程是一门艺术与科学,旨在智能体轨迹的每一步中,将恰到好处的信息填充到上下文窗口中。在这篇文章中,我们将通过回顾各种流行的智能体和论文,剖析上下文工程的一些常见策略——写入、选择、压缩和隔离。随后,我们将解释 LangGraph 是如何设计来支持这些策略的!
Also, see our video on context engineering here.此外,请点击此处观看我们关于上下文工程的视频。

Context Engineering
As Andrej Karpathy puts it, LLMs are like a new kind of operating system. The LLM is like the CPU and its context window is like the RAM, serving as the model’s working memory. Just like RAM, the LLM context window has limited capacity to handle various sources of context. And just as an operating system curates what fits into a CPU’s RAM, we can think about “context engineering” playing a similar role. Karpathy summarizes this well:正如 Andrej Karpathy 所言,大语言模型(LLM)就像一种新型操作系统。LLM 类似于 CPU,而其上下文窗口则类似于 RAM,充当模型的工作内存。就像 RAM 一样,LLM 的上下文窗口处理各种上下文来源的能力是有限的。正如操作系统会管理哪些内容适合放入 CPU 的 RAM 中一样,我们可以认为“上下文工程”也扮演着类似的角色。Karpathy 对此总结得很好:
[Context engineering is the] ”…delicate art and science of filling the context window with just the right information for the next step.”[上下文工程是] “……在每一步中,将恰到好处的信息填充到上下文窗口中的精妙艺术与科学。”

What are the types of context that we need to manage when building LLM applications? Context engineering as an umbrella that applies across a few different context types:在构建 LLM 应用时,我们需要管理哪些类型的上下文?上下文工程是一个涵盖多种不同上下文类型的总称:
- Instructions – prompts, memories, few‑shot examples, tool descriptions, etc指令 —— 提示词、记忆、少样本示例、工具描述等
- Knowledge – facts, memories, etc知识 —— 事实、记忆等
- Tools – feedback from tool calls工具 —— 工具调用的反馈
Context Engineering for Agents面向智能体的上下文工程
This year, interest in agents has grown tremendously as LLMs get better at reasoning and tool calling. Agents interleave LLM invocations and tool calls, often for long-running tasks. Agents interleave LLM calls and tool calls, using tool feedback to decide the next step.今年,随着 LLM 在推理和工具调用能力上的提升,人们对智能体的兴趣激增。智能体通常在长时间运行的任务中交替进行 LLM 调用和工具调用。智能体通过交替使用 LLM 调用和工具调用,并利用工具反馈来决定下一步行动。

However, long-running tasks and accumulating feedback from tool calls mean that agents often utilize a large number of tokens. This can cause numerous problems: it can exceed the size of the context window, balloon cost / latency, or degrade agent performance. Drew Breunig nicely outlined a number of specific ways that longer context can cause perform problems, including:然而,长时间运行的任务和不断累积的工具调用反馈意味着智能体往往会消耗大量的 Token。这可能导致诸多问题:超出上下文窗口大小、推高成本/延迟,或降低智能体性能。Drew Breunig 很好地概述了较长上下文导致性能问题的几种具体方式,包括:
- Context Poisoning: When a hallucination makes it into the context上下文中毒(Context Poisoning):当幻觉进入上下文时
- Context Distraction: When the context overwhelms the training上下文干扰(Context Distraction):当上下文淹没了训练内容时
- Context Confusion: When superfluous context influences the response上下文混淆(Context Confusion):当多余的上下文影响了响应时
- Context Clash: When parts of the context disagree上下文冲突(Context Clash):当上下文的各部分内容不一致时

With this in mind, Cognition called out the importance of context engineering:考虑到这一点,Cognition 指出了上下文工程的重要性:
“Context engineering” … is effectively the #1 job of engineers building AI agents.“上下文工程”……实际上是构建 AI 智能体的工程师的首要工作。
Anthropic also laid it out clearly:Anthropic 也明确阐述了这一点:
Agents often engage in conversations spanning hundreds of turns, requiring careful context management strategies.智能体经常进行跨越数百轮的对话,这需要精细的上下文管理策略。
So, how are people tackling this challenge today? We group common strategies for agent context engineering into four buckets — write, select, compress, and isolate — and give examples of each from review of some popular agent products and papers. We then explain how LangGraph is designed to support them!那么,人们今天是如何应对这一挑战的呢?我们将智能体上下文工程的常见策略归纳为四个类别——写入、选择、压缩和隔离——并从对一些流行智能体产品和论文的回顾中给出每个类别的示例。随后,我们将解释 LangGraph 是如何设计来支持这些策略的!

Write Context写入上下文
Writing context means saving it outside the context window to help an agent perform a task.写入上下文意味着将其保存在上下文窗口之外,以帮助智能体执行任务。
Scratchpads草稿板(Scratchpads)
When humans solve tasks, we take notes and remember things for future, related tasks. Agents are also gaining these capabilities! Note-taking via a “scratchpad” is one approach to persist information while an agent is performing a task. The idea is to save information outside of the context window so that it’s available to the agent. Anthropic’s multi-agent researcher illustrates a clear example of this:当人类执行任务时,我们会做笔记并记住一些事情以备未来相关的任务使用。智能体也正在获得这些能力!通过“草稿板”进行笔记记录是一种在智能体执行任务时持久化信息的方法。其核心思想是将信息保存在上下文窗口之外,以便智能体在需要时可以获取。Anthropic 的多智能体研究员展示了一个清晰的例子:
The LeadResearcher begins by thinking through the approach and saving its plan to Memory to persist the context, since if the context window exceeds 200,000 tokens it will be truncated and it is important to retain the plan.首席研究员(LeadResearcher)首先思考方法并将计划保存到内存(Memory)中以持久化上下文,因为如果上下文窗口超过 200,000 个 Token,它将被截断,而保留计划至关重要。
Scratchpads can be implemented in a few different ways. They can be a tool call that simply writes to a file. They can also be a field in a runtime state object that persists during the session. In either case, scratchpads let agents save useful information to help them accomplish a task.草稿板可以通过几种不同的方式实现。它们可以是一个简单的写入文件的工具调用。它们也可以是运行时状态对象中的一个字段,在会话期间保持持久化。无论哪种方式,草稿板都能让智能体保存有用的信息,以帮助它们完成任务。
Memories记忆(Memories)
Scratchpads help agents solve a task within a given session (or thread), but sometimes agents benefit from remembering things across many sessions! Reflexion introduced the idea of reflection following each agent turn and re-using these self-generated memories. Generative Agents created memories synthesized periodically from collections of past agent feedback.草稿板帮助智能体在给定的会话(或线程)内解决任务,但有时智能体从跨多个会话的记忆中获益!Reflexion 引入了在每个智能体轮次后进行反思并重用这些自生成记忆的概念。生成式智能体(Generative Agents)则创建了定期从过去智能体反馈集合中合成的记忆。

These concepts made their way into popular products like ChatGPT, Cursor, and Windsurf, which all have mechanisms to auto-generate long-term memories that can persist across sessions based on user-agent interactions.这些概念已进入 ChatGPT、Cursor 和 Windsurf 等流行产品中,它们都具备基于用户与智能体的交互,自动生成可跨会话持久化的长期记忆的机制。
Select Context选择上下文
Selecting context means pulling it into the context window to help an agent perform a task.选择上下文意味着将其提取到上下文窗口中,以帮助智能体执行任务。
Scratchpad草稿板
The mechanism for selecting context from a scratchpad depends upon how the scratchpad is implemented. If it’s a tool, then an agent can simply read it by making a tool call. If it’s part of the agent’s runtime state, then the developer can choose what parts of state to expose to an agent each step. This provides a fine-grained level of control for exposing scratchpad context to the LLM at later turns.从草稿板中选择上下文的机制取决于草稿板的实现方式。如果它是一个工具,那么智能体只需通过调用该工具即可读取。如果它是智能体运行时状态的一部分,那么开发者可以选择在每一步向智能体公开状态的哪些部分。这为在后续轮次中向 LLM 公开草稿板上下文提供了细粒度的控制。
Memories
If agents have the ability to save memories, they also need the ability to select memories relevant to the task they are performing. This can be useful for a few reasons. Agents might select few-shot examples (episodic memories) for examples of desired behavior, instructions (procedural memories) to steer behavior, or facts (semantic memories) for task-relevant context.如果智能体有能力保存记忆,它们也需要有能力选择与当前执行任务相关的记忆。这在几个方面很有用。智能体可能会选择少样本示例(情景记忆)作为期望行为的范例,选择指令(程序记忆)来引导行为,或选择事实(语义记忆)作为任务相关的上下文。

One challenge is ensuring that relevant memories are selected. Some popular agents simply use a narrow set of files that are always pulled into context. For example, many code agent use specific files to save instructions (”procedural” memories) or, in some cases, examples (”episodic” memories). Claude Code uses CLAUDE.md. Cursor and Windsurf use rules files. 一个挑战是确保选出相关的记忆。一些流行的智能体只是使用一组始终被拉入上下文的固定文件。例如,许多代码智能体使用特定文件来保存指令(“程序”记忆),或者在某些情况下,使用示例(“情景”记忆)。Claude Code 使用 CLAUDE.md。Cursor 和 Windsurf 使用规则文件。
But, if an agent is storing a larger collection of facts and / or relationships (e.g., semantic memories), selection is harder. ChatGPT is a good example of a popular product that stores and selects from a large collection of user-specific memories.但是,如果智能体存储了大量的事实和/或关系(例如语义记忆),选择就会变得更加困难。ChatGPT 是一个很好的例子,它存储并从大量用户特定的记忆中进行选择。
Embeddings and / or knowledge graphs for memory indexing are commonly used to assist with selection. Still, memory selection is challenging. At the AIEngineer World’s Fair, Simon Willison shared an example of selection gone wrong: ChatGPT fetched his location from memories and unexpectedly injected it into a requested image. This type of unexpected or undesired memory retrieval can make some users feel like the context window “no longer belongs to them”! 嵌入(Embeddings)和/或用于记忆索引的知识图谱通常被用来辅助选择。尽管如此,记忆选择仍然具有挑战性。在 AIEngineer World’s Fair 上,Simon Willison 分享了一个选择错误的例子:ChatGPT 从记忆中获取了他的位置,并意外地将其注入到请求生成的图像中。这种意外或不想要的记忆检索会让一些用户觉得上下文窗口“不再属于他们”了!
Tools工具
Agents use tools, but can become overloaded if they are provided with too many. This is often because the tool descriptions overlap, causing model confusion about which tool to use. One approach is to apply RAG (retrieval augmented generation) to tool descriptions in order to fetch only the most relevant tools for a task. Some recent papers have shown that this improve tool selection accuracy by 3-fold.智能体使用工具,但如果提供的工具过多,它们可能会不堪重负。这通常是因为工具描述重叠,导致模型对使用哪个工具产生混淆。一种方法是对工具描述应用 RAG(检索增强生成),以便仅为任务获取最相关的工具。一些最近的论文表明,这可以将工具选择的准确性提高 3 倍。
Knowledge知识
RAG is a rich topic and it can be a central context engineering challenge. Code agents are some of the best examples of RAG in large-scale production. Varun from Windsurf captures some of these challenges well:RAG 是一个丰富的话题,它可以成为上下文工程的核心挑战。代码智能体是大规模生产中 RAG 的最佳示例之一。来自 Windsurf 的 Varun 很好地捕捉到了其中的一些挑战:
Indexing code ≠ context retrieval … [We are doing indexing & embedding search … [with] AST parsing code and chunking along semantically meaningful boundaries … embedding search becomes unreliable as a retrieval heuristic as the size of the codebase grows … we must rely on a combination of techniques like grep/file search, knowledge graph based retrieval, and … a re-ranking step where [context] is ranked in order of relevance.索引代码 ≠ 上下文检索……[我们正在进行索引和嵌入搜索……[使用] AST 解析代码并沿语义上有意义的边界进行分块……随着代码库规模的增长,嵌入搜索作为检索启发式方法变得不可靠……我们必须依赖多种技术的组合,如 grep/文件搜索、基于知识图谱的检索,以及……一个重排序步骤,其中 [上下文] 按相关性进行排序。
Compressing Context压缩上下文
Compressing context involves retaining only the tokens required to perform a task.压缩上下文涉及仅保留执行任务所需的 Token。
Context Summarization上下文摘要
Agent interactions can span hundreds of turns and use token-heavy tool calls. Summarization is one common way to manage these challenges. If you’ve used Claude Code, you’ve seen this in action. Claude Code runs “auto-compact” after you exceed 95% of the context window and it will summarize the full trajectory of user-agent interactions. This type of compression across an agent trajectory can use various strategies such as recursive or hierarchical summarization.智能体交互可以跨越数百轮,并使用消耗大量 Token 的工具调用。摘要是应对这些挑战的一种常见方式。如果你使用过 Claude Code,你就会看到它的实际应用。Claude Code 在你超过上下文窗口 95% 后会运行“自动压缩”,它将总结用户与智能体交互的完整轨迹。这种跨智能体轨迹的压缩可以使用各种策略,例如递归或分层摘要。

It can also be useful to add summarization at specific points in an agent’s design. For example, it can be used to post-process certain tool calls (e.g., token-heavy search tools). As a second example, Cognition mentioned summarization at agent-agent boundaries to reduce tokens during knowledge hand-off. Summarization can be a challenge if specific events or decisions need to be captured. Cognition uses a fine-tuned model for this, which underscores how much work can go into this step.在智能体设计的特定点添加摘要也很有用。例如,它可以用于后处理某些工具调用(例如,消耗大量 Token 的搜索工具)。第二个例子是,Cognition 提到了在智能体与智能体边界处进行摘要,以减少知识移交过程中的 Token 消耗。如果需要捕获特定的事件或决策,摘要可能会是一个挑战。Cognition 为此使用了一个微调模型,这强调了这一步骤需要投入多少工作。
Context Trimming上下文修剪
Whereas summarization typically uses an LLM to distill the most relevant pieces of context, trimming can often filter or, as Drew Breunig points out, “prune” context. This can use hard-coded heuristics like removing older messages from a list. Drew also mentions Provence, a trained context pruner for Question-Answering.虽然摘要通常使用 LLM 来提炼最相关的上下文片段,但修剪通常可以过滤,或者正如 Drew Breunig 指出的那样,“修剪”上下文。这可以使用硬编码的启发式方法,例如从列表中删除较旧的消息。Drew 还提到了 Provence,这是一种用于问答的训练有素的上下文修剪器。
Isolating Context隔离上下文
Isolating context involves splitting it up to help an agent perform a task.隔离上下文涉及将其拆分,以帮助智能体执行任务。
Multi-agent多智能体
One of the most popular ways to isolate context is to split it across sub-agents. A motivation for the OpenAI Swarm library was separation of concerns, where a team of agents can handle specific sub-tasks. Each agent has a specific set of tools, instructions, and its own context window.隔离上下文最流行的方法之一是将其拆分到子智能体中。OpenAI Swarm 库的动机之一是关注点分离,即一个智能体团队可以处理特定的子任务。每个智能体都有一组特定的工具、指令和自己的上下文窗口。

Anthropic’s multi-agent researcher makes a case for this: many agents with isolated contexts outperformed single-agent, largely because each subagent context window can be allocated to a more narrow sub-task. As the blog said:Anthropic 的多智能体研究员为此提供了一个理由:许多具有隔离上下文的智能体表现优于单一智能体,主要是因为每个子智能体的上下文窗口都可以分配给更狭窄的子任务。正如博客所说:
[Subagents operate] in parallel with their own context windows, exploring different aspects of the question simultaneously.[子智能体] 并行运行,拥有各自的上下文窗口,同时探索问题的不同方面。
Of course, the challenges with multi-agent include token use (e.g., up to 15× more tokens than chat as reported by Anthropic), the need for careful prompt engineering to plan sub-agent work, and coordination of sub-agents.当然,多智能体的挑战包括 Token 使用(例如,据 Anthropic 报道,比聊天多出 15 倍的 Token)、需要仔细的提示工程来规划子智能体的工作,以及子智能体的协调。
Context Isolation with Environments通过环境进行上下文隔离
HuggingFace’s deep researcher shows another interesting example of context isolation. Most agents use tool calling APIs, which return JSON objects (tool arguments) that can be passed to tools (e.g., a search API) to get tool feedback (e.g., search results). HuggingFace uses a CodeAgent, which outputs that contains the desired tool calls. The code then runs in a sandbox. Selected context (e.g., return values) from the tool calls is then passed back to the LLM.HuggingFace 的深度研究员展示了上下文隔离的另一个有趣例子。大多数智能体使用工具调用 API,这些 API 返回可传递给工具(例如搜索 API)以获取工具反馈(例如搜索结果)的 JSON 对象(工具参数)。HuggingFace 使用了一个 CodeAgent,它输出包含所需工具调用的代码。然后代码在沙箱中运行。来自工具调用的选定上下文(例如返回值)随后被传回给 LLM。

This allows context to be isolated from the LLM in the environment. Hugging Face noted that this is a great way to isolate token-heavy objects in particular:这允许上下文在环境中与 LLM 隔离。Hugging Face 指出,这是处理消耗大量 Token 的对象的一种绝佳方式:
[Code Agents allow for] a better handling of state … Need to store this image / audio / other for later use? No problem, just assign it as a variable in your state and you [use it later].[代码智能体允许] 更好地处理状态……需要存储此图像/音频/其他内容以供以后使用?没问题,只需将其分配为状态中的变量,你就可以 [稍后使用它]。
State状态
It’s worth calling out that an agent’s runtime state object can also be a great way to isolate context. This can serve the same purpose as sandboxing. A state object can be designed with a schema that has fields that context can be written to. One field of the schema (e.g., messages) can be exposed to the LLM at each turn of the agent, but the schema can isolate information in other fields for more selective use.值得一提的是,智能体的运行时状态对象也可以是隔离上下文的好方法。这可以起到与沙箱相同的作用。状态对象可以设计为具有特定模式,其中包含可以写入上下文的字段。模式的一个字段(例如消息)可以在智能体的每一轮中向 LLM 公开,但模式可以将信息隔离在其他字段中,以便进行更具选择性的使用。
Context Engineering with LangSmith / LangGraph使用 LangSmith / LangGraph 进行上下文工程
So, how can you apply these ideas? Before you start, there are two foundational pieces that are helpful. First, ensure that you have a way to look at your data and track token-usage across your agent. This helps inform where best to apply effort context engineering. LangSmith is well-suited for agent tracing / observability, and offers a great way to do this. Second, be sure you have a simple way to test whether context engineering hurts or improve agent performance. LangSmith enables agent evaluation to test the impact of any context engineering effort.那么,你该如何应用这些想法呢?在开始之前,有两个基础部分很有帮助。首先,确保你有一种方法来查看数据并跟踪智能体的 Token 使用情况。这有助于确定在何处最好地投入上下文工程。LangSmith 非常适合智能体追踪/可观测性,并提供了实现这一点的绝佳方式。其次,确保你有一种简单的方法来测试上下文工程是损害还是改善了智能体性能。LangSmith 支持智能体评估,以测试任何上下文工程工作的影响。
Write context写入上下文
LangGraph was designed with both thread-scoped (short-term) and long-term memory. Short-term memory uses checkpointing to persist agent state across all steps of an agent. This is extremely useful as a “scratchpad”, allowing you to write information to state and fetch it at any step in your agent trajectory.LangGraph 的设计同时考虑了线程范围(短期)和长期记忆。短期记忆使用检查点(checkpointing)在智能体的所有步骤中持久化智能体状态。这作为“草稿板”非常有用,允许你将信息写入状态并在智能体轨迹的任何步骤中获取它。
LangGraph’s long-term memory lets you to persist context across many sessions with your agent. It is flexible, allowing you to save small sets of files (e.g., a user profile or rules) or larger collections of memories. In addition, LangMem provides a broad set of useful abstractions to aid with LangGraph memory management.LangGraph 的长期记忆允许你跨多个会话持久化上下文。它非常灵活,允许你保存小规模的文件集(例如用户配置文件或规则)或更大规模的记忆集合。此外,LangMem 提供了一套广泛的有用抽象,以辅助 LangGraph 记忆管理。
Select context选择上下文
Within each node (step) of a LangGraph agent, you can fetch state. This give you fine-grained control over what context you present to the LLM at each agent step. 在 LangGraph 智能体的每个节点(步骤)内,你可以获取状态。这使你能够对在每个智能体步骤中向 LLM 展示的上下文进行细粒度控制。
In addition, LangGraph’s long-term memory is accessible within each node and supports various types of retrieval (e.g., fetching files as well as embedding-based retrieval on a memory collection). For an overview of long-term memory, see our Deeplearning.ai course. And for an entry point to memory applied to a specific agent, see our Ambient Agents course. This shows how to use LangGraph memory in a long-running agent that can manage your email and learn from your feedback.此外,LangGraph 的长期记忆在每个节点内都是可访问的,并支持各种类型的检索(例如,获取文件以及对记忆集合进行基于嵌入的检索)。有关长期记忆的概述,请参阅我们的 Deeplearning.ai 课程。对于应用于特定智能体的记忆入口点,请参阅我们的 Ambient Agents 课程。这展示了如何在可以管理你的电子邮件并从你的反馈中学习的长时间运行的智能体中使用 LangGraph 记忆。

For tool selection, the LangGraph Bigtool library is a great way to apply semantic search over tool descriptions. This helps select the most relevant tools for a task when working with a large collection of tools. Finally, we have several tutorials and videos that show how to use various types of RAG with LangGraph.对于工具选择,LangGraph Bigtool 库是在工具描述上应用语义搜索的绝佳方式。这有助于在处理大量工具集合时为任务选择最相关的工具。最后,我们有几个教程和视频,展示了如何将各种类型的 RAG 与 LangGraph 一起使用。
Compressing context压缩上下文
Because LangGraph is a low-level orchestration framework, you lay out your agent as a set of nodes, define the logic within each one, and define an state object that is passed between them. This control offers several ways to compress context.由于 LangGraph 是一个低级编排框架,你可以将智能体布局为一组节点,定义每个节点内的逻辑,并定义在它们之间传递的状态对象。这种控制提供了几种压缩上下文的方法。
One common approach is to use a message list as your agent state and summarize or trim it periodically using a few built-in utilities. However, you can also add logic to post-process tool calls or work phases of your agent in a few different ways. You can add summarization nodes at specific points or also add summarization logic to your tool calling node in order to compress the output of specific tool calls.一种常见的方法是使用消息列表作为智能体状态,并使用一些内置工具定期对其进行总结或修剪。但是,你也可以通过几种不同的方式添加逻辑来后处理工具调用或智能体的工作阶段。你可以在特定点添加摘要节点,或者在工具调用节点中添加摘要逻辑,以压缩特定工具调用的输出。
Isolating context隔离上下文
LangGraph is designed around a state object, allowing you to specify a state schema and access state at each agent step. For example, you can store context from tool calls in certain fields in state, isolating them from the LLM until that context is required. In addition to state, LangGraph supports use of sandboxes for context isolation. See this repo for an example LangGraph agent that uses an E2B sandbox for tool calls. See this video for an example of sandboxing using Pyodide where state can be persisted. LangGraph also has a lot of support for building multi-agent architecture, such as the supervisor and swarm libraries. You can see these videos for more detail on using multi-agent with LangGraph.LangGraph 是围绕状态对象设计的,允许你指定状态模式并在每个智能体步骤访问状态。例如,你可以将来自工具调用的上下文存储在状态的特定字段中,将其与 LLM 隔离,直到需要该上下文为止。除了状态之外,LangGraph 还支持使用沙箱进行上下文隔离。请参阅此仓库以获取使用 E2B 沙箱进行工具调用的 LangGraph 智能体示例。请参阅此视频以获取使用 Pyodide 进行沙箱处理的示例,其中状态可以持久化。LangGraph 还对构建多智能体架构提供了大量支持,例如 supervisor 和 swarm 库。你可以查看这些视频以了解有关在 LangGraph 中使用多智能体的更多详细信息。
Conclusion结论
Context engineering is becoming a craft that agents builders should aim to master. Here, we covered a few common patterns seen across many popular agents today:上下文工程正成为智能体构建者应该努力掌握的一门手艺。在这里,我们涵盖了当今许多流行智能体中常见的几种模式:
- Writing context - saving it outside the context window to help an agent perform a task.写入上下文 - 将其保存在上下文窗口之外,以帮助智能体执行任务。
- Selecting context - pulling it into the context window to help an agent perform a task.选择上下文 - 将其拉入上下文窗口,以帮助智能体执行任务。
- Compressing context - retaining only the tokens required to perform a task.压缩上下文 - 仅保留执行任务所需的 Token。
- Isolating context - splitting it up to help an agent perform a task.隔离上下文 - 将其拆分,以帮助智能体执行任务。
LangGraph makes it easy to implement each of them and LangSmith provides an easy way to test your agent and track context usage. Together, LangGraph and LangGraph enable a virtuous feedback loop for identifying the best opportunity to apply context engineering, implementing it, testing it, and repeating.LangGraph 使实现这些策略变得容易,而 LangSmith 提供了一种测试智能体和跟踪上下文使用情况的简便方法。LangGraph 和 LangSmith 共同实现了一个良性反馈循环,用于识别应用上下文工程的最佳机会、实施它、测试它并不断重复。
.png)
.png)





