ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

langchain1.X学习笔记-36-上下文与记忆Memory之长期记忆(四)静态运行时上下文(Static runtime Context)在工具中访问

langchain1.X学习笔记-36-上下文与记忆Memory之长期记忆(四)静态运行时上下文(Static runtime Context)在工具中访问 文章目录1 模型初始化2 工具的自定义args_schema3 工具读写长期记忆3.1 代码示例3.1.1 输出thread_1 messages3.1.2 输出thread_2 messages3.2 代码分析3.2.1 核心组件3.2.2 两个关键设计3.2.3 第一次调用(thread_1)3.2.4 第二次调用(thread_1同一线程)3.2.5 第三次调用(thread_2不同线程同一用户)3.2.6 Store vs Checkpointer的分工tool参数列表中的ToolRuntime是Langchain/Langgraph运行时注入的,在工具schema中没有体现。工具函数通过runtime: ToolRuntime[UserContext, Any]参数自动获取runtime.context(用户ID)和runtime.store(存储实例),无需手动传递。1 模型初始化from langchain_openaiimportChatOpenAI from dotenvimportload_dotenvimportos load_dotenv(override=True)#通过ChatOpenAI 连接智谱AI模型API_KEY=os.getenv("API_KEY"
返回列表