langgraph---条件边

(1)使用langgrahp.rpebuilt中的tools_condition

复制代码
from langgraph.prebuilt import tools_condition

builder.add_conditional_edges('llm节点',tools_condition)

(2)自定义 条件边

复制代码
#(1)自定义路由函数
def rout_func(state:State):

    if hasattr(state,'messages'):
        messages = state.messages
    elif isinstance(state,dict) and 'messages' in state:
        messages = state.get('messages', [])
    else:
        raise ValueError(f"无法从状态中获取到messages:{state}")

    last_message = messages[-1]

    if hasattr(last_message,'tool_calls') and len(last_message.tool_calls)>0:
        return 'tools'

#(2)条件边
builder.add_conditional_edges(
    'llm节点',
    rout_func,
    path_map={
        'tools':'tools',
        END:END
    }
)
相关推荐
qq_22589174664 分钟前
基于Flask的空气质量监测与预测分析系统
开发语言·后端·python·信息可视化·django·flask
恋猫de小郭11 分钟前
社区版 Dart macros?一个可以解决 JSON 序列化的Fluter “宏编程”第三方包
android·前端·flutter
lhldsg18 分钟前
社区健身系统开发实战:从需求分析到落地部署全流程指南
java·开发语言·小程序·需求分析
李高钢19 分钟前
C# WPF Prism 进阶(三):导航(Navigation)深入
开发语言·c#·wpf
冯汉栩20 分钟前
Swift Control DashLineView(虚线)
开发语言·ios·swift
覆东流26 分钟前
4.Java运算符与表达式
java·开发语言·后端
2601_965798471 小时前
Contractor Web Setup: Deploying Bathrooms & Kitchens Theme Fast
前端·web3·php·wordpress
Dxy12393102161 小时前
Python XPath position() 完整使用指南,避坑合集(lxml适用)
前端·javascript·python
SomeB1oody1 小时前
【RustyML入门】5.1. 回归指标
开发语言·后端·机器学习·rust·教程
名字还没想好☜1 小时前
React 19 useOptimistic 实战:点赞评论先更新 UI,失败自动回滚
前端·javascript·react.js·ui·react·useoptimistic