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

langgraph-reflexion

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.jsqmd.com/news/29196/

相关文章:

  • WC 2026 备战记录
  • 面向院区病房的空间智能体新范式:下一代病房框架研究(上)
  • JSR 303 常用注解及示例
  • 实用指南:用 Go 并发优化用户中心 API:goroutine 和 errgroup 的实战魔法
  • MySQL02 函数
  • 夸克网盘免费领取1TB空间的方法
  • python:pymupdf的save参数
  • vmware fusion:windows会自动挂起
  • 前端三剑客——javascript函数作用域与内置函数
  • 完全背包内外循环是否能对调?
  • 浅谈ASP.NET Core中间件实现分布式 Session
  • .NET周刊【10月第3期 2025-10-19】
  • 2025 年 11 月快速卷帘门厂家最新推荐,聚焦高端定制需求与全案交付能力!
  • 【大模型应用开发】之调用大模型
  • 11/2
  • 2025 年 11 月快速卷帘门厂家最新推荐,技术实力与市场口碑深度解析!
  • 2025 年 11 月快速卷帘门厂家最新推荐,实力品牌深度解析采购无忧之选!
  • 基于Opengauss的餐厅管理系统
  • 2025 年 11 月杀虫公司最新推荐,聚焦资质、案例、售后的五家机构深度解读!
  • WSL2安装perf的简易方法
  • 从图像到文本:手写体汉字识别的技术路径与产业赋能
  • 2025 年 11 月杀虫公司最新推荐,高性能与可靠性兼具的优质品牌!
  • 2025 年 11 月杀虫公司最新推荐,聚焦高端定制需求与全案交付能力!
  • 微信小脚本的校园生活助手系统
  • 2025 年 11 月不锈钢厂家推荐排行榜,不锈钢板,不锈钢管,不锈钢卷,不锈钢带,不锈钢材批发公司推荐!
  • 震卦、困卦、中孚卦
  • [2025.11.2 鲜花] trick or treat
  • 基于MATLAB绘制CALIPSO Level 2产品中体积退偏比垂直廓线和频率分布直方图
  • Redis各类数据结构详细介绍及其在Go语言Gin框架下实践应用
  • 2025 年 11 月弹簧片厂家推荐排行榜,304弹簧片,301弹簧片,不锈铁,430不锈钢板材公司推荐