当前位置: 首页 > news >正文

LangChain-25 ReAct 让大模型自己思考和决策下一步 AutoGPT实现途径、AGI重要里程碑

请添加图片描述

背景介绍

大模型ReAct(Reasoning and Acting)是一种新兴的技术框架,旨在通过逻辑推理和行动序列的构建,使大型语言模型(LLM)能够达成特定的目标。这一框架的核心思想是赋予机器模型类似人类的推理和行动能力,从而在各种任务和环境中实现更高效、更智能的决策和操作。

核心组成

ReAct框架主要由三个关键概念组成:Thought(思考)、Act(行动)、和Obs(观察)。

  • Thought:由LLM模型生成,是LLM产生行为和依据的基础。它代表了模型在面对特定任务时的逻辑推理过程,是决策的前提。
  • Act:指LLM判断本次需要执行的具体行为。这通常涉及选择合适的工具或API,并生成所需的参数,以实现目标行动。
  • Obs:LLM框架对于外界输入的获取,类似于LLM的“五官”,将外界的反馈信息同步给LLM模型,协助模型进一步的做分析或者决策。

安装依赖


Prompt

# Get the prompt to use - you can modify this!
# Answer the following questions as best you can. You have access to the following tools:
#
# {tools}
#
# Use the following format:
#
# Question: the input question you must answer
# Thought: you should always think about what to do
# Action: the action to take, should be one of [{tool_names}]
# Action Input: the input to the action
# Observation: the result of the action
# ... (this Thought/Action/Action Input/Observation can repeat N times)
# Thought: I now know the final answer
# Final Answer: the final answer to the original input question
#
# Begin!
#
# Question: {input}
# Thought:{agent_scratchpad}

编写代码

from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_openai import OpenAItools = [TavilySearchResults(max_results=1)]
# Get the prompt to use - you can modify this!
# Answer the following questions as best you can. You have access to the following tools:
#
# {tools}
#
# Use the following format:
#
# Question: the input question you must answer
# Thought: you should always think about what to do
# Action: the action to take, should be one of [{tool_names}]
# Action Input: the input to the action
# Observation: the result of the action
# ... (this Thought/Action/Action Input/Observation can repeat N times)
# Thought: I now know the final answer
# Final Answer: the final answer to the original input question
#
# Begin!
#
# Question: {input}
# Thought:{agent_scratchpad}
prompt = hub.pull("hwchase17/react")# Choose the LLM to use
llm = OpenAI(model="gpt-3.5-turbo",temperature=0
)# Construct the ReAct agent
agent = create_react_agent(llm, tools, prompt)
# Create an agent executor by passing in the agent and tools
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)message1 = agent_executor.invoke({"input": "what is LangChain?"})
print(f"message1: {message1}")

执行结果

我们可以看到,大模型自己进行思考,并进行下一步。(详细可看执行日志)

