如何将运行时机密传递给可运行对象
langchain-core >= 0.2.22
我们可以使用 RunnableConfig
在运行时将机密传递给我们的可运行对象。具体来说,我们可以将带有 __
前缀的机密传递给 configurable
字段。这将确保这些机密不会作为调用的一部分被追踪:
from langchain_core.runnables import RunnableConfig
from langchain_core.tools import tool
@tool
def foo(x: int, config: RunnableConfig) -> int:
"""Sum x and a secret int"""
return x + config["configurable"]["__top_secret_int"]
foo.invoke({"x": 5}, {"configurable": {"__top_secret_int": 2, "traced_key": "bar"}})
7
查看此运行的 LangSmith 跟踪,我们可以看到 "traced_key" 被记录(作为元数据的一部分),而我们的机密整数没有被记录: https://smith.langchain.com/public/aa7e3289-49ca-422d-a408-f6b927210170/r