langgraph-genui

news/2025/9/28 16:45:24/文章来源:https://www.cnblogs.com/lightsong/p/19117087

langgraph-genui

https://github.com/fanqingsong/langgraph-genui

LangGraph GenUI 微服务架构

这是一个基于 LangGraph 的微服务架构项目,包含智能体服务和前端对话界面两个独立的微服务。

项目结构

langgraph-genui/
├── agent/                    # 智能体微服务
│   ├── src/                 # 智能体源代码
│   ├── langgraph.json       # LangGraph 配置
│   ├── pyproject.toml       # Python 项目配置
│   ├── requirements.txt     # Python 依赖
│   ├── Dockerfile          # 智能体 Docker 配置
│   ├── docker-compose.yml  # 智能体 Docker Compose 配置
│   ├── start.sh            # 智能体启动脚本
│   └── README.md           # 智能体服务说明
├── chatui/                  # 前端对话界面微服务
│   ├── src/                 # 前端源代码
│   ├── public/              # 静态资源
│   ├── package.json         # Node.js 项目配置
│   ├── Dockerfile          # 前端 Docker 配置
│   ├── docker-compose.yml  # 前端 Docker Compose 配置
│   ├── start.sh            # 前端启动脚本
│   └── README.md           # 前端服务说明
└── README.md               # 项目总体说明
 

微服务说明

1. Agent 服务 (端口 8123)

  • 功能: LangGraph 智能体后端服务
  • 技术栈: Python + LangGraph + Docker
  • API: 提供智能体 API 接口
  • Studio: 支持 LangGraph Studio 可视化界面

2. ChatUI 服务 (端口 3000)

  • 功能: 前端对话界面
  • 技术栈: Next.js + React + TypeScript + Docker
  • 特性: 基于 agent-chat-ui 项目

 

参考:

Agent Chat UI

https://github.com/langchain-ai/agent-chat-ui

 Agent Chat UI is a Next.js application which enables chatting with any LangGraph server with a messages key through a chat interface.

Usage

Once the app is running (or if using the deployed site), you'll be prompted to enter:

  • Deployment URL: The URL of the LangGraph server you want to chat with. This can be a production or development URL.
  • Assistant/Graph ID: The name of the graph, or ID of the assistant to use when fetching, and submitting runs via the chat interface.
  • LangSmith API Key: (only required for connecting to deployed LangGraph servers) Your LangSmith API key to use when authenticating requests sent to LangGraph servers.

After entering these values, click Continue. You'll then be redirected to a chat interface where you can start chatting with your LangGraph server.

 

LangChain 和 Vercel AI SDK 协同打造生成式 UI

https://www.bilibili.com/opus/944968117423964169

149beac610c07ea0ed4ed056c3aa080f28357052

 

生成式 UI 实现流程

为了理解 LangChain 和 Vercel AI SDK 如何协同创建流式 UI,让我们按图中的箭头逐步分析。

请求流程(蓝色箭头)

  1. 用户互动:用户与前端的对话组件进行互动,进行提问(及文件上传)。
  2. 请求逻辑:用户互动触发客户端 UI 组件向服务端 RSC 逻辑模块发送请求,该模块包含处理请求所需的逻辑。(通常 RSC 逻辑模块会先向 Next.js React 前端回传准备好的各类加载界面,前端接收后渲染加载界面)
  3. 请求 LangChain.js:RSC 逻辑模块将请求发送给 LangChain.js,作为和后端 LangChain Python 服务之间的桥梁。
  4. 请求 LangServe:LangChain.js 将请求发送给 LangServe(通过 FastAPI),调用请求中指定的模型或工具;并开始接收流失数据回传。