➜ python3 test26.py> Entering new AgentExecutor chain...I should search for LangChain to see what it is
Action: tavily_search_results_json
Action Input: "LangChain"[{'url': 'https://towardsdatascience.com/getting-started-with-langchain-a-beginners-guide-to-building-llm-powered-applications-95fc8898732c', 'content': 'linkedin.com/in/804250ab\nMore from Leonie Monigatti and Towards Data Science\nLeonie Monigatti\nin\nTowards Data Science\nRetrieval-Augmented Generation (RAG): From Theory to LangChain Implementation\nFrom the theory of the original academic paper to its Python implementation with OpenAI, Weaviate, and LangChain\n--\n2\nMarco Peixeiro\nin\nTowards Data Science\nTimeGPT: The First Foundation Model for Time Series Forecasting\nExplore the first generative pre-trained forecasting model and apply it in a project with Python\n--\n22\nRahul Nayak\nin\nTowards Data Science\nHow to Convert Any Text Into a Graph of Concepts\nA method to convert any text corpus into a Knowledge Graph using Mistral 7B.\n--\n32\nLeonie Monigatti\nin\nTowards Data Science\nRecreating Andrej Karpathy’s Weekend Project\u200a—\u200aa Movie Search Engine\nBuilding a movie recommender system with OpenAI embeddings and a vector database\n--\n3\nRecommended from Medium\nKrishna Yogi\nBuilding a question-answering system using LLM on your private data\n--\n6\nRahul Nayak\nin\nTowards Data Science\nHow to Convert Any Text Into a Graph of Concepts\nA method to convert any text corpus into a Knowledge Graph using Mistral 7B.\n--\n32\nLists\nPredictive Modeling w/ Python\nPractical Guides to Machine Learning\nNatural Language Processing\nChatGPT prompts\nOnkar Mishra\nUsing langchain for Question Answering on own data\nStep-by-step guide to using langchain to chat with own data\n--\n10\nAmogh Agastya\nin\nBetter Programming\nHarnessing Retrieval Augmented Generation With Langchain\nImplementing RAG using Langchain\n--\n6\nAnindyadeep\nHow to integrate custom LLM using langchain. This is part 1 of my mini-series: Building end to end LLM powered applications without Open AI’s API\n--\n3\nAkriti Upadhyay\nin\nAccredian\nImplementing RAG with Langchain and Hugging Face\nUsing Open Source for Information Retrieval\n--\n6\nHelp\nStatus\nAbout\nCareers\nBlog\nPrivacy\nTerms\nText to speech\nTeams A Beginner’s Guide to Building LLM-Powered Applications\nA LangChain tutorial to build anything with large language models in Python\nLeonie Monigatti\nFollow\nTowards Data Science\n--\n27\nShare\n GitHub - hwchase17/langchain: ⚡ Building applications with LLMs through composability ⚡\n⚡ Building applications with LLMs through composability ⚡ Production Support: As you move your LangChains into…\ngithub.com\nWhat is LangChain?\nLangChain is a framework built to help you build LLM-powered applications more easily by providing you with the following:\nIt is an open-source project (GitHub repository) created by Harrison Chase.\n --\n--\n27\nWritten by Leonie Monigatti\nTowards Data Science\nDeveloper Advocate @'}] I should read the first search result to learn more about LangChain
Action: tavily_search_results_json
Action Input: "LangChain tutorial"[{'url': 'https://python.langchain.com/docs/get_started/quickstart', 'content': "Once we have a key we'll want to set it as an environment variable by running:\nIf you'd prefer not to set an environment variable you can pass the key in directly via the openai_api_key named parameter when initiating the OpenAI LLM class:\nLangSmith\u200b\nMany of the applications you build with LangChain will contain multiple steps with multiple invocations of LLM calls.\n The fact that LLM and ChatModel accept the same inputs means that you can directly swap them for one another in most chains without breaking anything,\nthough it's of course important to think about how inputs are being coerced and how that may affect model performance.\n The base message interface is defined by BaseMessage, which has two required attributes:\nLangChain provides several objects to easily distinguish between different roles:\nIf none of those roles sound right, there is also a ChatMessage class where you can specify the role manually.\n This chain will take input variables, pass those to a prompt template to create a prompt, pass the prompt to a language model, and then pass the output through an (optional) output parser.\n Next steps\u200b\nWe've touched on how to build an application with LangChain, how to trace it with LangSmith, and how to serve it with LangServe.\n"}] I should read the LangChain tutorial to learn more about LangChain
Action: tavily_search_results_json
Action Input: "LangChain tutorial"[{'url': 'https://python.langchain.com/docs/additional_resources/tutorials', 'content': 'Learn how to use Langchain, a Python library for building AI applications with natural language processing and generation. Explore books, handbooks, cheatsheets, courses, and tutorials by various authors and topics.'}] I should read the LangChain tutorial to learn more about LangChain
Action: tavily_search_results_json

在这里插入图片描述

相关文章:

LangChain-25 ReAct 让大模型自己思考和决策下一步 AutoGPT实现途径、AGI重要里程碑

背景介绍 大模型ReAct(Reasoning and Acting)是一种新兴的技术框架,旨在通过逻辑推理和行动序列的构建,使大型语言模型(LLM)能够达成特定的目标。这一框架的核心思想是赋予机器模型类似人类的推理和行动能…...

24/04/15总结

