From 2115cffc945ae9c3f89b5fc523401907fc07ca97 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Mon, 28 Jul 2025 15:17:05 -0400 Subject: [PATCH 1/6] notes on context --- docs/docs/agents/context.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/docs/agents/context.md b/docs/docs/agents/context.md index a84c28a4e..b246b6dce 100644 --- a/docs/docs/agents/context.md +++ b/docs/docs/agents/context.md @@ -8,7 +8,7 @@ Context includes *any* data outside the message list that can shape behavior. Th - Internal state updated during a multi-step reasoning process. - Persistent memory or facts from previous interactions. -LangGraph provides **three** primary ways to supply context: +LangGraph provides **three** primary ways to manage context: | Type | Description | Mutable? | Lifetime | |------------------------------------------------------------------------------|-----------------------------------------------|----------|-------------------------| @@ -20,12 +20,26 @@ LangGraph provides **three** primary ways to supply context: !!! note "`config['configurable']` -> `runtime.context`" - In LangGraph < v1.0, static runtime context was passed via the `config['configurable']` key, paired with a `config_schema` argument + In LangGraph < v0.6, static runtime context was passed via the `config['configurable']` key, paired with a `config_schema` argument to `StateGraph` or `Pregel`. This is now deprecated and will be removed in v2.0. - As of LangGraph v1.0, the Runtime object is recommended to access static context and runtime-specific information like the store and stream writer. + As of LangGraph v0.6, the `Runtime` object is recommended to access static context and runtime-specific information like the store and stream writer. -Runtime context is for immutable data like user metadata or API keys. Use this when you have values that don't change mid-run. +!!! warning "Context is an overloaded term" + + In the world of LLMs, "context" is quite the overloaded term. + + There are two main types of context that you will encounter: + + 1. Local context: data and dependencies your code needs to run. This might be helpful for tools, node invocations, + conditional branching, etc. + 2. LLM context: often talked about regarding the "context window" of an LLM. This is the data the LLM sees when generating a response. + The field of "context engineering" refers to the practice of optimizing the content of the context window to improve the LLM's performance. + + The context discussed in this section is the local context. As a developer, you might use the local context to eventually optimize + the LLM context (ex: use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories). + +Runtime context is for immutable data like user metadata, tools, db connections, etc. Use this when you have values that don't change mid-run. Specify static context via the `context` argument to `invoke` / `stream`, which is reserved for this purpose: From 624247a51f07b596e7a085caf449f6718c9b9c8e Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Mon, 28 Jul 2025 15:31:36 -0400 Subject: [PATCH 2/6] Update docs/docs/agents/context.md Co-authored-by: Eugene Yurtsev --- docs/docs/agents/context.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/agents/context.md b/docs/docs/agents/context.md index b246b6dce..c571fffda 100644 --- a/docs/docs/agents/context.md +++ b/docs/docs/agents/context.md @@ -37,7 +37,7 @@ LangGraph provides **three** primary ways to manage context: The field of "context engineering" refers to the practice of optimizing the content of the context window to improve the LLM's performance. The context discussed in this section is the local context. As a developer, you might use the local context to eventually optimize - the LLM context (ex: use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories). + the LLM context. For example, use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories. Runtime context is for immutable data like user metadata, tools, db connections, etc. Use this when you have values that don't change mid-run. From 1923ff8d852db8fe7c561f86944b715905a987c2 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Mon, 28 Jul 2025 16:15:14 -0400 Subject: [PATCH 3/6] first pass --- docs/docs/agents/context.md | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/docs/docs/agents/context.md b/docs/docs/agents/context.md index b246b6dce..94bb27616 100644 --- a/docs/docs/agents/context.md +++ b/docs/docs/agents/context.md @@ -18,29 +18,20 @@ LangGraph provides **three** primary ways to manage context: ### Runtime Context -!!! note "`config['configurable']` -> `runtime.context`" - - In LangGraph < v0.6, static runtime context was passed via the `config['configurable']` key, paired with a `config_schema` argument - to `StateGraph` or `Pregel`. This is now deprecated and will be removed in v2.0. - - As of LangGraph v0.6, the `Runtime` object is recommended to access static context and runtime-specific information like the store and stream writer. - -!!! warning "Context is an overloaded term" - - In the world of LLMs, "context" is quite the overloaded term. - - There are two main types of context that you will encounter: - - 1. Local context: data and dependencies your code needs to run. This might be helpful for tools, node invocations, - conditional branching, etc. - 2. LLM context: often talked about regarding the "context window" of an LLM. This is the data the LLM sees when generating a response. - The field of "context engineering" refers to the practice of optimizing the content of the context window to improve the LLM's performance. - - The context discussed in this section is the local context. As a developer, you might use the local context to eventually optimize - the LLM context (ex: use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories). - Runtime context is for immutable data like user metadata, tools, db connections, etc. Use this when you have values that don't change mid-run. +!!! version-added "New in LangGraph v0.6: `Runtime.context` replaces config['configurable']" + + The `Runtime` object is recommended to access static context and runtime-specific information like the store and stream writer. + +!!! note "'Context' is an overloaded term" + + Runtime context refers to local context: data and dependencies your code needs to run. + It does not refer to the LLM context, which is the data passed into the LLM's prompt. + + You likely want to use the local context to optimize the llm's context window. For example, you + could use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories. + Specify static context via the `context` argument to `invoke` / `stream`, which is reserved for this purpose: ```python From 7ec049e0c7ff9aefe94f26ff1398f21e9e4f9ee3 Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Mon, 28 Jul 2025 16:15:56 -0400 Subject: [PATCH 4/6] note on window --- docs/docs/agents/context.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/docs/agents/context.md b/docs/docs/agents/context.md index 94bb27616..482f8bc3c 100644 --- a/docs/docs/agents/context.md +++ b/docs/docs/agents/context.md @@ -27,7 +27,10 @@ Runtime context is for immutable data like user metadata, tools, db connections, !!! note "'Context' is an overloaded term" Runtime context refers to local context: data and dependencies your code needs to run. - It does not refer to the LLM context, which is the data passed into the LLM's prompt. + + It does not refer to: + * The LLM context, which is the data passed into the LLM's prompt. + * The "context window", which is the maximum number of tokens that can be passed to the LLM. You likely want to use the local context to optimize the llm's context window. For example, you could use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories. From 14949c81c822acbb1eff63c33f45d2a45ebfaed9 Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Mon, 28 Jul 2025 16:22:16 -0400 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Lauren Hirata Singh --- docs/docs/agents/context.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/agents/context.md b/docs/docs/agents/context.md index 5b39b4090..9c8403a6a 100644 --- a/docs/docs/agents/context.md +++ b/docs/docs/agents/context.md @@ -24,14 +24,14 @@ Runtime context is for immutable data like user metadata, tools, db connections, The `Runtime` object is recommended to access static context and runtime-specific information like the store and stream writer. -!!! note "'Context' is an overloaded term" +!!! note Runtime context refers to local context: data and dependencies your code needs to run. It does not refer to: * The LLM context, which is the data passed into the LLM's prompt. * The "context window", which is the maximum number of tokens that can be passed to the LLM. - You likely want to use the local context to optimize the llm's context window. For example, you + You likely want to use the local context to optimize the LLM's context window. For example, you could use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories. Specify static context via the `context` argument to `invoke` / `stream`, which is reserved for this purpose: From c020f01425b5de1ec97784c5644c72de882a162f Mon Sep 17 00:00:00 2001 From: Sydney Runkle Date: Mon, 28 Jul 2025 16:34:13 -0400 Subject: [PATCH 6/6] final nits --- docs/docs/agents/context.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/agents/context.md b/docs/docs/agents/context.md index 5b39b4090..68cbaf976 100644 --- a/docs/docs/agents/context.md +++ b/docs/docs/agents/context.md @@ -20,7 +20,7 @@ LangGraph provides **three** primary ways to manage context: Runtime context is for immutable data like user metadata, tools, db connections, etc. Use this when you have values that don't change mid-run. -!!! version-added "New in LangGraph v0.6: `Runtime.context` replaces config['configurable']" +!!! version-added "New in LangGraph v0.6: `Runtime.context` replaces `config['configurable']`" The `Runtime` object is recommended to access static context and runtime-specific information like the store and stream writer. @@ -32,7 +32,7 @@ Runtime context is for immutable data like user metadata, tools, db connections, * The "context window", which is the maximum number of tokens that can be passed to the LLM. You likely want to use the local context to optimize the llm's context window. For example, you - could use a user_id to fetch a user's name and information from a database to populate the context window with relevant memories. + could use a user id to fetch a user's name and information from a database to populate the context window with relevant memories. Specify static context via the `context` argument to `invoke` / `stream`, which is reserved for this purpose: