这是用户在 2025-8-7 20:32 为 https://blog.langchain.com/context-engineering-for-agents/ 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Context Engineering

Context Engineering  上下文工程

11 min read

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!
代理需要上下文才能执行任务。上下文工程是关于在代理轨迹的每一步恰到好处地填充上下文窗口的艺术和科学。在这篇文章中,我们通过回顾各种流行的代理和论文,分解了一些常见的上下文工程策略——写入、选择、压缩和隔离。然后,我们解释了 LangGraph 是如何设计来支持它们的!

Also, see our video on context engineering here.
此外,请在此处查看我们的上下文工程视频。

General categories of context engineering
上下文工程的通用类别

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:
正如安德烈·卡帕西所说,LLMs 就像一种新的操作系统。LLM 就像 CPU,而它的上下文窗口就像 RAM,作为模型的内存。就像 RAM 一样,LLM 上下文窗口有有限的容量来处理各种上下文来源。正如操作系统筛选适合放入 CPU RAM 的内容一样,我们可以将“上下文工程”视为扮演类似的角色。卡帕西很好地总结了这一点:

[Context engineering is the] ”…delicate art and science of filling the context window with just the right information for the next step.”
[上下文工程是] “……一种精妙的艺术和科学,为下一步在上下文窗口中填入恰到好处的信息。”
Context types commonly used in LLM applications
LLM 应用中常用的上下文类型

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.
今年,随着 LLMs 在推理和工具调用方面的能力不断提升,人们对代理的兴趣与日俱增。代理会交替调用 LLMs 和工具,通常用于处理长时间运行的任务。代理交替调用 LLMs 和工具,并使用工具的反馈来决定下一步操作。

Agents interleave LLM calls and tool calls, using tool feedback to decide the next step
代理交替调用 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 from tool calls accumulates over multiple agent turns
来自工具调用的上下文会在多个代理回合中累积

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 是如何设计来支持它们的!

General categories of context engineering
上下文工程的通用类别

Write Context  写入上下文

Writing context means saving it outside the context window to help an agent perform a task.
写入上下文意味着将其保存到上下文窗口之外,以帮助智能体执行任务。

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.
首席研究员首先构思方法,并将计划保存到内存中以持久化上下文,因为如果上下文窗口超过 20 万个 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

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.
草稿板帮助智能体在给定会话(或线程)内解决任务,但有时智能体需要跨多个会话记住事情!反射引入了在每个智能体回合后进行反思并重用这些自我生成的记忆的概念。生成式智能体则定期从过去的智能体反馈集合中合成记忆。

An LLM can be used to update or create memories
一个 LLM 可以用来更新或创建记忆

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”!
用于记忆索引的嵌入和/或知识图谱通常用于协助选择。然而,记忆选择仍然具有挑战性。在 AIEngineer 世界博览会,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(检索增强生成)到工具描述中,以便只为任务获取最相关的工具。一些最近的论文表明,这种方法可以将工具选择准确率提高三倍。

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.
压缩上下文涉及仅保留执行任务所需的标记。

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%的上下文窗口后会运行“自动压缩”,并会总结用户-智能体交互的完整轨迹。这种跨智能体轨迹的压缩可以使用多种策略,如递归或分层摘要。

A few places where summarization can be applied
摘要可以应用的几个地方

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 库的动机是关注分离,一个智能体团队可以处理特定的子任务。每个智能体有一套特定的工具、指令和自己的上下文窗口。

Split context across multiple agents
将上下文分散到多个智能体

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.
当然,多代理的挑战包括令牌使用(例如,Anthropic 报告高达 15 倍的令牌量比聊天多)、需要仔细的提示工程来规划子代理工作,以及子代理的协调。

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 返回 JSON 对象(工具参数),可以传递给工具(例如,搜索 API)以获取工具反馈(例如,搜索结果)。HuggingFace 使用 CodeAgent,该代理输出包含所需工具调用的内容。代码然后在沙盒中运行。从工具调用中选择的部分上下文(例如,返回值)随后被传递回 LLM。

Sandboxes can isolate context from the LLM.
沙盒可以将上下文与 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 指出,这是一种特别好的方法来隔离重量级的对象:

[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.
值得指出的是,代理的运行时状态对象也可以是隔离上下文的好方法。这可以达到与沙盒相同的目的。状态对象可以设计一个具有可写入上下文的字段的模式。模式的一个字段(例如, messages )可以在代理的每次交互中暴露给 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 被设计为同时具有线程范围(短期)和长期记忆。短期记忆使用检查点来持久化代理状态,跨越代理的所有步骤。这非常实用,作为一个“草稿板”,允许你将信息写入状态,并在代理轨迹的任何步骤中获取它。

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 记忆。

Email agent with user feedback and long-term memory
带用户反馈和长期记忆的邮件代理

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 库是应用语义搜索到工具描述的一种绝佳方式。这有助于在处理大量工具时,为任务选择最相关的工具。最后,我们提供了几个教程和视频,展示如何使用 LangGraph 中的各种类型 RAG。

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.
LangGraph 是围绕状态对象设计的,允许你指定状态模式并在每个代理步骤中访问状态。例如,你可以将工具调用的上下文存储在状态中的某些字段里,直到需要这些上下文时才将其提供给 LLM。

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 还支持使用沙盒进行上下文隔离。查看这个仓库,了解一个使用 E2B 沙盒进行工具调用的 LangGraph 代理示例。查看这个视频,了解使用 Pyodide 进行沙盒化的示例,其中状态可以被持久化。LangGraph 还为构建多代理架构提供了大量支持,例如监督器和群集库。你可以查看这些视频,了解更多关于使用 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.
    压缩上下文 - 仅保留执行任务所需的标记。
  • 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.
LangGraph 使实现它们变得容易,而 LangSmith 提供了一种简单的方法来测试您的代理并跟踪上下文使用情况。

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 共同实现了一个良性的反馈循环,用于识别应用上下文工程的最佳机会,实施它,测试它,并重复进行。