多线程: 线程 线程是操作系统能够进行运算调度的最小单位。它被包含在进程之中,是进程中的实际运作单位 并发:在同一时刻,有多个指令在单个cpu上交替执行 并行:在同一时刻,有多个指令在多个cpu上同时执行 多线程的实现方式 1.继承…...

vue3、vue2中nextTick源码解析

nexttick是啥 nextTick是Vue提供的一个全局API,由于Vue的异步更新策略导致我们对数据的修改不会更新,如果此时想要获取更新后的Dom,就需要使用这个方法. vue的异步更新策略意思是如果数据变化,vue不会立刻更新dom,而是开启一个队列,把组件更…...

【氮化镓】GaN HEMTs结温和热阻测试方法

文章《Temperature rise detection in GaN high-electron-mobility transistors via gate-drain Schottky junction forward-conduction voltages》,由Xiujuan Huang, Chunsheng Guo, Qian Wen, Shiwei Feng, 和 Yamin Zhang撰写,发表在《Microelectroni…...

c++11 标准模板(STL)本地化库 - 平面类别(std::codecvt) - 在字符编码间转换,包括 UTF-8、UTF-16、UTF-32 (四)

本地化库 本地环境设施包含字符分类和字符串校对、数值、货币及日期/时间格式化和分析,以及消息取得的国际化支持。本地环境设置控制流 I/O 、正则表达式库和 C 标准库的其他组件的行为。 平面类别 在字符编码间转换,包括 UTF-8、UTF-16、UTF-32 std::…...

【状态压缩 容斥原理 组合数学】100267. 单面值组合的第 K 小金额

本文涉及知识点 状态压缩 容斥原理 组合数学 二分查找算法合集 LeetCode100267. 单面值组合的第 K 小金额 给你一个整数数组 coins 表示不同面额的硬币,另给你一个整数 k 。 你有无限量的每种面额的硬币。但是,你 不能 组合使用不同面额的硬币。 返回…...

.net框架和c#程序设计第三次测试

目录 一、测试要求 二、实现效果 三、实现代码 一、测试要求 二、实现效果 数据库中的内容&#xff1a; 使用数据库中的账号登录&#xff1a; 若不是数据库中的内容&#xff1a; 三、实现代码 login.aspx文件&#xff1a; <% Page Language"C#" AutoEventW…...

架构师系列-搜索引擎ElasticSearch(五)- 索引设计

索引创建后&#xff0c;要非常谨慎&#xff0c;创建不好后面会出现各种问题。 索引设计的重要性 索引创建后&#xff0c;索引分片只能通过_split和_shrink 接口对其进行成倍的增加和缩减。 ES的数据是通过_routing分配到各个分片上的&#xff0c;所以本质上不推荐区改变索引的…...

kafka ----修改log4j、jmx、jvm参数等

1、修改log4j 日志路径 在kafka-run-class.sh文件中修改如下配置&#xff0c;将 LOG_DIR变量指定为自己想要存储的路径 # Log directory to use if [ "x$LOG_DIR" "x" ]; thenLOG_DIR"$base_dir/logs" fi2、修改jmx参数 在kafka-run-class.s…...

Python 全栈 Web 应用模板:成熟架构,急速开发 | 开源日报 No.223

tiangolo/full-stack-fastapi-template Stars: 15.6k License: MIT full-stack-fastapi-template 是一个现代化的全栈 Web 应用模板。 使用 FastAPI 构建 Python 后端 API。使用 SQLModel 进行 Python SQL 数据库交互&#xff08;ORM&#xff09;。Pydantic 用于数据验证和设…...

STM32之DHT11温湿度传感器

目录 一 DHT11温湿度传感器简介 1.1 传感器特点 1.2 传感器特性 1.3 传感器引脚说明 二 测量原理及方法 2.1 典型应用电路 2.2 单线制串行简介 2.2.1 串行接口 (单线双向) 2.2.2 数据示例 2.3 通信时序 三 单片机简介 3.1 STM32F103C8T6最小系统板 四 接线说明 …...

paddle ocr

