langgraph-reflexion

news/2025/11/2 15:01:41/文章来源:https://www.cnblogs.com/lightsong/p/19184974

langgraph-reflexion

https://github.com/fanqingsong/langgraph-reflexion/tree/main

Implementation of a sophisticated Reflexion agent using LangGraph and LangChain, designed to generate high-quality responses through self-reflection and iterative improvement.

This project demonstrates advanced AI agent capabilities using LangGraph's state-of-the-art control flow mechanisms for self-reflection and response refinement.

Logo

Features

  • Self-Reflection: Implements sophisticated reflection mechanisms for response improvement
  • Iterative Refinement: Uses a graph-based approach to iteratively enhance responses
  • Production-Ready: Built with scalability and real-world applications in mind
  • Integrated Search: Leverages Tavily search for enhanced response accuracy
  • Structured Output: Uses Pydantic models for reliable data handling
  • Docker Support: Complete Docker setup for easy deployment
  • LangGraph Dev Server: Supports LangGraph Studio for visualization and debugging

Architecture

The agent uses a graph-based architecture with the following components:

  • Entry Point: draft node for initial response generation
  • Processing Nodes: execute_tools and revise for refinement
  • Maximum Iterations: 2 (configurable)
  • Chain Components: First responder and revisor using GPT-4
  • Tool Integration: Tavily Search for web research

 

https://blog.langchain.com/reflection-agents/

Reflexion by Shinn, et. al., is an architecture designed to learn through verbal feedback and self-reflection. Within reflexion, the actor agent explicitly critiques each response and grounds its criticism in external data. It is forced to generate citations and explicitly enumerate superfluous and missing aspects of the generated response. This makes the content of the reflections more constructive and better steers the generator in responding to the feedback.

In the linked example, we stop after a fixed number of steps, though you can also offload this decision to the reflection LLM call.

An overview of the agent loop is shown below:

Reflexion Actor Overview

For each step, the responder is tasked with generating a response, along with additional actions in the form of search queries. Then the revisor is prompted to reflect on the current state. The logic can be defined in LangGraph as follows:

from langgraph.graph import END, MessageGraphMAX_ITERATIONS = 5
builder = MessageGraph()
builder.add_node("draft", first_responder.respond)
builder.add_node("execute_tools", execute_tools)
builder.add_node("revise", revisor.respond)
# draft -> execute_tools
builder.add_edge("draft", "execute_tools")
# execute_tools -> revise
builder.add_edge("execute_tools", "revise")# Define looping logic:
def event_loop(state: List[BaseMessage]) -> str:# in our case, we'll just stop after N plansnum_iterations = _get_num_iterations(state)if num_iterations > MAX_ITERATIONS:return ENDreturn "execute_tools"# revise -> execute_tools OR end
builder.add_conditional_edges("revise", event_loop)
builder.set_entry_point("draft")
graph = builder.compile()

This agent can effectively use explicit reflections and web-based citations to improve the quality of the final response. It only pursues one fixed trajectory, however, so if it makes a misstep, that error can impact subsequent decisions.

 

 

https://python.langchain.com.cn/docs/modules/agents/tools/how_to/custom_tools

https://juejin.cn/post/7514593209680986163

import requests
from langchain.tools import StructuredTooldef post_message(url: str, body: dict, parameters: Optional[dict] = None) -> str:"""Sends a POST request to the given url with the given body and parameters."""result = requests.post(url, json=body, params=parameters)return f"Status: {result.status_code} - {result.text}"tool = StructuredTool.from_function(post_message)

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/953629.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WC 2026 备战记录

CSP 2025 炸了,意识到 CTT 再炸就没有 WC 玩了,很生气! 记录了日常训练中的一些题。 目录

面向院区病房的空间智能体新范式:下一代病房框架研究(上)

面向院区病房的空间智能体新范式:下一代病房框架研究(上)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Conso…

JSR 303 常用注解及示例

