import{s as it,f as pt,o as ct,n as mt}from"../chunks/scheduler.889ebb13.js";import{S as ot,i as wt,g as e,s as n,r as p,A as It,h as U,f as t,c as M,j as Tt,u as T,x as J,k as b,y as Ct,a,v as j,d as y,t as i,w as c,m as jt,n as yt}from"../chunks/index.ca18042b.js";import{T as ut}from"../chunks/Tip.b8116e3c.js";import{C}from"../chunks/CodeBlock.a65374d4.js";import{H as I,E as ht}from"../chunks/index.544c5610.js";function rt(Ql){let o,w,h="这个 notebook",u;return{c(){o=jt("你可以在 "),w=e("a"),w.textContent=h,u=jt(" 中查看完整代码，并通过 Google Colab 运行。"),this.h()},l(m){o=yt(m,"你可以在 "),w=U(m,"A",{href:!0,target:!0,"data-svelte-h":!0}),J(w)!=="svelte-38evbg"&&(w.textContent=h),u=yt(m," 中查看完整代码，并通过 Google Colab 运行。"),this.h()},h(){b(w,"href","https://huggingface.co/agents-course/notebooks/resolve/main/unit2/langgraph/mail_sorting.ipynb"),b(w,"target","_blank")},m(m,r){a(m,o,r),a(m,w,r),a(m,u,r)},p:mt,d(m){m&&(t(o),t(w),t(u))}}}function gt(Ql){let o,w,h,u,m,r,B,As="现在我们已经理解了基本构建模块，让我们通过构建第一个功能图来实践。我们将实现 Alfred 的邮件处理系统，他需要：",dl,V,Es="<li>阅读 incoming emails</li> <li>将其分类为 spam 或 legitimate</li> <li>为 legitimate 邮件起草初步响应</li> <li>当邮件合法时向 Mr. Wayne 发送信息（仅打印）</li>",fl,Q,Ss="这个示例演示了如何使用 LangGraph 构建涉及基于 LLM 决策的工作流程结构。虽然这不能算是真正的 Agent（因为没有涉及工具），但本节更侧重于学习 LangGraph 框架而非 Agents。",Nl,g,Al,d,El,f,Zs="这是我们将要构建的工作流程：",Sl,N,Fs,Zl,A,Fl,E,Rs="首先安装必要的包：",Rl,S,Wl,Z,Ws="接下来，让我们导入必要的模块：",Gl,F,ql,R,kl,W,Gs="让我们定义 Alfred 在电子邮件处理工作流程中需要跟踪哪些信息：",Yl,G,$l,q,qs="<p>💡 <strong>提示：</strong>让您的状态足够全面，以跟踪所有重要信息，但避免用不必要的细节使其变得臃肿。</p>",_l,k,Xl,Y,ks="现在，让我们创建将形成我们节点的处理函数：",zl,$,vl,_,xl,X,Ys="我们需要一个函数来确定分类后要采取哪条路径：",Ol,z,Hl,v,$s="<p>💡 <strong>注意：</strong> LangGraph 调用此路由函数来确定在分类节点之后要跟随哪条边。返回值必须与我们的条件边映射中的一个键匹配。</p>",Ll,x,Dl,O,_s="现在我们将所有内容连接在一起：",Kl,H,Pl,L,Xs="注意我们如何使用 LangGraph 提供的特殊“END”节点。这表示工作流完成的终端状态。",ls,D,ss,K,zs="让我们用一封合法的电子邮件和一封垃圾邮件来测试我们的图表：",ts,P,as,ll,ns,sl,vs="随着 Alfred 对主分类智能体进行微调，他越来越厌倦调试其运行。智能体本质上是不可预测的，难以检查。但由于他的目标是构建终极垃圾邮件检测智能体并将其部署到生产中，因此他需要强大的可追溯性以供将来监控和分析。",Ms,tl,xs='为此，Alfred 可以使用可观察性工具（例如 <a href="https://langfuse.com/" rel="nofollow">Langfuse</a>）来跟踪和监控智能体。',es,al,Os="首先，我们 pip install Langfuse：",Us,nl,Js,Ml,Hs='接下来，我们将 Langfuse API 密钥和主机地址添加为环境变量。您可以通过注册 <a href="https://cloud.langfuse.com" rel="nofollow">Langfuse Cloud</a> 或 <a href="https://langfuse.com/self-hosting" rel="nofollow">self-host Langfuse</a> 获取 Langfuse 凭据。',ps,el,Ts,Ul,Ls='然后，我们配置 <a href="https://langfuse.com/docs/integrations/langchain/tracing#add-langfuse-to-your-langchain-application" rel="nofollow">Langfuse <code>callback_handler</code></a>，并通过将 <code>langfuse_callback</code> 添加到图的调用来检测智能体：<code>config={&quot;callbacks&quot;: [langfuse_handler]}</code>。',js,Jl,ys,pl,Ds="Alfred 现已连接 🔌！LangGraph 的运行记录在 Langfuse 中，使他能够全面了解智能体的行为。通过此设置，他可以重新查看之前的运行并进一步完善他的邮件分类智能体。",is,Tl,Ks='<img src="https://langfuse.com/images/cookbook/huggingface-agent-course/langgraph-trace-legit.png" alt="Langfuse 中的示例跟踪"/>',cs,jl,Ps='<em><a href="https://cloud.langfuse.com/project/cloramnkj0002jz088vzn1ja4/traces/f5d6d72e-20af-4357-b232-af44c3728a7b?timestamp=2025-03-17T10%3A13%3A28.413Z&amp;observation=6997ba69-043f-4f77-9445-700a033afba1" rel="nofollow">带有合法电子邮件的跟踪的公共链接</a></em>',ms,yl,os,il,lt="LangGraph 允许我们可视化我们的工作流程，以便更好地理解和调试其结构：",ws,cl,Is,ml,st,Cs,ol,tt="这会产生一个可视化表示，显示我们的节点如何连接以及可以采取的条件路径。",us,wl,hs,Il,at="我们创建了一个完整的电子邮件处理工作流程：",rs,Cl,nt="<li>接收传入的电子邮件</li> <li>使用 LLM 将其分类为垃圾邮件或合法邮件</li> <li>通过丢弃垃圾邮件来处理垃圾邮件</li> <li>对于合法电子邮件，起草回复并通知 Mr. Hugg</li>",gs,ul,Mt="这展示了 LangGraph 使用 LLM 编排复杂工作流程同时保持清晰、结构化流程的强大功能。",bs,hl,Bs,rl,et="<li><strong>状态管理</strong>：我们定义了全面的状态来跟踪电子邮件处理的所有方面</li> <li><strong>节点实现</strong>：我们创建了与 LLM 交互的功能节点</li> <li><strong>条件路由</strong>：我们根据电子邮件分类实现了分支逻辑</li> <li><strong>终端状态</strong>：我们使用 END 节点标记工作流程中的完成点</li>",Vs,gl,Qs,bl,Ut="在下一部分中，我们将探索 LangGraph 的更多高级功能，包括处理工作流中的人机交互以及根据多种条件实现更复杂的分支逻辑。",ds,Bl,fs,Vl,Ns;return m=new I({props:{title:"构建你的第一个 LangGraph",local:"构建你的第一个-langgraph",headingTag:"h1"}}),g=new ut({props:{$$slots:{default:[rt]},$$scope:{ctx:Ql}}}),d=new I({props:{title:"工作流程",local:"工作流程",headingTag:"h2"}}),A=new I({props:{title:"环境设置",local:"环境设置",headingTag:"h2"}}),S=new C({props:{code:"JTI1cGlwJTIwaW5zdGFsbCUyMGxhbmdncmFwaCUyMGxhbmdjaGFpbl9vcGVuYWk=",highlighted:"%pip install langgraph langchain_openai",wrap:!1}}),F=new C({props:{code:"aW1wb3J0JTIwb3MlMEFmcm9tJTIwdHlwaW5nJTIwaW1wb3J0JTIwVHlwZWREaWN0JTJDJTIwTGlzdCUyQyUyMERpY3QlMkMlMjBBbnklMkMlMjBPcHRpb25hbCUwQWZyb20lMjBsYW5nZ3JhcGguZ3JhcGglMjBpbXBvcnQlMjBTdGF0ZUdyYXBoJTJDJTIwRU5EJTBBZnJvbSUyMGxhbmdjaGFpbl9vcGVuYWklMjBpbXBvcnQlMjBDaGF0T3BlbkFJJTBBZnJvbSUyMGxhbmdjaGFpbl9jb3JlLm1lc3NhZ2VzJTIwaW1wb3J0JTIwSHVtYW5NZXNzYWdlJTJDJTIwQUlNZXNzYWdl",highlighted:`<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> TypedDict, <span class="hljs-type">List</span>, <span class="hljs-type">Dict</span>, <span class="hljs-type">Any</span>, <span class="hljs-type">Optional</span>
<span class="hljs-keyword">from</span> langgraph.graph <span class="hljs-keyword">import</span> StateGraph, END
<span class="hljs-keyword">from</span> langchain_openai <span class="hljs-keyword">import</span> ChatOpenAI
<span class="hljs-keyword">from</span> langchain_core.messages <span class="hljs-keyword">import</span> HumanMessage, AIMessage`,wrap:!1}}),R=new I({props:{title:"步骤 1：定义我们的状态",local:"步骤-1定义我们的状态",headingTag:"h2"}}),G=new C({props:{code:"Y2xhc3MlMjBFbWFpbFN0YXRlKFR5cGVkRGljdCklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjAlRTYlQUQlQTMlRTUlOUMlQTglRTUlQTQlODQlRTclOTAlODYlRTclOUElODQlRTclOTQlQjUlRTUlQUQlOTAlRTklODIlQUUlRTQlQkIlQjYlMEElMjAlMjAlMjAlMjBlbWFpbCUzQSUyMERpY3QlNUJzdHIlMkMlMjBBbnklNUQlMjAlMjAlMjMlMjAlRTUlOEMlODUlRTUlOTAlQUIlRTQlQjglQkIlRTklQTIlOTglRTMlODAlODElRTUlOEYlOTElRTQlQkIlQjYlRTQlQkElQkElRTMlODAlODElRTYlQUQlQTMlRTYlOTYlODclRTclQUQlODklRTMlODAlODIlMEElMjAlMjAlMjAlMjAlMEElMjAlMjAlMjAlMjAlMjMlMjAlRTUlODglODYlRTYlOUUlOTAlRTQlQjglOEUlRTUlODYlQjMlRTclQUQlOTYlMEElMjAlMjAlMjAlMjBpc19zcGFtJTNBJTIwT3B0aW9uYWwlNUJib29sJTVEJTBBJTIwJTIwJTIwJTIwJTBBJTIwJTIwJTIwJTIwJTIzJTIwJUU1JTkzJThEJUU1JUJBJTk0JUU3JTk0JTlGJUU2JTg4JTkwJTBBJTIwJTIwJTIwJTIwZHJhZnRfcmVzcG9uc2UlM0ElMjBPcHRpb25hbCU1QnN0ciU1RCUwQSUyMCUyMCUyMCUyMCUwQSUyMCUyMCUyMCUyMCUyMyUyMCVFNSVBNCU4NCVFNyU5MCU4NiVFNSU4NSU4MyVFNiU5NSVCMCVFNiU4RCVBRSUwQSUyMCUyMCUyMCUyMG1lc3NhZ2VzJTNBJTIwTGlzdCU1QkRpY3QlNUJzdHIlMkMlMjBBbnklNUQlNUQlMjAlMjAlMjMlMjAlRTglQjclOUYlRTglQjglQUElRTQlQjglOEUlMjBMTE0lMjAlRTclOUElODQlRTUlQUYlQjklRTglQUYlOUQlRTQlQkIlQTUlRTglQkYlOUIlRTglQTElOEMlRTUlODglODYlRTYlOUUlOTA=",highlighted:`<span class="hljs-keyword">class</span> <span class="hljs-title class_">EmailState</span>(<span class="hljs-title class_ inherited__">TypedDict</span>):
    <span class="hljs-comment"># 正在处理的电子邮件</span>
    email: <span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Any</span>]  <span class="hljs-comment"># 包含主题、发件人、正文等。</span>
    
    <span class="hljs-comment"># 分析与决策</span>
    is_spam: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">bool</span>]
    
    <span class="hljs-comment"># 响应生成</span>
    draft_response: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">str</span>]
    
    <span class="hljs-comment"># 处理元数据</span>
    messages: <span class="hljs-type">List</span>[<span class="hljs-type">Dict</span>[<span class="hljs-built_in">str</span>, <span class="hljs-type">Any</span>]]  <span class="hljs-comment"># 跟踪与 LLM 的对话以进行分析</span>`,wrap:!1}}),k=new I({props:{title:"第 2 步：定义我们的节点",local:"第-2-步定义我们的节点",headingTag:"h2"}}),$=new C({props:{code:" ",highlighted:`<span class="hljs-comment"># Initialize our LLM</span>
model = ChatOpenAI(temperature=<span class="hljs-number">0</span>)

<span class="hljs-keyword">def</span> <span class="hljs-title function_">read_email</span>(<span class="hljs-params">state: EmailState</span>):
    <span class="hljs-string">&quot;&quot;&quot;Alfred reads and logs the incoming email&quot;&quot;&quot;</span>
    email = state[<span class="hljs-string">&quot;email&quot;</span>]
    
    <span class="hljs-comment"># 在这里我们可能会做一些初步的预处理</span>
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Alfred is processing an email from <span class="hljs-subst">{email[<span class="hljs-string">&#x27;sender&#x27;</span>]}</span> with subject: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;subject&#x27;</span>]}</span>&quot;</span>)
    
    <span class="hljs-comment"># 这里不需要更改状态</span>
    <span class="hljs-keyword">return</span> {}

<span class="hljs-keyword">def</span> <span class="hljs-title function_">classify_email</span>(<span class="hljs-params">state: EmailState</span>):
    <span class="hljs-string">&quot;&quot;&quot;Alfred uses an LLM to determine if the email is spam or legitimate&quot;&quot;&quot;</span>
    email = state[<span class="hljs-string">&quot;email&quot;</span>]
    
    <span class="hljs-comment"># 为 LLM 准备提示</span>
    prompt = <span class="hljs-string">f&quot;&quot;&quot;
    As Alfred the butler, analyze this email and determine if it is spam or legitimate.
    
    Email:
    From: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;sender&#x27;</span>]}</span>
    Subject: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;subject&#x27;</span>]}</span>
    Body: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;body&#x27;</span>]}</span>
    
    First, determine if this email is spam. If it is spam, explain why.
    If it is legitimate, categorize it (inquiry, complaint, thank you, etc.).
    &quot;&quot;&quot;</span>
    
    <span class="hljs-comment"># Call the LLM</span>
    messages = [HumanMessage(content=prompt)]
    response = model.invoke(messages)
    
    <span class="hljs-comment"># 解析响应的简单逻辑（在实际应用中，您需要更强大的解析）</span>
    response_text = response.content.lower()
    is_spam = <span class="hljs-string">&quot;spam&quot;</span> <span class="hljs-keyword">in</span> response_text <span class="hljs-keyword">and</span> <span class="hljs-string">&quot;not spam&quot;</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> response_text
    
    <span class="hljs-comment"># 如果是垃圾邮件，请提取原因</span>
    spam_reason = <span class="hljs-literal">None</span>
    <span class="hljs-keyword">if</span> is_spam <span class="hljs-keyword">and</span> <span class="hljs-string">&quot;reason:&quot;</span> <span class="hljs-keyword">in</span> response_text:
        spam_reason = response_text.split(<span class="hljs-string">&quot;reason:&quot;</span>)[<span class="hljs-number">1</span>].strip()
    
    <span class="hljs-comment"># 确定类别是否合法</span>
    email_category = <span class="hljs-literal">None</span>
    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> is_spam:
        categories = [<span class="hljs-string">&quot;inquiry&quot;</span>, <span class="hljs-string">&quot;complaint&quot;</span>, <span class="hljs-string">&quot;thank you&quot;</span>, <span class="hljs-string">&quot;request&quot;</span>, <span class="hljs-string">&quot;information&quot;</span>]
        <span class="hljs-keyword">for</span> category <span class="hljs-keyword">in</span> categories:
            <span class="hljs-keyword">if</span> category <span class="hljs-keyword">in</span> response_text:
                email_category = category
                <span class="hljs-keyword">break</span>
    
    <span class="hljs-comment"># 更新消息以进行追踪</span>
    new_messages = state.get(<span class="hljs-string">&quot;messages&quot;</span>, []) + [
        {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: prompt},
        {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;assistant&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: response.content}
    ]
    
    <span class="hljs-comment"># 返回状态更新</span>
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;is_spam&quot;</span>: is_spam,
        <span class="hljs-string">&quot;spam_reason&quot;</span>: spam_reason,
        <span class="hljs-string">&quot;email_category&quot;</span>: email_category,
        <span class="hljs-string">&quot;messages&quot;</span>: new_messages
    }

<span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_spam</span>(<span class="hljs-params">state: EmailState</span>):
    <span class="hljs-string">&quot;&quot;&quot;Alfred discards spam email with a note&quot;&quot;&quot;</span>
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Alfred has marked the email as spam. Reason: <span class="hljs-subst">{state[<span class="hljs-string">&#x27;spam_reason&#x27;</span>]}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;The email has been moved to the spam folder.&quot;</span>)
    
    <span class="hljs-comment"># 我们已处理完这封电子邮件</span>
    <span class="hljs-keyword">return</span> {}

<span class="hljs-keyword">def</span> <span class="hljs-title function_">draft_response</span>(<span class="hljs-params">state: EmailState</span>):
    <span class="hljs-string">&quot;&quot;&quot;Alfred drafts a preliminary response for legitimate emails&quot;&quot;&quot;</span>
    email = state[<span class="hljs-string">&quot;email&quot;</span>]
    category = state[<span class="hljs-string">&quot;email_category&quot;</span>] <span class="hljs-keyword">or</span> <span class="hljs-string">&quot;general&quot;</span>
    
    <span class="hljs-comment"># 为 LLM 准备提示词</span>
    prompt = <span class="hljs-string">f&quot;&quot;&quot;
    As Alfred the butler, draft a polite preliminary response to this email.
    
    Email:
    From: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;sender&#x27;</span>]}</span>
    Subject: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;subject&#x27;</span>]}</span>
    Body: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;body&#x27;</span>]}</span>
    
    This email has been categorized as: <span class="hljs-subst">{category}</span>
    
    Draft a brief, professional response that Mr. Hugg can review and personalize before sending.
    &quot;&quot;&quot;</span>
    
    <span class="hljs-comment"># Call the LLM</span>
    messages = [HumanMessage(content=prompt)]
    response = model.invoke(messages)
    
    <span class="hljs-comment"># 更新消息以进行追踪</span>
    new_messages = state.get(<span class="hljs-string">&quot;messages&quot;</span>, []) + [
        {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;user&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: prompt},
        {<span class="hljs-string">&quot;role&quot;</span>: <span class="hljs-string">&quot;assistant&quot;</span>, <span class="hljs-string">&quot;content&quot;</span>: response.content}
    ]
    
    <span class="hljs-comment"># 返回状态更新</span>
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;draft_response&quot;</span>: response.content,
        <span class="hljs-string">&quot;messages&quot;</span>: new_messages
    }

<span class="hljs-keyword">def</span> <span class="hljs-title function_">notify_mr_hugg</span>(<span class="hljs-params">state: EmailState</span>):
    <span class="hljs-string">&quot;&quot;&quot;Alfred notifies Mr. Hugg about the email and presents the draft response&quot;&quot;&quot;</span>
    email = state[<span class="hljs-string">&quot;email&quot;</span>]
    
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;\\n&quot;</span> + <span class="hljs-string">&quot;=&quot;</span>*<span class="hljs-number">50</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Sir, you&#x27;ve received an email from <span class="hljs-subst">{email[<span class="hljs-string">&#x27;sender&#x27;</span>]}</span>.&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Subject: <span class="hljs-subst">{email[<span class="hljs-string">&#x27;subject&#x27;</span>]}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Category: <span class="hljs-subst">{state[<span class="hljs-string">&#x27;email_category&#x27;</span>]}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;\\nI&#x27;ve prepared a draft response for your review:&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-&quot;</span>*<span class="hljs-number">50</span>)
    <span class="hljs-built_in">print</span>(state[<span class="hljs-string">&quot;draft_response&quot;</span>])
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=&quot;</span>*<span class="hljs-number">50</span> + <span class="hljs-string">&quot;\\n&quot;</span>)
    
    <span class="hljs-comment"># 我们已处理完这封电子邮件</span>
    <span class="hljs-keyword">return</span> {}`,wrap:!1}}),_=new I({props:{title:"步骤 3：定义我们的路由逻辑",local:"步骤-3定义我们的路由逻辑",headingTag:"h2"}}),z=new C({props:{code:"ZGVmJTIwcm91dGVfZW1haWwoc3RhdGUlM0ElMjBFbWFpbFN0YXRlKSUyMC0lM0UlMjBzdHIlM0ElMEElMjAlMjAlMjAlMjAlMjIlMjIlMjJEZXRlcm1pbmUlMjB0aGUlMjBuZXh0JTIwc3RlcCUyMGJhc2VkJTIwb24lMjBzcGFtJTIwY2xhc3NpZmljYXRpb24lMjIlMjIlMjIlMEElMjAlMjAlMjAlMjBpZiUyMHN0YXRlJTVCJTIyaXNfc3BhbSUyMiU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMCUyMnNwYW0lMjIlMEElMjAlMjAlMjAlMjBlbHNlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTIybGVnaXRpbWF0ZSUyMg==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">route_email</span>(<span class="hljs-params">state: EmailState</span>) -&gt; <span class="hljs-built_in">str</span>:
    <span class="hljs-string">&quot;&quot;&quot;Determine the next step based on spam classification&quot;&quot;&quot;</span>
    <span class="hljs-keyword">if</span> state[<span class="hljs-string">&quot;is_spam&quot;</span>]:
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;spam&quot;</span>
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;legitimate&quot;</span>`,wrap:!1}}),x=new I({props:{title:"步骤 4：创建 StateGraph 并定义边",local:"步骤-4创建-stategraph-并定义边",headingTag:"h2"}}),H=new C({props:{code:"JTIzJTIwJUU1JTg4JTlCJUU1JUJCJUJBJTIwZ3JhcGglMEFlbWFpbF9ncmFwaCUyMCUzRCUyMFN0YXRlR3JhcGgoRW1haWxTdGF0ZSklMEElMEElMjMlMjAlRTYlQjclQkIlRTUlOEElQTAlMjBub2RlcyUwQWVtYWlsX2dyYXBoLmFkZF9ub2RlKCUyMnJlYWRfZW1haWwlMjIlMkMlMjByZWFkX2VtYWlsKSUwQWVtYWlsX2dyYXBoLmFkZF9ub2RlKCUyMmNsYXNzaWZ5X2VtYWlsJTIyJTJDJTIwY2xhc3NpZnlfZW1haWwpJTBBZW1haWxfZ3JhcGguYWRkX25vZGUoJTIyaGFuZGxlX3NwYW0lMjIlMkMlMjBoYW5kbGVfc3BhbSklMEFlbWFpbF9ncmFwaC5hZGRfbm9kZSglMjJkcmFmdF9yZXNwb25zZSUyMiUyQyUyMGRyYWZ0X3Jlc3BvbnNlKSUwQWVtYWlsX2dyYXBoLmFkZF9ub2RlKCUyMm5vdGlmeV9tcl9odWdnJTIyJTJDJTIwbm90aWZ5X21yX2h1Z2cpJTBBJTBBJTIzJTIwJUU2JUI3JUJCJUU1JThBJUEwJTIwZWRnZXMlMjAtJTIwJUU1JUFFJTlBJUU0JUI5JTg5JUU2JUI1JTgxJUU3JUE4JThCJTBBZW1haWxfZ3JhcGguYWRkX2VkZ2UoJTIycmVhZF9lbWFpbCUyMiUyQyUyMCUyMmNsYXNzaWZ5X2VtYWlsJTIyKSUwQSUwQSUyMyUyMCVFNCVCQiU4RSUyMGNsYXNzaWZ5X2VtYWlsJTIwJUU2JUI3JUJCJUU1JThBJUEwJUU2JTlEJUExJUU0JUJCJUI2JUU1JTg4JTg2JUU2JTk0JUFGJTBBZW1haWxfZ3JhcGguYWRkX2NvbmRpdGlvbmFsX2VkZ2VzKCUwQSUyMCUyMCUyMCUyMCUyMmNsYXNzaWZ5X2VtYWlsJTIyJTJDJTBBJTIwJTIwJTIwJTIwcm91dGVfZW1haWwlMkMlMEElMjAlMjAlMjAlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJzcGFtJTIyJTNBJTIwJTIyaGFuZGxlX3NwYW0lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJsZWdpdGltYXRlJTIyJTNBJTIwJTIyZHJhZnRfcmVzcG9uc2UlMjIlMEElMjAlMjAlMjAlMjAlN0QlMEEpJTBBJTBBJTIzJTIwJUU2JUI3JUJCJUU1JThBJUEwJUU2JTlDJTgwJUU1JTkwJThFJUU3JTlBJTg0JTIwZWRnZXMlMEFlbWFpbF9ncmFwaC5hZGRfZWRnZSglMjJoYW5kbGVfc3BhbSUyMiUyQyUyMEVORCklMEFlbWFpbF9ncmFwaC5hZGRfZWRnZSglMjJkcmFmdF9yZXNwb25zZSUyMiUyQyUyMCUyMm5vdGlmeV9tcl9odWdnJTIyKSUwQWVtYWlsX2dyYXBoLmFkZF9lZGdlKCUyMm5vdGlmeV9tcl9odWdnJTIyJTJDJTIwRU5EKSUwQSUwQSUyMyUyMCVFNyVCQyU5NiVFOCVBRiU5MSUyMGdyYXBoJTBBY29tcGlsZWRfZ3JhcGglMjAlM0QlMjBlbWFpbF9ncmFwaC5jb21waWxlKCk=",highlighted:`<span class="hljs-comment"># 创建 graph</span>
email_graph = StateGraph(EmailState)

<span class="hljs-comment"># 添加 nodes</span>
email_graph.add_node(<span class="hljs-string">&quot;read_email&quot;</span>, read_email)
email_graph.add_node(<span class="hljs-string">&quot;classify_email&quot;</span>, classify_email)
email_graph.add_node(<span class="hljs-string">&quot;handle_spam&quot;</span>, handle_spam)
email_graph.add_node(<span class="hljs-string">&quot;draft_response&quot;</span>, draft_response)
email_graph.add_node(<span class="hljs-string">&quot;notify_mr_hugg&quot;</span>, notify_mr_hugg)

<span class="hljs-comment"># 添加 edges - 定义流程</span>
email_graph.add_edge(<span class="hljs-string">&quot;read_email&quot;</span>, <span class="hljs-string">&quot;classify_email&quot;</span>)

<span class="hljs-comment"># 从 classify_email 添加条件分支</span>
email_graph.add_conditional_edges(
    <span class="hljs-string">&quot;classify_email&quot;</span>,
    route_email,
    {
        <span class="hljs-string">&quot;spam&quot;</span>: <span class="hljs-string">&quot;handle_spam&quot;</span>,
        <span class="hljs-string">&quot;legitimate&quot;</span>: <span class="hljs-string">&quot;draft_response&quot;</span>
    }
)

<span class="hljs-comment"># 添加最后的 edges</span>
email_graph.add_edge(<span class="hljs-string">&quot;handle_spam&quot;</span>, END)
email_graph.add_edge(<span class="hljs-string">&quot;draft_response&quot;</span>, <span class="hljs-string">&quot;notify_mr_hugg&quot;</span>)
email_graph.add_edge(<span class="hljs-string">&quot;notify_mr_hugg&quot;</span>, END)

<span class="hljs-comment"># 编译 graph</span>
compiled_graph = email_graph.<span class="hljs-built_in">compile</span>()`,wrap:!1}}),D=new I({props:{title:"步骤 5：运行应用程序",local:"步骤-5运行应用程序",headingTag:"h2"}}),P=new C({props:{code:"JTIzJTIwJUU1JTkwJTg4JUU2JUIzJTk1JUU3JTk0JUI1JUU1JUFEJTkwJUU5JTgyJUFFJUU0JUJCJUI2JUU3JUE0JUJBJUU0JUJFJThCJTBBbGVnaXRpbWF0ZV9lbWFpbCUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMnNlbmRlciUyMiUzQSUyMCUyMmpvaG4uc21pdGglNDBleGFtcGxlLmNvbSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMnN1YmplY3QlMjIlM0ElMjAlMjJRdWVzdGlvbiUyMGFib3V0JTIweW91ciUyMHNlcnZpY2VzJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyYm9keSUyMiUzQSUyMCUyMkRlYXIlMjBNci4lMjBIdWdnJTJDJTIwSSUyMHdhcyUyMHJlZmVycmVkJTIwdG8lMjB5b3UlMjBieSUyMGElMjBjb2xsZWFndWUlMjBhbmQlMjBJJ20lMjBpbnRlcmVzdGVkJTIwaW4lMjBsZWFybmluZyUyMG1vcmUlMjBhYm91dCUyMHlvdXIlMjBjb25zdWx0aW5nJTIwc2VydmljZXMuJTIwQ291bGQlMjB3ZSUyMHNjaGVkdWxlJTIwYSUyMGNhbGwlMjBuZXh0JTIwd2VlayUzRiUyMEJlc3QlMjByZWdhcmRzJTJDJTIwSm9obiUyMFNtaXRoJTIyJTBBJTdEJTBBJTBBJTIzJTIwJUU1JTlFJTgzJUU1JTlDJUJFJUU5JTgyJUFFJUU0JUJCJUI2JUU3JUE0JUJBJUU0JUJFJThCJTBBc3BhbV9lbWFpbCUyMCUzRCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMnNlbmRlciUyMiUzQSUyMCUyMndpbm5lciU0MGxvdHRlcnktaW50bC5jb20lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJzdWJqZWN0JTIyJTNBJTIwJTIyWU9VJTIwSEFWRSUyMFdPTiUyMCUyNDUlMkMwMDAlMkMwMDAhISElMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJib2R5JTIyJTNBJTIwJTIyQ09OR1JBVFVMQVRJT05TISUyMFlvdSUyMGhhdmUlMjBiZWVuJTIwc2VsZWN0ZWQlMjBhcyUyMHRoZSUyMHdpbm5lciUyMG9mJTIwb3VyJTIwaW50ZXJuYXRpb25hbCUyMGxvdHRlcnkhJTIwVG8lMjBjbGFpbSUyMHlvdXIlMjAlMjQ1JTJDMDAwJTJDMDAwJTIwcHJpemUlMkMlMjBwbGVhc2UlMjBzZW5kJTIwdXMlMjB5b3VyJTIwYmFuayUyMGRldGFpbHMlMjBhbmQlMjBhJTIwcHJvY2Vzc2luZyUyMGZlZSUyMG9mJTIwJTI0MTAwLiUyMiUwQSU3RCUwQSUwQSUyMyUyMCVFNSVBNCU4NCVFNyU5MCU4NiVFNSU5MCU4OCVFNiVCMyU5NSVFNyU5NCVCNSVFNSVBRCU5MCVFOSU4MiVBRSVFNCVCQiVCNiUwQXByaW50KCUyMiU1Q25Qcm9jZXNzaW5nJTIwbGVnaXRpbWF0ZSUyMGVtYWlsLi4uJTIyKSUwQWxlZ2l0aW1hdGVfcmVzdWx0JTIwJTNEJTIwY29tcGlsZWRfZ3JhcGguaW52b2tlKCU3QiUwQSUyMCUyMCUyMCUyMCUyMmVtYWlsJTIyJTNBJTIwbGVnaXRpbWF0ZV9lbWFpbCUyQyUwQSUyMCUyMCUyMCUyMCUyMmlzX3NwYW0lMjIlM0ElMjBOb25lJTJDJTBBJTIwJTIwJTIwJTIwJTIyc3BhbV9yZWFzb24lMjIlM0ElMjBOb25lJTJDJTBBJTIwJTIwJTIwJTIwJTIyZW1haWxfY2F0ZWdvcnklMjIlM0ElMjBOb25lJTJDJTBBJTIwJTIwJTIwJTIwJTIyZHJhZnRfcmVzcG9uc2UlMjIlM0ElMjBOb25lJTJDJTBBJTIwJTIwJTIwJTIwJTIybWVzc2FnZXMlMjIlM0ElMjAlNUIlNUQlMEElN0QpJTBBJTBBJTIzJTIwJUU1JUE0JTg0JUU3JTkwJTg2JUU1JTlFJTgzJUU1JTlDJUJFJUU5JTgyJUFFJUU0JUJCJUI2JTBBcHJpbnQoJTIyJTVDblByb2Nlc3NpbmclMjBzcGFtJTIwZW1haWwuLi4lMjIpJTBBc3BhbV9yZXN1bHQlMjAlM0QlMjBjb21waWxlZF9ncmFwaC5pbnZva2UoJTdCJTBBJTIwJTIwJTIwJTIwJTIyZW1haWwlMjIlM0ElMjBzcGFtX2VtYWlsJTJDJTBBJTIwJTIwJTIwJTIwJTIyaXNfc3BhbSUyMiUzQSUyME5vbmUlMkMlMEElMjAlMjAlMjAlMjAlMjJzcGFtX3JlYXNvbiUyMiUzQSUyME5vbmUlMkMlMEElMjAlMjAlMjAlMjAlMjJlbWFpbF9jYXRlZ29yeSUyMiUzQSUyME5vbmUlMkMlMEElMjAlMjAlMjAlMjAlMjJkcmFmdF9yZXNwb25zZSUyMiUzQSUyME5vbmUlMkMlMEElMjAlMjAlMjAlMjAlMjJtZXNzYWdlcyUyMiUzQSUyMCU1QiU1RCUwQSU3RCk=",highlighted:`<span class="hljs-comment"># 合法电子邮件示例</span>
legitimate_email = {
    <span class="hljs-string">&quot;sender&quot;</span>: <span class="hljs-string">&quot;john.smith@example.com&quot;</span>,
    <span class="hljs-string">&quot;subject&quot;</span>: <span class="hljs-string">&quot;Question about your services&quot;</span>,
    <span class="hljs-string">&quot;body&quot;</span>: <span class="hljs-string">&quot;Dear Mr. Hugg, I was referred to you by a colleague and I&#x27;m interested in learning more about your consulting services. Could we schedule a call next week? Best regards, John Smith&quot;</span>
}

<span class="hljs-comment"># 垃圾邮件示例</span>
spam_email = {
    <span class="hljs-string">&quot;sender&quot;</span>: <span class="hljs-string">&quot;winner@lottery-intl.com&quot;</span>,
    <span class="hljs-string">&quot;subject&quot;</span>: <span class="hljs-string">&quot;YOU HAVE WON $5,000,000!!!&quot;</span>,
    <span class="hljs-string">&quot;body&quot;</span>: <span class="hljs-string">&quot;CONGRATULATIONS! You have been selected as the winner of our international lottery! To claim your $5,000,000 prize, please send us your bank details and a processing fee of $100.&quot;</span>
}

<span class="hljs-comment"># 处理合法电子邮件</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;\\nProcessing legitimate email...&quot;</span>)
legitimate_result = compiled_graph.invoke({
    <span class="hljs-string">&quot;email&quot;</span>: legitimate_email,
    <span class="hljs-string">&quot;is_spam&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;spam_reason&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;email_category&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;draft_response&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;messages&quot;</span>: []
})

<span class="hljs-comment"># 处理垃圾邮件</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;\\nProcessing spam email...&quot;</span>)
spam_result = compiled_graph.invoke({
    <span class="hljs-string">&quot;email&quot;</span>: spam_email,
    <span class="hljs-string">&quot;is_spam&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;spam_reason&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;email_category&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;draft_response&quot;</span>: <span class="hljs-literal">None</span>,
    <span class="hljs-string">&quot;messages&quot;</span>: []
})`,wrap:!1}}),ll=new I({props:{title:"第 6 步：使用 Langfuse 检查我们的邮件分类智能体 📡",local:"第-6-步使用-langfuse-检查我们的邮件分类智能体-",headingTag:"h2"}}),nl=new C({props:{code:"JTI1cGlwJTIwaW5zdGFsbCUyMC1xJTIwbGFuZ2Z1c2U=",highlighted:"%pip install -q langfuse",wrap:!1}}),el=new C({props:{code:"aW1wb3J0JTIwb3MlMEElMjAlMEElMjMlMjBHZXQlMjBrZXlzJTIwZm9yJTIweW91ciUyMHByb2plY3QlMjBmcm9tJTIwdGhlJTIwcHJvamVjdCUyMHNldHRpbmdzJTIwcGFnZSUzQSUyMGh0dHBzJTNBJTJGJTJGY2xvdWQubGFuZ2Z1c2UuY29tJTBBb3MuZW52aXJvbiU1QiUyMkxBTkdGVVNFX1BVQkxJQ19LRVklMjIlNUQlMjAlM0QlMjAlMjJway1sZi0uLi4lMjIlMjAlMEFvcy5lbnZpcm9uJTVCJTIyTEFOR0ZVU0VfU0VDUkVUX0tFWSUyMiU1RCUyMCUzRCUyMCUyMnNrLWxmLS4uLiUyMiUwQW9zLmVudmlyb24lNUIlMjJMQU5HRlVTRV9IT1NUJTIyJTVEJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZjbG91ZC5sYW5nZnVzZS5jb20lMjIlMjAlMjMlMjAlRjAlOUYlODclQUElRjAlOUYlODclQkElMjBFVSUyMHJlZ2lvbiUwQSUyMyUyMG9zLmVudmlyb24lNUIlMjJMQU5HRlVTRV9IT1NUJTIyJTVEJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZ1cy5jbG91ZC5sYW5nZnVzZS5jb20lMjIlMjAlMjMlMjAlRjAlOUYlODclQkElRjAlOUYlODclQjglMjBVUyUyMHJlZ2lvbg==",highlighted:`<span class="hljs-keyword">import</span> os
 
<span class="hljs-comment"># Get keys for your project from the project settings page: https://cloud.langfuse.com</span>
os.environ[<span class="hljs-string">&quot;LANGFUSE_PUBLIC_KEY&quot;</span>] = <span class="hljs-string">&quot;pk-lf-...&quot;</span> 
os.environ[<span class="hljs-string">&quot;LANGFUSE_SECRET_KEY&quot;</span>] = <span class="hljs-string">&quot;sk-lf-...&quot;</span>
os.environ[<span class="hljs-string">&quot;LANGFUSE_HOST&quot;</span>] = <span class="hljs-string">&quot;https://cloud.langfuse.com&quot;</span> <span class="hljs-comment"># 🇪🇺 EU region</span>
<span class="hljs-comment"># os.environ[&quot;LANGFUSE_HOST&quot;] = &quot;https://us.cloud.langfuse.com&quot; # 🇺🇸 US region</span>`,wrap:!1}}),Jl=new C({props:{code:"ZnJvbSUyMGxhbmdmdXNlLmNhbGxiYWNrJTIwaW1wb3J0JTIwQ2FsbGJhY2tIYW5kbGVyJTBBJTBBJTIzJTIwJUU0JUI4JUJBJTIwTGFuZ0dyYXBoJTJGTGFuZ2NoYWluJTIwJUU1JTg4JTlEJUU1JUE3JThCJUU1JThDJTk2JTIwTGFuZ2Z1c2UlMjBDYWxsYmFja0hhbmRsZXIlRUYlQkMlODglRTglQjclOUYlRTglQjglQUElRUYlQkMlODklMEFsYW5nZnVzZV9oYW5kbGVyJTIwJTNEJTIwQ2FsbGJhY2tIYW5kbGVyKCklMEElMEElMjMlMjAlRTUlQTQlODQlRTclOTAlODYlRTUlOTAlODglRTYlQjMlOTUlRTclOTQlQjUlRTUlQUQlOTAlRTklODIlQUUlRTQlQkIlQjYlMEFsZWdpdGltYXRlX3Jlc3VsdCUyMCUzRCUyMGNvbXBpbGVkX2dyYXBoLmludm9rZSglMEElMjAlMjAlMjAlMjBpbnB1dCUzRCU3QiUyMmVtYWlsJTIyJTNBJTIwbGVnaXRpbWF0ZV9lbWFpbCUyQyUyMCUyMmlzX3NwYW0lMjIlM0ElMjBOb25lJTJDJTIwJTIyc3BhbV9yZWFzb24lMjIlM0ElMjBOb25lJTJDJTIwJTIyZW1haWxfY2F0ZWdvcnklMjIlM0ElMjBOb25lJTJDJTIwJTIyZHJhZnRfcmVzcG9uc2UlMjIlM0ElMjBOb25lJTJDJTIwJTIybWVzc2FnZXMlMjIlM0ElMjAlNUIlNUQlN0QlMkMlMEElMjAlMjAlMjAlMjBjb25maWclM0QlN0IlMjJjYWxsYmFja3MlMjIlM0ElMjAlNUJsYW5nZnVzZV9oYW5kbGVyJTVEJTdEJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> langfuse.callback <span class="hljs-keyword">import</span> CallbackHandler

<span class="hljs-comment"># 为 LangGraph/Langchain 初始化 Langfuse CallbackHandler（跟踪）</span>
langfuse_handler = CallbackHandler()

<span class="hljs-comment"># 处理合法电子邮件</span>
legitimate_result = compiled_graph.invoke(
    <span class="hljs-built_in">input</span>={<span class="hljs-string">&quot;email&quot;</span>: legitimate_email, <span class="hljs-string">&quot;is_spam&quot;</span>: <span class="hljs-literal">None</span>, <span class="hljs-string">&quot;spam_reason&quot;</span>: <span class="hljs-literal">None</span>, <span class="hljs-string">&quot;email_category&quot;</span>: <span class="hljs-literal">None</span>, <span class="hljs-string">&quot;draft_response&quot;</span>: <span class="hljs-literal">None</span>, <span class="hljs-string">&quot;messages&quot;</span>: []},
    config={<span class="hljs-string">&quot;callbacks&quot;</span>: [langfuse_handler]}
)`,wrap:!1}}),yl=new I({props:{title:"可视化我们的图表",local:"可视化我们的图表",headingTag:"h2"}}),cl=new C({props:{code:"Y29tcGlsZWRfZ3JhcGguZ2V0X2dyYXBoKCkuZHJhd19tZXJtYWlkX3BuZygp",highlighted:"compiled_graph.get_graph().draw_mermaid_png()",wrap:!1}}),wl=new I({props:{title:"我们构建了什么",local:"我们构建了什么",headingTag:"h2"}}),hl=new I({props:{title:"关键要点",local:"关键要点",headingTag:"h2"}}),gl=new I({props:{title:"下一步是什么？",local:"下一步是什么",headingTag:"h2"}}),Bl=new ht({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/zh-CN/unit2/langgraph/first_graph.mdx"}}),{c(){o=e("meta"),w=n(),h=e("p"),u=n(),p(m.$$.fragment),r=n(),B=e("p"),B.textContent=As,dl=n(),V=e("ol"),V.innerHTML=Es,fl=n(),Q=e("p"),Q.textContent=Ss,Nl=n(),p(g.$$.fragment),Al=n(),p(d.$$.fragment),El=n(),f=e("p"),f.textContent=Zs,Sl=n(),N=e("img"),Zl=n(),p(A.$$.fragment),Fl=n(),E=e("p"),E.textContent=Rs,Rl=n(),p(S.$$.fragment),Wl=n(),Z=e("p"),Z.textContent=Ws,Gl=n(),p(F.$$.fragment),ql=n(),p(R.$$.fragment),kl=n(),W=e("p"),W.textContent=Gs,Yl=n(),p(G.$$.fragment),$l=n(),q=e("blockquote"),q.innerHTML=qs,_l=n(),p(k.$$.fragment),Xl=n(),Y=e("p"),Y.textContent=ks,zl=n(),p($.$$.fragment),vl=n(),p(_.$$.fragment),xl=n(),X=e("p"),X.textContent=Ys,Ol=n(),p(z.$$.fragment),Hl=n(),v=e("blockquote"),v.innerHTML=$s,Ll=n(),p(x.$$.fragment),Dl=n(),O=e("p"),O.textContent=_s,Kl=n(),p(H.$$.fragment),Pl=n(),L=e("p"),L.textContent=Xs,ls=n(),p(D.$$.fragment),ss=n(),K=e("p"),K.textContent=zs,ts=n(),p(P.$$.fragment),as=n(),p(ll.$$.fragment),ns=n(),sl=e("p"),sl.textContent=vs,Ms=n(),tl=e("p"),tl.innerHTML=xs,es=n(),al=e("p"),al.textContent=Os,Us=n(),p(nl.$$.fragment),Js=n(),Ml=e("p"),Ml.innerHTML=Hs,ps=n(),p(el.$$.fragment),Ts=n(),Ul=e("p"),Ul.innerHTML=Ls,js=n(),p(Jl.$$.fragment),ys=n(),pl=e("p"),pl.textContent=Ds,is=n(),Tl=e("p"),Tl.innerHTML=Ks,cs=n(),jl=e("p"),jl.innerHTML=Ps,ms=n(),p(yl.$$.fragment),os=n(),il=e("p"),il.textContent=lt,ws=n(),p(cl.$$.fragment),Is=n(),ml=e("img"),Cs=n(),ol=e("p"),ol.textContent=tt,us=n(),p(wl.$$.fragment),hs=n(),Il=e("p"),Il.textContent=at,rs=n(),Cl=e("ol"),Cl.innerHTML=nt,gs=n(),ul=e("p"),ul.textContent=Mt,bs=n(),p(hl.$$.fragment),Bs=n(),rl=e("ul"),rl.innerHTML=et,Vs=n(),p(gl.$$.fragment),Qs=n(),bl=e("p"),bl.textContent=Ut,ds=n(),p(Bl.$$.fragment),fs=n(),Vl=e("p"),this.h()},l(l){const s=It("svelte-u9bgzb",document.head);o=U(s,"META",{name:!0,content:!0}),s.forEach(t),w=M(l),h=U(l,"P",{}),Tt(h).forEach(t),u=M(l),T(m.$$.fragment,l),r=M(l),B=U(l,"P",{"data-svelte-h":!0}),J(B)!=="svelte-wtpds"&&(B.textContent=As),dl=M(l),V=U(l,"OL",{"data-svelte-h":!0}),J(V)!=="svelte-1w47pet"&&(V.innerHTML=Es),fl=M(l),Q=U(l,"P",{"data-svelte-h":!0}),J(Q)!=="svelte-kmq3p0"&&(Q.textContent=Ss),Nl=M(l),T(g.$$.fragment,l),Al=M(l),T(d.$$.fragment,l),El=M(l),f=U(l,"P",{"data-svelte-h":!0}),J(f)!=="svelte-kmmosp"&&(f.textContent=Zs),Sl=M(l),N=U(l,"IMG",{src:!0,alt:!0}),Zl=M(l),T(A.$$.fragment,l),Fl=M(l),E=U(l,"P",{"data-svelte-h":!0}),J(E)!=="svelte-i8w9z9"&&(E.textContent=Rs),Rl=M(l),T(S.$$.fragment,l),Wl=M(l),Z=U(l,"P",{"data-svelte-h":!0}),J(Z)!=="svelte-u3fqu"&&(Z.textContent=Ws),Gl=M(l),T(F.$$.fragment,l),ql=M(l),T(R.$$.fragment,l),kl=M(l),W=U(l,"P",{"data-svelte-h":!0}),J(W)!=="svelte-1oeecsl"&&(W.textContent=Gs),Yl=M(l),T(G.$$.fragment,l),$l=M(l),q=U(l,"BLOCKQUOTE",{"data-svelte-h":!0}),J(q)!=="svelte-1gaur76"&&(q.innerHTML=qs),_l=M(l),T(k.$$.fragment,l),Xl=M(l),Y=U(l,"P",{"data-svelte-h":!0}),J(Y)!=="svelte-r4wysq"&&(Y.textContent=ks),zl=M(l),T($.$$.fragment,l),vl=M(l),T(_.$$.fragment,l),xl=M(l),X=U(l,"P",{"data-svelte-h":!0}),J(X)!=="svelte-se56vn"&&(X.textContent=Ys),Ol=M(l),T(z.$$.fragment,l),Hl=M(l),v=U(l,"BLOCKQUOTE",{"data-svelte-h":!0}),J(v)!=="svelte-1hjck2a"&&(v.innerHTML=$s),Ll=M(l),T(x.$$.fragment,l),Dl=M(l),O=U(l,"P",{"data-svelte-h":!0}),J(O)!=="svelte-1b8z0o4"&&(O.textContent=_s),Kl=M(l),T(H.$$.fragment,l),Pl=M(l),L=U(l,"P",{"data-svelte-h":!0}),J(L)!=="svelte-cxg8gi"&&(L.textContent=Xs),ls=M(l),T(D.$$.fragment,l),ss=M(l),K=U(l,"P",{"data-svelte-h":!0}),J(K)!=="svelte-9y4o4n"&&(K.textContent=zs),ts=M(l),T(P.$$.fragment,l),as=M(l),T(ll.$$.fragment,l),ns=M(l),sl=U(l,"P",{"data-svelte-h":!0}),J(sl)!=="svelte-1gah1tl"&&(sl.textContent=vs),Ms=M(l),tl=U(l,"P",{"data-svelte-h":!0}),J(tl)!=="svelte-p2eoxe"&&(tl.innerHTML=xs),es=M(l),al=U(l,"P",{"data-svelte-h":!0}),J(al)!=="svelte-e1sodk"&&(al.textContent=Os),Us=M(l),T(nl.$$.fragment,l),Js=M(l),Ml=U(l,"P",{"data-svelte-h":!0}),J(Ml)!=="svelte-1fd3ji6"&&(Ml.innerHTML=Hs),ps=M(l),T(el.$$.fragment,l),Ts=M(l),Ul=U(l,"P",{"data-svelte-h":!0}),J(Ul)!=="svelte-12a4tv9"&&(Ul.innerHTML=Ls),js=M(l),T(Jl.$$.fragment,l),ys=M(l),pl=U(l,"P",{"data-svelte-h":!0}),J(pl)!=="svelte-1vyc13"&&(pl.textContent=Ds),is=M(l),Tl=U(l,"P",{"data-svelte-h":!0}),J(Tl)!=="svelte-ugmrhh"&&(Tl.innerHTML=Ks),cs=M(l),jl=U(l,"P",{"data-svelte-h":!0}),J(jl)!=="svelte-16dcubd"&&(jl.innerHTML=Ps),ms=M(l),T(yl.$$.fragment,l),os=M(l),il=U(l,"P",{"data-svelte-h":!0}),J(il)!=="svelte-1ntiz7g"&&(il.textContent=lt),ws=M(l),T(cl.$$.fragment,l),Is=M(l),ml=U(l,"IMG",{src:!0,alt:!0}),Cs=M(l),ol=U(l,"P",{"data-svelte-h":!0}),J(ol)!=="svelte-10q7f2o"&&(ol.textContent=tt),us=M(l),T(wl.$$.fragment,l),hs=M(l),Il=U(l,"P",{"data-svelte-h":!0}),J(Il)!=="svelte-cz9mlc"&&(Il.textContent=at),rs=M(l),Cl=U(l,"OL",{"data-svelte-h":!0}),J(Cl)!=="svelte-1raplg6"&&(Cl.innerHTML=nt),gs=M(l),ul=U(l,"P",{"data-svelte-h":!0}),J(ul)!=="svelte-aijfvw"&&(ul.textContent=Mt),bs=M(l),T(hl.$$.fragment,l),Bs=M(l),rl=U(l,"UL",{"data-svelte-h":!0}),J(rl)!=="svelte-1i0l2cv"&&(rl.innerHTML=et),Vs=M(l),T(gl.$$.fragment,l),Qs=M(l),bl=U(l,"P",{"data-svelte-h":!0}),J(bl)!=="svelte-1rewr8w"&&(bl.textContent=Ut),ds=M(l),T(Bl.$$.fragment,l),fs=M(l),Vl=U(l,"P",{}),Tt(Vl).forEach(t),this.h()},h(){b(o,"name","hf:doc:metadata"),b(o,"content",bt),pt(N.src,Fs="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/first_graph.png")||b(N,"src",Fs),b(N,"alt","First LangGraph"),pt(ml.src,st="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/mail_flow.png")||b(ml,"src",st),b(ml,"alt","Mail LangGraph")},m(l,s){Ct(document.head,o),a(l,w,s),a(l,h,s),a(l,u,s),j(m,l,s),a(l,r,s),a(l,B,s),a(l,dl,s),a(l,V,s),a(l,fl,s),a(l,Q,s),a(l,Nl,s),j(g,l,s),a(l,Al,s),j(d,l,s),a(l,El,s),a(l,f,s),a(l,Sl,s),a(l,N,s),a(l,Zl,s),j(A,l,s),a(l,Fl,s),a(l,E,s),a(l,Rl,s),j(S,l,s),a(l,Wl,s),a(l,Z,s),a(l,Gl,s),j(F,l,s),a(l,ql,s),j(R,l,s),a(l,kl,s),a(l,W,s),a(l,Yl,s),j(G,l,s),a(l,$l,s),a(l,q,s),a(l,_l,s),j(k,l,s),a(l,Xl,s),a(l,Y,s),a(l,zl,s),j($,l,s),a(l,vl,s),j(_,l,s),a(l,xl,s),a(l,X,s),a(l,Ol,s),j(z,l,s),a(l,Hl,s),a(l,v,s),a(l,Ll,s),j(x,l,s),a(l,Dl,s),a(l,O,s),a(l,Kl,s),j(H,l,s),a(l,Pl,s),a(l,L,s),a(l,ls,s),j(D,l,s),a(l,ss,s),a(l,K,s),a(l,ts,s),j(P,l,s),a(l,as,s),j(ll,l,s),a(l,ns,s),a(l,sl,s),a(l,Ms,s),a(l,tl,s),a(l,es,s),a(l,al,s),a(l,Us,s),j(nl,l,s),a(l,Js,s),a(l,Ml,s),a(l,ps,s),j(el,l,s),a(l,Ts,s),a(l,Ul,s),a(l,js,s),j(Jl,l,s),a(l,ys,s),a(l,pl,s),a(l,is,s),a(l,Tl,s),a(l,cs,s),a(l,jl,s),a(l,ms,s),j(yl,l,s),a(l,os,s),a(l,il,s),a(l,ws,s),j(cl,l,s),a(l,Is,s),a(l,ml,s),a(l,Cs,s),a(l,ol,s),a(l,us,s),j(wl,l,s),a(l,hs,s),a(l,Il,s),a(l,rs,s),a(l,Cl,s),a(l,gs,s),a(l,ul,s),a(l,bs,s),j(hl,l,s),a(l,Bs,s),a(l,rl,s),a(l,Vs,s),j(gl,l,s),a(l,Qs,s),a(l,bl,s),a(l,ds,s),j(Bl,l,s),a(l,fs,s),a(l,Vl,s),Ns=!0},p(l,[s]){const Jt={};s&2&&(Jt.$$scope={dirty:s,ctx:l}),g.$set(Jt)},i(l){Ns||(y(m.$$.fragment,l),y(g.$$.fragment,l),y(d.$$.fragment,l),y(A.$$.fragment,l),y(S.$$.fragment,l),y(F.$$.fragment,l),y(R.$$.fragment,l),y(G.$$.fragment,l),y(k.$$.fragment,l),y($.$$.fragment,l),y(_.$$.fragment,l),y(z.$$.fragment,l),y(x.$$.fragment,l),y(H.$$.fragment,l),y(D.$$.fragment,l),y(P.$$.fragment,l),y(ll.$$.fragment,l),y(nl.$$.fragment,l),y(el.$$.fragment,l),y(Jl.$$.fragment,l),y(yl.$$.fragment,l),y(cl.$$.fragment,l),y(wl.$$.fragment,l),y(hl.$$.fragment,l),y(gl.$$.fragment,l),y(Bl.$$.fragment,l),Ns=!0)},o(l){i(m.$$.fragment,l),i(g.$$.fragment,l),i(d.$$.fragment,l),i(A.$$.fragment,l),i(S.$$.fragment,l),i(F.$$.fragment,l),i(R.$$.fragment,l),i(G.$$.fragment,l),i(k.$$.fragment,l),i($.$$.fragment,l),i(_.$$.fragment,l),i(z.$$.fragment,l),i(x.$$.fragment,l),i(H.$$.fragment,l),i(D.$$.fragment,l),i(P.$$.fragment,l),i(ll.$$.fragment,l),i(nl.$$.fragment,l),i(el.$$.fragment,l),i(Jl.$$.fragment,l),i(yl.$$.fragment,l),i(cl.$$.fragment,l),i(wl.$$.fragment,l),i(hl.$$.fragment,l),i(gl.$$.fragment,l),i(Bl.$$.fragment,l),Ns=!1},d(l){l&&(t(w),t(h),t(u),t(r),t(B),t(dl),t(V),t(fl),t(Q),t(Nl),t(Al),t(El),t(f),t(Sl),t(N),t(Zl),t(Fl),t(E),t(Rl),t(Wl),t(Z),t(Gl),t(ql),t(kl),t(W),t(Yl),t($l),t(q),t(_l),t(Xl),t(Y),t(zl),t(vl),t(xl),t(X),t(Ol),t(Hl),t(v),t(Ll),t(Dl),t(O),t(Kl),t(Pl),t(L),t(ls),t(ss),t(K),t(ts),t(as),t(ns),t(sl),t(Ms),t(tl),t(es),t(al),t(Us),t(Js),t(Ml),t(ps),t(Ts),t(Ul),t(js),t(ys),t(pl),t(is),t(Tl),t(cs),t(jl),t(ms),t(os),t(il),t(ws),t(Is),t(ml),t(Cs),t(ol),t(us),t(hs),t(Il),t(rs),t(Cl),t(gs),t(ul),t(bs),t(Bs),t(rl),t(Vs),t(Qs),t(bl),t(ds),t(fs),t(Vl)),t(o),c(m,l),c(g,l),c(d,l),c(A,l),c(S,l),c(F,l),c(R,l),c(G,l),c(k,l),c($,l),c(_,l),c(z,l),c(x,l),c(H,l),c(D,l),c(P,l),c(ll,l),c(nl,l),c(el,l),c(Jl,l),c(yl,l),c(cl,l),c(wl,l),c(hl,l),c(gl,l),c(Bl,l)}}}const bt='{"title":"构建你的第一个 LangGraph","local":"构建你的第一个-langgraph","sections":[{"title":"工作流程","local":"工作流程","sections":[],"depth":2},{"title":"环境设置","local":"环境设置","sections":[],"depth":2},{"title":"步骤 1：定义我们的状态","local":"步骤-1定义我们的状态","sections":[],"depth":2},{"title":"第 2 步：定义我们的节点","local":"第-2-步定义我们的节点","sections":[],"depth":2},{"title":"步骤 3：定义我们的路由逻辑","local":"步骤-3定义我们的路由逻辑","sections":[],"depth":2},{"title":"步骤 4：创建 StateGraph 并定义边","local":"步骤-4创建-stategraph-并定义边","sections":[],"depth":2},{"title":"步骤 5：运行应用程序","local":"步骤-5运行应用程序","sections":[],"depth":2},{"title":"第 6 步：使用 Langfuse 检查我们的邮件分类智能体 📡","local":"第-6-步使用-langfuse-检查我们的邮件分类智能体-","sections":[],"depth":2},{"title":"可视化我们的图表","local":"可视化我们的图表","sections":[],"depth":2},{"title":"我们构建了什么","local":"我们构建了什么","sections":[],"depth":2},{"title":"关键要点","local":"关键要点","sections":[],"depth":2},{"title":"下一步是什么？","local":"下一步是什么","sections":[],"depth":2}],"depth":1}';function Bt(Ql){return ct(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class At extends ot{constructor(o){super(),wt(this,o,Bt,gt,it,{})}}export{At as component};