paddle安装教程&#xff0c;git clone xxxgit https://blog.csdn.net/Castlehe/article/details/117356343 只有paddle 1.x 的教程&#xff1a;https://github.com/PaddlePaddle/PaddleOCR/blob/static/doc/doc_en/quickstart_en.md 报错是因为安装的是paddle 2.x而教程只给了…...

Xcode 15.0 新 #Preview 预览让 SwiftUI 界面调试更加悠然自得

概览 从 Xcode 15 开始&#xff0c;苹果推出了新的 #Preview 宏预览机制&#xff0c;它无论从语法还是灵活性上都远远超过之前的预览方式。#Preview 不但可以实时预览 SwiftUI 视图&#xff0c;而且对 UIKit 的界面预览也是信手拈来。 想学习新 #Preview 预览的一些超实用调试…...

【VS2019】x64 Native Tools Command Prompt for Vs 2019使用conda命令进入环境

【VS2019】x64 Native Tools Command Prompt for Vs 2019使用conda命令进入环境 安装完VS2019后&#xff0c;打开终端x64 Native Tools Command Prompt for Vs 2019&#xff0c;直接运行conda会出现‘conda’ 不是内部或外部命令&#xff0c;也不是可运行的程序 原因分析&am…...

网络篇09 | 运输层 udp

网络篇09 | 运输层 udp 01 简介UDP 是面向报文的 02 报文协议 01 简介 UDP 只在 IP 的数据报服务之上增加了一些功能&#xff1a;复用和分用、差错检测 UDP 的主要特点&#xff1a;无连接。发送数据之前不需要建立连接。 使用尽最大努力交付。即不保证可靠交付。 面向报文。…...

vim相关指令

vim的各种模式及其转换关系图 vim 默认处于命令模式&#xff01;&#xff01;&#xff01; 模式之间转换的指令 除【命令模式】之外&#xff0c;其它模式要切换到【命令模式】&#xff0c;只需要无脑 ESC 即可&#xff01;&#xff01;&#xff01; [ 命令模式 ] 切换至 [ 插…...

STM32常见调试工具介绍

STM32的常见调试工具主要包括ST-LINK、USB转TTL、USB转485以及USB转CAN。这些工具在嵌入式系统开发、调试以及通信中发挥着重要的作用。 1.ST-LINK&#xff1a; ST-LINK是STMicroelectronics公司专为其STM32系列微控制器开发的调试和编程工具。既能仿真也能将编译好的程序下载…...

简历上写熟悉Linux下常用命令?直接寄

大家写简历技术栈时&#xff0c;都觉得越多越好&#xff0c;其中一条&#xff0c;熟悉Linux下常用命令&#xff1f;其实开发中Linux不是必备考点&#xff0c;除了运维&#xff0c;真正用的多的仅仅cd ls mkdir等&#xff0c;但当面试官问到上面命令时&#xff0c;是不是就傻眼了…...

【设计模式】4、prototype 原型模式

四、prototype 原型模式 https://refactoringguru.cn/design-patterns/prototype 如果希望 复制对象, 可使用 “prototype 模式” 如果 “待复制的对象” 是 interface 而不是 class, 或者如果 class 有 private 变量时. 无法知道 "待复制的对象"的细节, 则需要其…...

ES6 关于Class类的继承 extends(2024-04-10)

1、简介 类Class 可以通过extends关键字实现继承&#xff0c;让子类继承父类的属性和方法。extends 的写法比 ES5 的原型链继承&#xff0c;要清晰和方便很多。 class Foo {constructor(x, y) {this.x x;this.y y;console.log(父类构造函数)}toString() {return ( this.x …...

深度解析 APT:Linux 运维人员的“瑞士军刀”,你真的用对了吗?

在 Linux 的世界里&#xff0c;尤其是对于 Debian 系&#xff08;如 Ubuntu、Linux Mint&#xff09;的用户来说&#xff0c;APT 是一个无法绕开的名字。很多初学者在安装软件时&#xff0c;只知道机械地复制粘贴 sudo apt install 命令&#xff0c;却对背后这套强大的机制知之…...

从 0 开始讲透 C++ Lambda(对标 Java)