JSR 303 常用注解及示例JSR 303 常用注解及示例 ✅ JSR 303 常用注解及示例注解 作用 示例@NotNull 值不能为 null @NotNull(message = "ID不能为空")@NotBlank 字符串不能为空(非 null 且去除空格后长度 &…

实用指南:用 Go 并发优化用户中心 API:goroutine 和 errgroup 的实战魔法

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

MySQL02 函数

MySQL02 函数函数 字符串函数调用方式:SELECT F(x) 或和其他语法结合使用 update user set id = lpad(id,4,0);一般来说都是更新,先选中表,再对对象调用函数,用等于号连接。 数值函数 CEIL(X)//向上取整 FLOOR(X)/…

夸克网盘免费领取1TB空间的方法

一、活动时间 2025年01月01日 ~ 2026年12月31日 二、面向用户 夸克 App 新用户,即在手机端和 PC 端从未使用手机号注册过夸克账号的用户只安装过夸克客户端但从未注册夸克账号的用户,也可获得本次新用户活动奖励; …

前端三剑客——javascript函数作用域与内置函数

大纲 :1.js代码执行流程2.函数的声明与匿名函数自执行:普通函数/匿名函数及其自执行普通函数/匿名函数/箭头函数/2者区别3.var和let区别与函数作用域:var和let作用域区别匿名函数/箭头函数this指向4.内置函数js代码执…

完全背包内外循环是否能对调?

结论:完全背包内外层循环不可以对调之前一直认为完全背包内外层循环可以互相对调,可能也是由于某一些题目数据的巧合吧,现在碰到一道题目帮我纠正了 题目 纠正 内外层循环对调,无非就是先物品后容积,还有就是先容…

浅谈ASP.NET Core中间件实现分布式 Session

浅谈ASP.NET Core中间件实现分布式 Session浅谈ASP.NET Core中间件实现分布式 Session 1.1. 中间件原理 1.1.1. 什么是中间件 中间件是段代码用于处理请求和响应,通常多个中间件链接起来形成管道,由每个中间件自己来…

.NET周刊【10月第3期 2025-10-19】

国内文章 史诗级警报:ASP.NET Core 被曝 CVSS 9.9 分漏洞,几乎所有.NET 版本无一幸免! https://www.cnblogs.com/netry/p/19147223/CVE-2025-55315 2025 年 10 月的微软补丁星期二更新中,ASP.NET Core 漏洞 CVE-20…

2025 年 11 月快速卷帘门厂家最新推荐,聚焦高端定制需求与全案交付能力!

当前快速卷帘门应用场景日益多元,高端定制需求与全案交付能力成为采购关键。据行业权威门窗协会 2025 年 10 月调研显示,近 42% 的采购方因厂家定制能力不足,导致产品与场景适配偏差,额外改造成本增加 30%;而交付…

【大模型应用开发】之调用大模型

调用大模型 大模型接口规范 大模型接口说明大模型开发是通过访问模型对外暴露的API接口,实现与大模型的交互。 大多数大模型都遵循OpenAI接口规范,是基于Http协议的接口。因此请求路径、参数和返回值信息都是类似的。…

11/2

找第k小的数的分治算法描述:先选最右元素作基准,partition 函数将数组分区,小于等于基准的放左,大于的放右,返回基准位置 p。find 函数递归:若 p 左元素数 c 等于 k,返回 a [p];k 小于 c 则在左分区找 k;否则…

2025 年 11 月快速卷帘门厂家最新推荐,技术实力与市场口碑深度解析!

快速卷帘门行业的技术迭代与市场反馈,是采购决策的关键依据。据行业权威门窗协会 2025 年 10 月发布的调研数据,技术落后导致的产品淘汰率达 32%,而市场口碑差的品牌客户复购率不足 20%。为精准筛选优质厂家,本次联…

2025 年 11 月快速卷帘门厂家最新推荐,实力品牌深度解析采购无忧之选!

快速卷帘门采购过程中,品牌实力不足、服务缺失往往导致采购风险,据行业权威门窗协会 2025 年 10 月数据显示,近 38% 的采购方因选择非实力品牌,遭遇交货延迟、售后缺位等问题,额外成本增加 25%。为助力采购无忧,…

基于Opengauss的餐厅管理系统

项目名称:基于Opengauss的餐厅管理系统这个项目属于哪个课程 https://edu.cnblogs.com/campus/gdgy/Class34Grade23ComputerScience/homework/13480作业要求 作业链接作业的目标 小组组队,完成团队展示及选题,讨论团…

2025 年 11 月杀虫公司最新推荐,聚焦资质、案例、售后的五家机构深度解读!

近期,行业权威协会开展杀虫服务机构专项测评,以 “资质合规性、案例适配性、售后完善度” 为核心维度,覆盖 120 家服务商。测评采用 “三维验证法”:资质层面审核有害防制 A 级证书、三体系认证等 12 项核心资质;…

WSL2安装perf的简易方法

前言 由于WSL2使用的是微软定制的内核,并非标准的Ubuntu内核,因此直接使用apt安装linux-tools包会失败。 网上给出的方法很多是直接下载微软的 wsl2 内核源码并对其中的 perf 进行手动编译来实现,具体步骤有些繁琐。…