响应流程(紫色箭头)

  1. 调用应用逻辑:LangServe 处理请求,调用指定的 LLM 应用逻辑。该过程由 LangGraph 管理,按需执行应用的推理逻辑,或者模型上所绑定的工具(例如 Foo 和 Bar)。
  2. 数据流回传:LangServe 将模型或工具执行的结果通过数据流的方式,经过 LangChain.js 的 Remote Runnable 对象传输回服务端的 RSC 逻辑模块。
  3. 流传输 UI: RSC 逻辑模块基于响应数据创建或更新可流式传输回前端的流式组件,并将服务端渲染得到的 UI 内容回传给前端。
  4. UI 更新:Next.js React 客户端接收到新的可渲染内容后动态更新前端 UI(如渲染 Foo 工具的组件界面),以新的数据提供无缝和互动的用户体验。

总结

LangChain 和 Vercel AI SDK 的结合为构建生成式 UI 应用提供了强大的工具包。通过利用这两种技术的优势,开发人员可以创建高度个性化和互动的用户界面,实时适应用户行为和偏好。这种集成不仅增强了用户参与度,还简化了开发过程,使得构建复杂的 AI 驱动应用变得更加容易。

 

LangChain Generative UI(生成式UI)

 

https://www.bilibili.com/video/BV1T4421D7pR/?vd_source=57e261300f39bf692de396b55bf8c41b&spm_id_from=333.788.player.switch

Gen UI Python: https://github.com/bracesproul/gen-ui-python

Gen UI JS: https://github.com/bracesproul/gen-ui Vercel

AI SDK RSC: https://sdk.vercel.ai/docs/ai-sdk-rsc/overview

 

 

How to implement generative user interfaces with LangGraph

https://docs.langchain.com/langgraph-platform/generative-ui-react

Generative user interfaces (Generative UI) allows agents to go beyond text and generate rich user interfaces. This enables creating more interactive and context-aware applications where the UI adapts based on the conversation flow and AI responses. Agent Chat showing a prompt about booking/lodging and a generated set of hotel listing cards (images, titles, prices, locations) rendered inline as UI components.LangGraph Platform supports colocating your React components with your graph code. This allows you to focus on building specific UI components for your graph while easily plugging into existing chat interfaces such as Agent Chat and loading the code only when actually needed.

 

Agent Chat UI

https://docs.langchain.com/oss/python/langchain/ui

LangChain provides a powerful prebuilt user interface that work seamlessly with agents created using create_agent(). This UI is designed to provide rich, interactive experiences for your agents with minimal setup, whether you’re running locally or in a deployed context (such as LangGraph Platform).

 

Agent Chat UI

Agent Chat UI is a Next.js application that provides a conversational interface for interacting with any LangChain agent. It supports real-time chat, tool visualization, and advanced features like time-travel debugging and state forking. Agent Chat UI is open source and can be adapted to your application needs.

 

Connect to your agent