在写 C 多线程或 STL 时&#xff0c;经常会看到这样的代码&#xff1a;std::thread t([]{ std::cout << "Hello C Thread\n"; });很多人第一反应&#xff1a;这 [] 是什么&#xff1f;为什么和 Java 不一样&#xff1f;一、先给结论&#xff08;先建立整体认知…...

OpenClaw异常处理:配置nanobot自动重试失败任务

OpenClaw异常处理&#xff1a;配置nanobot自动重试失败任务 1. 为什么需要自动重试机制 上周我让OpenClaw执行一个简单的夜间数据收集任务时&#xff0c;遇到了一个令人头疼的问题。凌晨3点&#xff0c;网络突然波动导致任务中断&#xff0c;而当我早上打开电脑时&#xff0c…...

Ubuntu 22.04 开机卡在/dev/sda3: clean的磁盘空间分析与扩容实战

1. 问题现象与初步诊断 当你兴冲冲地按下Ubuntu 22.04的开机键&#xff0c;却看到屏幕卡在/dev/sda3: clean这个神秘提示时&#xff0c;那种感觉就像开车时突然遇到路障——明明昨天还能正常使用&#xff0c;今天怎么就罢工了&#xff1f;这种情况我遇到过不止一次&#xff0c;…...

AudioLDM-S效果惊艳:科幻飞船、城市夜晚,AI生成的音效有多真实?

AudioLDM-S效果惊艳&#xff1a;科幻飞船、城市夜晚&#xff0c;AI生成的音效有多真实&#xff1f; 想象一下&#xff0c;你正在制作一个科幻短片&#xff0c;需要一个飞船引擎启动时低沉、充满能量的嗡鸣声。或者&#xff0c;你想为一段城市夜景视频配上背景音&#xff0c;需…...

突破语言边界:XUnity.AutoTranslator全场景应用指南

突破语言边界&#xff1a;XUnity.AutoTranslator全场景应用指南 【免费下载链接】XUnity.AutoTranslator 项目地址: https://gitcode.com/gh_mirrors/xu/XUnity.AutoTranslator 当你打开一款期待已久的外文游戏&#xff0c;却被满屏陌生文字阻挡了探索的脚步&#xff1…...

开局掌控者:EdB Prepare Carefully - RimWorld自定义体验革命

开局掌控者&#xff1a;EdB Prepare Carefully - RimWorld自定义体验革命 【免费下载链接】EdBPrepareCarefully EdB Prepare Carefully, a RimWorld mod 项目地址: https://gitcode.com/gh_mirrors/ed/EdBPrepareCarefully 副标题&#xff1a;如何告别随机开局&#xf…...

OpenClaw多通道管理:GLM-4.7-Flash同时对接飞书与钉钉的配置技巧

OpenClaw多通道管理&#xff1a;GLM-4.7-Flash同时对接飞书与钉钉的配置技巧 1. 为什么需要多通道管理&#xff1f; 上周我接到一个技术咨询需求&#xff1a;一个小型内容团队需要同时在飞书和钉钉两个平台上接收AI助手服务。他们的编辑用飞书&#xff0c;运营用钉钉&#xf…...

橄榄菜芝士焗三文鱼配脆米饼:潮汕咸香与海洋鲜美的跨界狂想

潮汕人家的厨房里&#xff0c;总有一罐橄榄菜。乌黑油亮&#xff0c;咸香醇厚&#xff0c;是白粥的最佳伴侣&#xff0c;也是蒸鱼炒菜的秘武器。而深海里的三文鱼&#xff0c;肥美丰腴&#xff0c;油脂均匀&#xff0c;是西餐的宠儿。当潮汕的咸香遇见西式的丰腴&#xff0c;再…...

2026权威评测:盘点毕业论文AIGC免费降重神器

【CSDN 资深算法架构师 / NLP技术专栏 导读】 各位还在发际线边缘挣扎的应届生和硕博党们&#xff0c;到了2026年&#xff0c;如果你的电脑里还装着那种老掉牙的“同义词替换”降重软件&#xff0c;我劝你赶紧停手&#xff01; 最近CSDN社群里哀嚎一片&#xff1a;“知网查重过…...