LangGraph 允许运行时配置动态修改智能体行为和权限。使用 LangSmith Deployment 时,您可以在请求正文(config)或特定请求标头中传递此配置。这使基于用户身份或其他请求的调整成为可能。 为了隐私,通过 langgraph.json 文件中的 http.configurable_headers 部分控制将哪些标头传递到运行时配置。 以下是如何自定义包含和排除的标头:
{
  "http": {
    "configurable_headers": {
      "include": ["x-user-id", "x-organization-id", "my-prefix-*"],
      "exclude": ["authorization", "x-api-key"]
    }
  }
}
includeexclude 列表接受精确的标头名称或使用 * 匹配任意数量字符的模式。为了您的安全,不支持其他正则表达式模式。

在图中使用

您可以使用任何节点的 config 参数访问图中包含的标头。
def my_node(state, config):
  organization_id = config["configurable"].get("x-organization-id")
  ...
或者从上下文中获取(在工具和或其他嵌套函数中很有用)。
from langgraph.config import get_config

def search_everything(query: str):
  organization_id = get_config()["configurable"].get("x-organization-id")
  ...
您甚至可以使用它动态编译图。
# my_graph.py.
import contextlib

@contextlib.asynccontextmanager
async def generate_agent(config):
  organization_id = config["configurable"].get("x-organization-id")
  if organization_id == "org1":
    graph = ...
    yield graph
  else:
    graph = ...
    yield graph

{
  "graphs": {"agent": "my_grph.py:generate_agent"}
}

选择退出可配置标头

如果您想选择退出可配置标头,只需在 exclude 列表中设置通配符模式:
{
  "http": {
    "configurable_headers": {
      "exclude": ["*"]
    }
  }
}
这将排除所有标头添加到运行的配置中。 请注意,排除优先于包含。
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.