Agent Chat UI can connect to both local and deployed agents. After starting Agent Chat UI, you’ll need to configure it to connect to your agent:

  1. Graph ID: Enter your graph name (find this under graphs in your langgraph.json file)
  2. Deployment URL: Your LangGraph server’s endpoint (e.g., http://localhost:2024 for local development, or your deployed agent’s URL)
  3. LangSmith API key (optional): Add your LangSmith API key (not required if you’re using a local LangGraph server)

 

Once configured, Agent Chat UI will automatically fetch and display any interrupted threads from your agent.

 

🧲 Claude Code 演练:LangGraph 构建生成式 UI 界面开发演示 🦜

https://www.bilibili.com/video/BV1jZ37zoEgc/?vd_source=57e261300f39bf692de396b55bf8c41b

GAC平台:https://gaccode.com/signup?ref=UWDADYQI

最佳实践:https://www.youware.com/project/12j7l4bqao

LangGraph GenUI:https://langchain-ai.github.io/langgraph/cloud/how-tos/generative_ui_react/

 

如何使用 LangGraph 实现生成式用户界面

https://github.langchain.ac.cn/langgraphjs/cloud/how-tos/generative_ui_react/#learn-more

生成式用户界面(Generative UI)允许 Agent 超越文本,生成丰富的用户界面。这使得创建更具交互性和上下文感知能力的应用成为可能,其中 UI 会根据对话流程和 AI 响应进行调整。

Generative UI Sample

LangGraph 平台支持将您的 React 组件与您的图代码并置。这使您能够专注于为您的图构建特定的 UI 组件,同时轻松插入到现有的聊天界面中,例如 Agent Chat,并仅在实际需要时才加载代码。

 

import uuid
from typing import Annotated, Sequence, TypedDictfrom langchain_core.messages import AIMessage, BaseMessage
from langchain_openai import ChatOpenAI
from langgraph.graph import StateGraph
from langgraph.graph.message import add_messages
from langgraph.graph.ui import AnyUIMessage, ui_message_reducer, push_ui_messageclass AgentState(TypedDict):  # noqa: D101
    messages: Annotated[Sequence[BaseMessage], add_messages]ui: Annotated[Sequence[AnyUIMessage], ui_message_reducer]async def weather(state: AgentState):class WeatherOutput(TypedDict):city: strweather: WeatherOutput = (await ChatOpenAI(model="gpt-4o-mini").with_structured_output(WeatherOutput).with_config({"tags": ["nostream"]}).ainvoke(state["messages"]))message = AIMessage(id=str(uuid.uuid4()),content=f"Here's the weather for {weather['city']}",)# Emit UI elements associated with the messagepush_ui_message("weather", weather, message=message)return {"messages": [message]}workflow = StateGraph(AgentState)
workflow.add_node(weather)
workflow.add_edge("__start__", "weather")
graph = workflow.compile()

 

 


 

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

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

相关文章

外国网站邀请做编辑广州做网站找酷爱网络

开源项目专题系列(八)1.开源项目名称:magpie_fly2.github地址:https://github.com/wuba/magpie_fly3.简介:magpie_fly 是58集体出品组件库,统一管理日常开发中的基础组件及高阶组件,并提供了相对友好的方式介绍组件的具…

中国住房和城乡建设厅网站美食教做网站

过了面试,后面的在线测评还会刷人吗?完全有可能刷,如果不是为了刷,何必要给你做线上测评,我说的有道理不? 好吧,说到为什么在线测评要刷人,怎么刷? 怎么才能确保不被刷&…

web服务器配置步骤有哪些?如何建立一个web服务器

建立一个 Web 服务器 并配置它,是托管网站、应用程序或服务的基础任务。以下是完整的 Web 服务器配置步骤,涵盖从准备服务器到部署网站的流程,包括选择技术栈、安装软件、配置安全性和优化性能。1. 准备工作 1.1 选…

题解:P10005 [集训队互测 2023] 基础寄术练习题

好牛的计数题。 题意:很简单了,不再赘述。 做法: 首先看到这个前缀和的乘积的倒数太难算了,一般来说肯定是考虑拆成 \(a\) 怎么样算一下,经过一定的手玩以后会发现 \(\sum\prod\limits_{i}\frac{1}{s_i}=\prod\fr…

详细介绍:Linux----gcc、g++的使用以及一些问题

详细介绍:Linux----gcc、g++的使用以及一些问题pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", …

网页和网站有什么关系网络建设与维护是什么

工厂模式用于干掉大量的if-else ,策略模式用于挪去臃肿的业务代码,还可以进一步升级加上模板模式,以及抽取成Starter public interface HandlerStrategy extends InitializingBean {void findSyncOrders(); }public class SalesPlatformFact…

网站logo怎么设计哪个网站可以做立体字的模板

文章目录1. 题目2. 解题1. 题目 设计一个支持下述操作的食物评分系统: 修改 系统中列出的某种食物的评分。返回系统中某一类烹饪方式下评分最高的食物。 实现 FoodRatings 类: FoodRatings(String[] foods, String[] cuisines, int[] ratings) 初始化…

电子商务网站开发常用工具建筑资料管理规程

最近很多朋友(Andrew、BENEN1)都在问如何让Lookup显示InActive记录,研究后发现可以通过Plugin来实现这样的功能,MSCRM真是无所不能,没有做不到,只有想不到!实现步骤:一、自定义实体->工程项目->表单和视图->查找视图->…

网站制作有哪些技术外贸电商网站建设

RPC和WebService的关系RPC(Remote Procedure Call)— 远程过程调用,是一个很大的概念, 它是一种通过网络从远程计算机程序上跨语言跨平台的请求服务,rpc能省略部分接口代码的开发,可以跨机器之间访问对象(java rmi),可以有更方便的…

学院网站建设时间控制变更申请表北京软件开发公司排行榜最新

在Spring Cloud Gateway中,GlobalFilter接口允许你创建全局过滤器,这意味着该过滤器会应用到所有的路由上,无论它们是否匹配特定的路由规则。Ordered接口用于定义过滤器的执行顺序。 以下是一个AuthFilter类的示例,该类实现了Glo…

同步和互斥的基本概念

同步与互斥的基本概念 临界资源 我们将一次仅允许一个进程使用的资源称为临界资源 什么是进程同步 直接制约关系,他是指为了完成某种任务而建立的两个或多个进程,这些进程因为需要某些位置上协调他们的工作次序而产生…

Sep 28

只整理 T1, T2. 原题是 「ROI 2012 Day 1」密码 和 「ROI 2012 Day 2」剧院始于演员,可以与 LOJ 提交。 T1 考试的时候忘记 return 0, 导致一口气把所有答案都输出出来了,100->30,再次警示使用 break 的时候一定…

图像采集卡:连接镜头与机器的“视觉神经”,释放工业智能核心动力

什么是图像采集卡? 身处机器视觉、智能制造、医疗影像等行业前沿的你,是否常听到“图像采集卡”这个词?它绝非简单的配件,而是现代工业应用中的关键“视觉神经”。简单来说,图像采集卡(又称视频采集卡或帧抓取器…

2025 年生态木厂商最新推荐榜单:TOP 前五企业实力解析及厂商选择指南生态木方通/户外地板/装饰线条/隔断/背景墙厂商推荐

在环保装饰材料需求持续攀升的当下,生态木(WPC)凭借环保、耐用等优势,成为家装与工装领域的热门选择,但市场乱象却让采购方陷入困境。一方面,大量中小品牌缺乏核心技术,产品在防水、防火、环保性上不达标,且同…

盲盒一番赏小应用用户需求分析:从行为动机到功能诉求的深度拆解

盲盒一番赏小应用用户需求分析:从行为动机到功能诉求的深度拆解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "C…

C++ IO 库全方位解析:从基础到实战 - 指南

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

解题报告-泥路(muddyroad.*)

泥路(muddyroad.*) 题目背景 yxr 热爱多级跳,而且他十分喜欢在泥路上练习多级跳。 不幸的是,有一天下雨了,yxr 穿着的却是一双新的鞋子。yxr 心疼自己的鞋子,但是又不舍得放弃练习多级跳,于是他决定先勘察泥路。 …

洛谷P10112 [GESP202312 八级] 奖品分配

传送门 原题 题目描述 班上有 \(N\) 名同学,学号从 \(0\) 到 \(N-1\)。有 \(M\) 种奖品要分给这些同学,其中,第 \(i\) 种奖品总共有 \(a_i\) 个 (\(i=0,1, \cdots ,M-1\))。 巧合的是,奖品的数量不多不少,每位同…

P10400 『STA - R5』消失的计算机

传送门 原题 题目描述 本题为提交答案题。 后台有一个正整数 \(n\)(你不知道 \(n\) 具体的值)。 你有 \(10^3\) 个变量 \(p_1,p_2,\cdots,p_{10^3}\),初始 \(p_1=n\),\(p_2=p_3=\cdots=p_{10^3}=0\)。 你需要写一个…

2025 地坪研磨机厂家推荐权威推荐排行榜:品牌深度解析及格力 / 宁德时代合作案例速递水磨石/遥控式/座驾式/小型地坪研磨机厂家推荐

伴随城市更新与智能制造升级,环氧地坪、固化混凝土等工程对研磨设备的精度、效率与稳定性提出严苛要求,地坪研磨机市场需求年均复合增长率达 3.5%。但市场中产品质量悬殊,动力不足、精度偏差、售后滞后等问题频发,…