LangChain Code

标签:LangChain Code下的所有文章

24 篇文章
0 min 平均阅读
Memory Basics - main.py

""" LangChain 1.0 - Memory Basics (内存管理基础) ========================================== 本模块重点讲解 LangGraph 提供的内存管理机制,包括: 1. InMemorySaver...

Memory Basics.py

# 核心概念 # 内存 = Agent 记住对话历史的能力 # 默认情况下,每次调用 agent.invoke() 都是全新的开始,不记得之前的对话。使用 InMemorySaver 可以让 Agent 记住历史。 # 基本用法 # 没有内存(默认) from langchain.agents ...

Agent Loop - main.py

"""LangChain 1.0 - Agent 执行循环本模块重点讲解:Agent 执行循环的详细过程流式输出(streaming)查看中间步骤理解消息流转"""import sysimport osfrom urllib import responsefrom openai import cha...

Agent Loop.py

# 核心概念 # Agent 执行循环 = 自动化的"思考-行动-观察"过程 # Agent 不是一次性调用,而是一个循环: # 用户问题 → AI 思考 → 调用工具 → 观察结果 → 继续思考 → 最终答案 # 执行循环详解 # 执行循环详解 # ┌──────────...

tools 工具类

calculator.py""" 自定义工具:计算器 ================== 演示带多个参数的工具 """ from langchain.tools import tool @tool def calculator(o...

Custom Tools - main.py

""" LangChain 1.0 - 自定义工具 (@tool 装饰器) ========================================= 本模块重点讲解: 1. 使用 @tool 装饰器创建工具(LangChain 1.0 推荐方式) 2. 工具...

Custom_Tools.py

# 04 - Custom Tools (自定义工具) # 核心概念 # 工具 (Tool) = 给 AI 的函数 # 使用 @tool 装饰器,让 AI 能调用你的 Python 函数。 # @tool 基本用法 import json from turtle import st from ...

messages.py

# 03 - Messages: 消息类型与对话管理 # 核心要点(只讲难点) # 初始化模型 from init_model import get_chat_model chat_model = get_chat_model() # 角色 字典格式 对象格式 用途 # Sys...