尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

langgraph-reflexion

langgraph-reflexion
📅 发布时间:2026/6/18 15:56:18

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.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

相关新闻

  • MySQL02 函数
  • python:pymupdf的save参数
  • 浅谈ASP.NET Core中间件实现分布式 Session

最新新闻

  • 2026年6月核心快讯:杭州帝舵手表保养收费价格与南京法穆兰保养收费明细 - 亨得利官方售后
  • 论文双检时代破局:告别无效改写,百考通AI一站式解决重复率与AIGC超标难题
  • 生成式AI实操手记:从GAN、VAE到扩散模型的可复现训练指南
  • 江苏地区消防证培训综合实力排行及核心指标解析 - 起跑123
  • Cecropin A ;KWKLFKKIEKVGQNIRDGIIKAGPAVAVVGQATQIAK-NH₂
  • Citra 3DS模拟器终极画质优化指南:如何在普通电脑上获得最佳视觉体验

日新闻

  • 2026年不锈钢卷板厂家推荐排行榜:冷轧热轧/304/201不锈钢卷板,高颜值耐腐蚀源头厂家实力精选 - 企业推荐官【官方】
  • FLUX.1-dev FP8模型实战指南:24GB以下显卡高效部署方案
  • 2026佛山长途搬家价目表:跨省跨市搬家费用完整计算指南 - 从来都是英雄出少年

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号