import{s as Bs,o as Rs,n as Es}from"../chunks/scheduler.889ebb13.js";import{S as Gs,i as fs,g as a,s as M,r as n,m as Us,A as ks,h as J,f as t,c as e,j as bs,u as T,x as w,n as Ms,k as ts,y as Fs,a as U,v as y,d as j,t as p,w as i}from"../chunks/index.ca18042b.js";import{T as Vs}from"../chunks/Tip.b8116e3c.js";import{C as c}from"../chunks/CodeBlock.a65374d4.js";import{H as o,E as Ys}from"../chunks/index.d845d0a2.js";function Zs(pl){let m,I,g="这个 notebook",h;return{c(){m=Us("您可以在 "),I=a("a"),I.textContent=g,h=Us(" 中查看代码，并通过 Google Colab 运行。"),this.h()},l(C){m=Ms(C,"您可以在 "),I=J(C,"A",{href:!0,target:!0,"data-svelte-h":!0}),w(I)!=="svelte-hz8ogu"&&(I.textContent=g),h=Ms(C," 中查看代码，并通过 Google Colab 运行。"),this.h()},h(){ts(I,"href","https://huggingface.co/agents-course/notebooks/blob/main/unit2/langgraph/agent.ipynb"),ts(I,"target","_blank")},m(C,u){U(C,m,u),U(C,I,u),U(C,h,u)},p:Es,d(C){C&&(t(m),t(I),t(h))}}}function Ws(pl){let m,I,g,h,C,u,A,es="Alfred 为您服务。作为韦恩先生值得信赖的管家，我已记录下协助处理各类文档需求的工作流程。当 Mr Wayne 外出进行…夜间活动时，我会确保所有文件、训练计划和营养方案都得到妥善分析和整理。",il,d,as="在离开前，他留下了本周训练计划的笔记。我随后负责拟定了明日餐点的<strong>菜单</strong>。",wl,Q,Js="为应对未来的类似需求，让我们使用 LangGraph 构建一个文档分析系统来服务 Mr Wayne。该系统能够：",Cl,b,ns="<li>处理图像文档</li> <li>使用视觉模型 (Vision Language Model) 提取文本</li> <li>在需要时执行计算（用于演示常规工具）</li> <li>分析内容并提供简明摘要</li> <li>执行与文档相关的特定指令</li>",ml,B,Il,R,Ts="我们将构建的工作流程遵循以下结构化方案：",cl,E,ys='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/alfred_flow.png" alt="Butler&#39;s Document Analysis Workflow"/>',ol,r,hl,G,gl,f,js="and imports :",ul,k,rl,F,Al,V,ps=`这个状态比我们之前见过的稍微复杂些。
AnyMessage 是来自 langchain 的类，用于定义消息，而 add_messages 是一个操作符，它会添加最新消息而不是覆盖现有状态。`,dl,Y,is="这是 langGraph 中的一个新概念，您可以在状态中添加 operators 来定义它们之间的交互方式。",Ql,Z,bl,W,Bl,$,Rl,S,El,N,Gl,O,fl,x,ws="请允许我解释该智能体的工作方式。该智能体遵循被称为 ReAct 的模式（推理-行动-观察）",kl,_,Cs="<li><strong>推理</strong> 分析文档和请求内容</li> <li><strong>行动</strong> 通过调用合适的工具执行操作</li> <li><strong>观察</strong> 工具执行结果</li> <li><strong>重复</strong> 上述步骤直到完全满足需求</li>",Fl,X,ms="这是使用 langGraph 实现的简单智能体实现。",Vl,v,Yl,z,Is='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/Agent.png" alt="ReAct Pattern"/>',Zl,D,Wl,q,$l,H,cs="在以下示例中，我们添加这个 divide 示例仅作为演示用途。",Sl,L,Nl,P,os="对话将会继续：",Ol,K,xl,ll,_l,sl,hs="当 Wayne 大师留下他的训练和​​用餐笔记时：",Xl,tl,vl,Ul,gs="交互将进行：",zl,Ml,Dl,el,ql,al,us="若您希望创建自己的文档分析管家，请遵循以下关键原则：",Hl,Jl,rs="<li><strong>定义清晰的工具</strong>（Define clear tools）用于特定文档相关任务</li> <li><strong>创建强大的状态跟踪器</strong>（Create a robust state tracker）以保持工具调用之间的上下文</li> <li><strong>考虑错误处理机制</strong>（Consider error handling）应对工具调用失败</li> <li><strong>保持上下文感知能力</strong>（Maintain contextual awareness）通过 add_messages 操作符确保历史交互的连贯性</li>",Ll,nl,As="遵循这些原则，您也能提供符合韦恩庄园标准的卓越文档分析服务。",Pl,Tl,ds="<em>相信以上解释已足够详尽。恕我失陪，韦恩老爷的披风还需在夜巡前熨烫妥当。</em>",Kl,yl,ls,jl,ss;return C=new o({props:{title:"文档分析图",local:"文档分析图",headingTag:"h1"}}),B=new o({props:{title:"管家的工作流程",local:"管家的工作流程",headingTag:"h2"}}),r=new Vs({props:{$$slots:{default:[Zs]},$$scope:{ctx:pl}}}),G=new c({props:{code:"JTI1cGlwJTIwaW5zdGFsbCUyMGxhbmdncmFwaCUyMGxhbmdjaGFpbl9vcGVuYWklMjBQaWxsb3clMjBiYXNlNjQlMjBsYW5nY2hhaW5fY29yZQ==",highlighted:"%pip install langgraph langchain_openai Pillow base64 langchain_core",wrap:!1}}),k=new c({props:{code:"aW1wb3J0JTIwYmFzZTY0JTBBZnJvbSUyMHR5cGluZyUyMGltcG9ydCUyMExpc3QlMkMlMjBUeXBlZERpY3QlMkMlMjBBbm5vdGF0ZWQlMkMlMjBPcHRpb25hbCUwQWZyb20lMjBsYW5nY2hhaW4uc2NoZW1hJTIwaW1wb3J0JTIwSHVtYW5NZXNzYWdlJTBBZnJvbSUyMGxhbmdjaGFpbl9vcGVuYWklMjBpbXBvcnQlMjBDaGF0T3BlbkFJJTBBZnJvbSUyMGxhbmdjaGFpbl9jb3JlLm1lc3NhZ2VzJTIwaW1wb3J0JTIwQW55TWVzc2FnZSUyQyUyMFN5c3RlbU1lc3NhZ2UlMEFmcm9tJTIwbGFuZ2dyYXBoLmdyYXBoLm1lc3NhZ2UlMjBpbXBvcnQlMjBhZGRfbWVzc2FnZXMlMEFmcm9tJTIwbGFuZ2dyYXBoLmdyYXBoJTIwaW1wb3J0JTIwU1RBUlQlMkMlMjBTdGF0ZUdyYXBoJTBBZnJvbSUyMGxhbmdncmFwaC5wcmVidWlsdCUyMGltcG9ydCUyMHRvb2xzX2NvbmRpdGlvbiUwQWZyb20lMjBsYW5nZ3JhcGgucHJlYnVpbHQlMjBpbXBvcnQlMjBUb29sTm9kZSUwQWZyb20lMjBJUHl0aG9uLmRpc3BsYXklMjBpbXBvcnQlMjBJbWFnZSUyQyUyMGRpc3BsYXk=",highlighted:`<span class="hljs-keyword">import</span> base64
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">List</span>, TypedDict, Annotated, <span class="hljs-type">Optional</span>
<span class="hljs-keyword">from</span> langchain.schema <span class="hljs-keyword">import</span> HumanMessage
<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> AnyMessage, SystemMessage
<span class="hljs-keyword">from</span> langgraph.graph.message <span class="hljs-keyword">import</span> add_messages
<span class="hljs-keyword">from</span> langgraph.graph <span class="hljs-keyword">import</span> START, StateGraph
<span class="hljs-keyword">from</span> langgraph.prebuilt <span class="hljs-keyword">import</span> tools_condition
<span class="hljs-keyword">from</span> langgraph.prebuilt <span class="hljs-keyword">import</span> ToolNode
<span class="hljs-keyword">from</span> IPython.display <span class="hljs-keyword">import</span> Image, display`,wrap:!1}}),F=new o({props:{title:"定义智能体的状态",local:"定义智能体的状态",headingTag:"h2"}}),Z=new c({props:{code:"Y2xhc3MlMjBBZ2VudFN0YXRlKFR5cGVkRGljdCklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjAlRTYlOEYlOTAlRTQlQkUlOUIlRTclOUElODQlRTYlOTYlODclRTQlQkIlQjYlMEElMjAlMjAlMjAlMjBpbnB1dF9maWxlJTNBJTIwT3B0aW9uYWwlNUJzdHIlNUQlMjAlMjAlMjMlMjBDb250YWlucyUyMGZpbGUlMjBwYXRoJTIwKFBERiUyRlBORyklMEElMjAlMjAlMjAlMjBtZXNzYWdlcyUzQSUyMEFubm90YXRlZCU1Qmxpc3QlNUJBbnlNZXNzYWdlJTVEJTJDJTIwYWRkX21lc3NhZ2VzJTVE",highlighted:`<span class="hljs-keyword">class</span> <span class="hljs-title class_">AgentState</span>(<span class="hljs-title class_ inherited__">TypedDict</span>):
    <span class="hljs-comment"># 提供的文件</span>
    input_file: <span class="hljs-type">Optional</span>[<span class="hljs-built_in">str</span>]  <span class="hljs-comment"># Contains file path (PDF/PNG)</span>
    messages: Annotated[<span class="hljs-built_in">list</span>[AnyMessage], add_messages]`,wrap:!1}}),W=new o({props:{title:"准备工具",local:"准备工具",headingTag:"h2"}}),$=new c({props:{code:" ",highlighted:`vision_llm = ChatOpenAI(model=<span class="hljs-string">&quot;gpt-4o&quot;</span>)

<span class="hljs-keyword">def</span> <span class="hljs-title function_">extract_text</span>(<span class="hljs-params">img_path: <span class="hljs-built_in">str</span></span>) -&gt; <span class="hljs-built_in">str</span>:
    <span class="hljs-string">&quot;&quot;&quot;
    Extract text from an image file using a multimodal model.
    
    Master Wayne often leaves notes with his training regimen or meal plans.
    This allows me to properly analyze the contents.
    &quot;&quot;&quot;</span>
    all_text = <span class="hljs-string">&quot;&quot;</span>
    <span class="hljs-keyword">try</span>:
        <span class="hljs-comment"># 读取图像并编码为 base64</span>
        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(img_path, <span class="hljs-string">&quot;rb&quot;</span>) <span class="hljs-keyword">as</span> image_file:
            image_bytes = image_file.read()

        image_base64 = base64.b64encode(image_bytes).decode(<span class="hljs-string">&quot;utf-8&quot;</span>)

        <span class="hljs-comment"># 准备包含 base64 图像数据的提示</span>
        message = [
            HumanMessage(
                content=[
                    {
                        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;text&quot;</span>,
                        <span class="hljs-string">&quot;text&quot;</span>: (
                            <span class="hljs-string">&quot;Extract all the text from this image. &quot;</span>
                            <span class="hljs-string">&quot;Return only the extracted text, no explanations.&quot;</span>
                        ),
                    },
                    {
                        <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;image_url&quot;</span>,
                        <span class="hljs-string">&quot;image_url&quot;</span>: {
                            <span class="hljs-string">&quot;url&quot;</span>: <span class="hljs-string">f&quot;data:image/png;base64,<span class="hljs-subst">{image_base64}</span>&quot;</span>
                        },
                    },
                ]
            )
        ]

        <span class="hljs-comment"># 调用具有视觉功能的模型</span>
        response = vision_llm.invoke(message)

        <span class="hljs-comment"># 附加提取的文本</span>
        all_text += response.content + <span class="hljs-string">&quot;\\n\\n&quot;</span>

        <span class="hljs-keyword">return</span> all_text.strip()
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        <span class="hljs-comment"># 管家应优雅地处理错误</span>
        error_msg = <span class="hljs-string">f&quot;Error extracting text: <span class="hljs-subst">{<span class="hljs-built_in">str</span>(e)}</span>&quot;</span>
        <span class="hljs-built_in">print</span>(error_msg)
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>

<span class="hljs-keyword">def</span> <span class="hljs-title function_">divide</span>(<span class="hljs-params">a: <span class="hljs-built_in">int</span>, b: <span class="hljs-built_in">int</span></span>) -&gt; <span class="hljs-built_in">float</span>:
    <span class="hljs-string">&quot;&quot;&quot;Divide a and b - for Master Wayne&#x27;s occasional calculations.&quot;&quot;&quot;</span>
    <span class="hljs-keyword">return</span> a / b

<span class="hljs-comment"># 为管家配备工具</span>
tools = [
    divide,
    extract_text
]

llm = ChatOpenAI(model=<span class="hljs-string">&quot;gpt-4o&quot;</span>)
llm_with_tools = llm.bind_tools(tools, parallel_tool_calls=<span class="hljs-literal">False</span>)`,wrap:!1}}),S=new o({props:{title:"节点",local:"节点",headingTag:"h2"}}),N=new c({props:{code:"ZGVmJTIwYXNzaXN0YW50KHN0YXRlJTNBJTIwQWdlbnRTdGF0ZSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjAlRTclQjMlQkIlRTclQkIlOUYlRTYlQjYlODglRTYlODElQUYlMEElMjAlMjAlMjAlMjB0ZXh0dWFsX2Rlc2NyaXB0aW9uX29mX3Rvb2wlM0QlMjIlMjIlMjIlMEFleHRyYWN0X3RleHQoaW1nX3BhdGglM0ElMjBzdHIpJTIwLSUzRSUyMHN0ciUzQSUwQSUyMCUyMCUyMCUyMEV4dHJhY3QlMjB0ZXh0JTIwZnJvbSUyMGFuJTIwaW1hZ2UlMjBmaWxlJTIwdXNpbmclMjBhJTIwbXVsdGltb2R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UyMGxvYWRlZCUyMGltYWdlJTIwaXMlM0ElMjAlN0JpbWFnZSU3RCUyMiklMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJtZXNzYWdlcyUyMiUzQSUyMCU1QmxsbV93aXRoX3Rvb2xzLmludm9rZSglNUJzeXNfbXNnJTVEJTIwJTJCJTIwc3RhdGUlNUIlMjJtZXNzYWdlcyUyMiU1RCklNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJpbnB1dF9maWxlJTIyJTNBJTIwc3RhdGUlNUIlMjJpbnB1dF9maWxlJTIyJTVEJTBBJTIwJTIwJTIwJTIwJTdE",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">assistant</span>(<span class="hljs-params">state: AgentState</span>):
    <span class="hljs-comment"># 系统消息</span>
    textual_description_of_tool=<span class="hljs-string">&quot;&quot;&quot;
extract_text(img_path: str) -&gt; str:
    Extract text from an image file using a multimodal model.

    Args:
        img_path: A local image file path (strings).

    Returns:
        A single string containing the concatenated text extracted from each image.
divide(a: int, b: int) -&gt; float:
    Divide a and b
&quot;&quot;&quot;</span>
    image=state[<span class="hljs-string">&quot;input_file&quot;</span>]
    sys_msg = SystemMessage(content=<span class="hljs-string">f&quot;You are an helpful butler named Alfred that serves Mr. Wayne and Batman. You can analyse documents and run computations with provided tools:\\n<span class="hljs-subst">{textual_description_of_tool}</span> \\n You have access to some optional images. Currently the loaded image is: <span class="hljs-subst">{image}</span>&quot;</span>)

    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;messages&quot;</span>: [llm_with_tools.invoke([sys_msg] + state[<span class="hljs-string">&quot;messages&quot;</span>])],
        <span class="hljs-string">&quot;input_file&quot;</span>: state[<span class="hljs-string">&quot;input_file&quot;</span>]
    }`,wrap:!1}}),O=new o({props:{title:"ReAct 模式：我如何协助 Wayne 先生",local:"react-模式我如何协助-wayne-先生",headingTag:"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TclOUIlQjQlRTYlOEUlQTUlRTUlOUIlOUUlRTUlQTQlOEQlMEElMjAlMjAlMjAlMjB0b29sc19jb25kaXRpb24lMkMlMEEpJTBBYnVpbGRlci5hZGRfZWRnZSglMjJ0b29scyUyMiUyQyUyMCUyMmFzc2lzdGFudCUyMiklMEFyZWFjdF9ncmFwaCUyMCUzRCUyMGJ1aWxkZXIuY29tcGlsZSgpJTBBJTBBJTIzJTIwJUU1JUIxJTk1JUU3JThFJUIwJUU3JUFFJUExJUU1JUFFJUI2JUU3JTlBJTg0JUU2JTgwJTlEJUU4JTgwJTgzJUU4JUJGJTg3JUU3JUE4JThCJTBBZGlzcGxheShJbWFnZShyZWFjdF9ncmFwaC5nZXRfZ3JhcGgoeHJheSUzRFRydWUpLmRyYXdfbWVybWFpZF9wbmcoKSkp",highlighted:`<span class="hljs-comment">## The graph</span>
builder = StateGraph(AgentState)

<span class="hljs-comment"># 定义节点：这些节点完成工作</span>
builder.add_node(<span class="hljs-string">&quot;assistant&quot;</span>, assistant)
builder.add_node(<span class="hljs-string">&quot;tools&quot;</span>, ToolNode(tools))

<span class="hljs-comment"># 定义边：这些决定了控制流如何移动</span>
builder.add_edge(START, <span class="hljs-string">&quot;assistant&quot;</span>)
builder.add_conditional_edges(
    <span class="hljs-string">&quot;assistant&quot;</span>,
    <span class="hljs-comment"># 如果最新消息需要工具，则路由至工具</span>
    <span class="hljs-comment"># 否则，请直接回复</span>
    tools_condition,
)
builder.add_edge(<span class="hljs-string">&quot;tools&quot;</span>, <span class="hljs-string">&quot;assistant&quot;</span>)
react_graph = builder.<span class="hljs-built_in">compile</span>()

<span class="hljs-comment"># 展现管家的思考过程</span>
display(Image(react_graph.get_graph(xray=<span class="hljs-literal">True</span>).draw_mermaid_png()))`,wrap:!1}}),D=new o({props:{title:"管家实战示例",local:"管家实战示例",headingTag:"h2"}}),q=new o({props:{title:"示例1：简单计算",local:"示例1简单计算",headingTag:"h3"}}),L=new c({props:{code:"bWVzc2FnZXMlMjAlM0QlMjAlNUJIdW1hbk1lc3NhZ2UoY29udGVudCUzRCUyMkRpdmlkZSUyMDY3OTAlMjBieSUyMDUlMjIpJTVEJTBBbWVzc2FnZXMlMjAlM0QlMjByZWFjdF9ncmFwaC5pbnZva2UoJTdCJTIybWVzc2FnZXMlMjIlM0ElMjBtZXNzYWdlcyUyQyUyMCUyMmlucHV0X2ZpbGUlMjIlM0ElMjBOb25lJTdEKQ==",highlighted:`messages = [HumanMessage(content=<span class="hljs-string">&quot;Divide 6790 by 5&quot;</span>)]
messages = react_graph.invoke({<span class="hljs-string">&quot;messages&quot;</span>: messages, <span class="hljs-string">&quot;input_file&quot;</span>: <span class="hljs-literal">None</span>})`,wrap:!1}}),K=new c({props:{code:"SHVtYW4lM0ElMjBEaXZpZGUlMjA2NzkwJTIwYnklMjA1JTBBJTBBQUklMjBUb29sJTIwQ2FsbCUzQSUyMGRpdmlkZShhJTNENjc5MCUyQyUyMGIlM0Q1KSUwQSUwQVRvb2wlMjBSZXNwb25zZSUzQSUyMDEzNTguMCUwQSUwQUFsZnJlZCUzQSUyMFRoZSUyMHJlc3VsdCUyMG9mJTIwZGl2aWRpbmclMjA2NzkwJTIwYnklMjA1JTIwaXMlMjAxMzU4LjAu",highlighted:`<span class="hljs-attribute">Human</span>: Divide <span class="hljs-number">6790</span> by <span class="hljs-number">5</span>

<span class="hljs-attribute">AI</span> Tool Call: divide(a=<span class="hljs-number">6790</span>, b=<span class="hljs-number">5</span>)

<span class="hljs-attribute">Tool</span> Response: <span class="hljs-number">1358</span>.<span class="hljs-number">0</span>

<span class="hljs-attribute">Alfred</span>: The result of dividing <span class="hljs-number">6790</span> by <span class="hljs-number">5</span> is <span class="hljs-number">1358</span>.<span class="hljs-number">0</span>.`,wrap:!1}}),ll=new o({props:{title:"示例 2：分析 Wayne 大师的训练文档",local:"示例-2分析-wayne-大师的训练文档",headingTag:"h3"}}),tl=new c({props:{code:"bWVzc2FnZXMlMjAlM0QlMjAlNUJIdW1hbk1lc3NhZ2UoY29udGVudCUzRCUyMkFjY29yZGluZyUyMHRvJTIwdGhlJTIwbm90ZSUyMHByb3ZpZGVkJTIwYnklMjBNci4lMjBXYXluZSUyMGluJTIwdGhlJTIwcHJvdmlkZWQlMjBpbWFnZXMuJTIwV2hhdCdzJTIwdGhlJTIwbGlzdCUyMG9mJTIwaXRlbXMlMjBJJTIwc2hvdWxkJTIwYnV5JTIwZm9yJTIwdGhlJTIwZGlubmVyJTIwbWVudSUzRiUyMiklNUQlMEFtZXNzYWdlcyUyMCUzRCUyMHJlYWN0X2dyYXBoLmludm9rZSglN0IlMjJtZXNzYWdlcyUyMiUzQSUyMG1lc3NhZ2VzJTJDJTIwJTIyaW5wdXRfZmlsZSUyMiUzQSUyMCUyMkJhdG1hbl90cmFpbmluZ19hbmRfbWVhbHMucG5nJTIyJTdEKQ==",highlighted:`messages = [HumanMessage(content=<span class="hljs-string">&quot;According to the note provided by Mr. Wayne in the provided images. What&#x27;s the list of items I should buy for the dinner menu?&quot;</span>)]
messages = react_graph.invoke({<span class="hljs-string">&quot;messages&quot;</span>: messages, <span class="hljs-string">&quot;input_file&quot;</span>: <span class="hljs-string">&quot;Batman_training_and_meals.png&quot;</span>})`,wrap:!1}}),Ml=new c({props:{code:"JUU3JTk0JUE4JUU2JTg4JUI3JUVGJUJDJTlBJUU2JUEwJUI5JUU2JThEJUFFJTIwV2F5bmUlMjAlRTUlODUlODglRTclOTQlOUYlRTUlOUMlQTglRTYlOEYlOTAlRTQlQkUlOUIlRTclOUElODQlRTUlOUIlQkUlRTUlODMlOEYlRTQlQjglQUQlRTclOUElODQlRTYlQjMlQTglRTklODclOEElRTMlODAlODIlRTYlODglOTElRTUlQkElOTQlRTglQUYlQTUlRTQlQjglQkElRTYlOTklOUElRTklQTQlOTAlRTglOEYlOUMlRTUlOEQlOTUlRTglQjQlQUQlRTQlQjklQjAlRTUlOTMlQUElRTQlQkElOUIlRTclODklQTklRTUlOTMlODElRUYlQkMlOUYlMEElMEFBSS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TgzJUE0JUU1JTg4JUI2JUU5JTg3JTkxJUU5JUJCJTg0JUU5JUE2JTk5JUU4JThEJTg5JUU1JTlDJTlGJUU4JUIxJTg2JUVGJUJDJTg5JTBBNS4lMjAlRTklQjElQkMlRTYlQjIlQjklRUYlQkMlODgyJTIwJUU1JTg1JThCJUVGJUJDJTg5JTBBJTBBJUU3JUExJUFFJUU0JUJGJTlEJUU3JTg5JTlCJUU2JThFJTkyJUU2JTk4JUFGJUU4JThEJTg5JUU5JUE1JUIyJUU3JTlBJTg0JUVGJUJDJThDJUU1JUI5JUI2JUU0JUI4JTk0JUU4JThGJUEwJUU4JThGJTlDJUU1JTkyJThDJUU4JUJFJUEzJUU2JUE0JTkyJUU2JTk4JUFGJUU2JTlDJTg5JUU2JTlDJUJBJUU3JTlBJTg0JUVGJUJDJThDJUU0JUJCJUE1JUU4JThFJUI3JUU1JUJFJTk3JUU2JTlDJTgwJUU0JUJEJUIzJUU1JTkzJTgxJUU4JUI0JUE4JUU3JTlBJTg0JUU5JUE0JTkwJUU3JTgyJUI5JUUzJTgwJTgy",highlighted:`用户：根据 Wayne 先生在提供的图像中的注释。我应该为晚餐菜单购买哪些物品？

AI<span class="hljs-built_in"> Tool </span>Call: extract_text(<span class="hljs-attribute">img_path</span>=<span class="hljs-string">&quot;Batman_training_and_meals.png&quot;</span>)
<span class="hljs-built_in">
Tool </span>Response: [包含训练计划和菜单详情的提取文本]

Alfred：根据晚餐菜单，您应该购买以下物品：

1. 草饲本地西冷牛排（Grass-fed local sirloin steak）
2. 有机菠菜（Organic spinach）
3. 皮克略辣椒（Piquillo peppers） 
4. 土豆（用于烤制金黄香草土豆）
5. 鱼油（2 克）

确保牛排是草饲的，并且菠菜和辣椒是有机的，以获得最佳品质的餐点。`,wrap:!1}}),el=new o({props:{title:"关键要点",local:"关键要点",headingTag:"h2"}}),yl=new Ys({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/zh-CN/unit2/langgraph/document_analysis_agent.mdx"}}),{c(){m=a("meta"),I=M(),g=a("p"),h=M(),n(C.$$.fragment),u=M(),A=a("p"),A.textContent=es,il=M(),d=a("p"),d.innerHTML=as,wl=M(),Q=a("p"),Q.textContent=Js,Cl=M(),b=a("ol"),b.innerHTML=ns,ml=M(),n(B.$$.fragment),Il=M(),R=a("p"),R.textContent=Ts,cl=M(),E=a("p"),E.innerHTML=ys,ol=M(),n(r.$$.fragment),hl=Us(`
## 设置环境

	`),n(G.$$.fragment),gl=M(),f=a("p"),f.textContent=js,ul=M(),n(k.$$.fragment),rl=M(),n(F.$$.fragment),Al=M(),V=a("p"),V.textContent=ps,dl=M(),Y=a("p"),Y.textContent=is,Ql=M(),n(Z.$$.fragment),bl=M(),n(W.$$.fragment),Bl=M(),n($.$$.fragment),Rl=M(),n(S.$$.fragment),El=M(),n(N.$$.fragment),Gl=M(),n(O.$$.fragment),fl=M(),x=a("p"),x.textContent=ws,kl=M(),_=a("ol"),_.innerHTML=Cs,Fl=M(),X=a("p"),X.textContent=ms,Vl=M(),n(v.$$.fragment),Yl=M(),z=a("p"),z.innerHTML=Is,Zl=M(),n(D.$$.fragment),Wl=M(),n(q.$$.fragment),$l=M(),H=a("p"),H.textContent=cs,Sl=M(),n(L.$$.fragment),Nl=M(),P=a("p"),P.textContent=os,Ol=M(),n(K.$$.fragment),xl=M(),n(ll.$$.fragment),_l=M(),sl=a("p"),sl.textContent=hs,Xl=M(),n(tl.$$.fragment),vl=M(),Ul=a("p"),Ul.textContent=gs,zl=M(),n(Ml.$$.fragment),Dl=M(),n(el.$$.fragment),ql=M(),al=a("p"),al.textContent=us,Hl=M(),Jl=a("ol"),Jl.innerHTML=rs,Ll=M(),nl=a("p"),nl.textContent=As,Pl=M(),Tl=a("p"),Tl.innerHTML=ds,Kl=M(),n(yl.$$.fragment),ls=M(),jl=a("p"),this.h()},l(l){const s=ks("svelte-u9bgzb",document.head);m=J(s,"META",{name:!0,content:!0}),s.forEach(t),I=e(l),g=J(l,"P",{}),bs(g).forEach(t),h=e(l),T(C.$$.fragment,l),u=e(l),A=J(l,"P",{"data-svelte-h":!0}),w(A)!=="svelte-j7qwy"&&(A.textContent=es),il=e(l),d=J(l,"P",{"data-svelte-h":!0}),w(d)!=="svelte-bhamdi"&&(d.innerHTML=as),wl=e(l),Q=J(l,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-bcok6p"&&(Q.textContent=Js),Cl=e(l),b=J(l,"OL",{"data-svelte-h":!0}),w(b)!=="svelte-2x2gky"&&(b.innerHTML=ns),ml=e(l),T(B.$$.fragment,l),Il=e(l),R=J(l,"P",{"data-svelte-h":!0}),w(R)!=="svelte-g72w59"&&(R.textContent=Ts),cl=e(l),E=J(l,"P",{"data-svelte-h":!0}),w(E)!=="svelte-g7cpwr"&&(E.innerHTML=ys),ol=e(l),T(r.$$.fragment,l),hl=Ms(l,`
## 设置环境

	`),T(G.$$.fragment,l),gl=e(l),f=J(l,"P",{"data-svelte-h":!0}),w(f)!=="svelte-1ey17wx"&&(f.textContent=js),ul=e(l),T(k.$$.fragment,l),rl=e(l),T(F.$$.fragment,l),Al=e(l),V=J(l,"P",{"data-svelte-h":!0}),w(V)!=="svelte-15ot7z4"&&(V.textContent=ps),dl=e(l),Y=J(l,"P",{"data-svelte-h":!0}),w(Y)!=="svelte-ay1eqk"&&(Y.textContent=is),Ql=e(l),T(Z.$$.fragment,l),bl=e(l),T(W.$$.fragment,l),Bl=e(l),T($.$$.fragment,l),Rl=e(l),T(S.$$.fragment,l),El=e(l),T(N.$$.fragment,l),Gl=e(l),T(O.$$.fragment,l),fl=e(l),x=J(l,"P",{"data-svelte-h":!0}),w(x)!=="svelte-9ivy9a"&&(x.textContent=ws),kl=e(l),_=J(l,"OL",{"data-svelte-h":!0}),w(_)!=="svelte-11lwswh"&&(_.innerHTML=Cs),Fl=e(l),X=J(l,"P",{"data-svelte-h":!0}),w(X)!=="svelte-1e5nt7w"&&(X.textContent=ms),Vl=e(l),T(v.$$.fragment,l),Yl=e(l),z=J(l,"P",{"data-svelte-h":!0}),w(z)!=="svelte-1nhlurw"&&(z.innerHTML=Is),Zl=e(l),T(D.$$.fragment,l),Wl=e(l),T(q.$$.fragment,l),$l=e(l),H=J(l,"P",{"data-svelte-h":!0}),w(H)!=="svelte-dxehyw"&&(H.textContent=cs),Sl=e(l),T(L.$$.fragment,l),Nl=e(l),P=J(l,"P",{"data-svelte-h":!0}),w(P)!=="svelte-16kdhwk"&&(P.textContent=os),Ol=e(l),T(K.$$.fragment,l),xl=e(l),T(ll.$$.fragment,l),_l=e(l),sl=J(l,"P",{"data-svelte-h":!0}),w(sl)!=="svelte-cyjxhu"&&(sl.textContent=hs),Xl=e(l),T(tl.$$.fragment,l),vl=e(l),Ul=J(l,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-1m9vwg1"&&(Ul.textContent=gs),zl=e(l),T(Ml.$$.fragment,l),Dl=e(l),T(el.$$.fragment,l),ql=e(l),al=J(l,"P",{"data-svelte-h":!0}),w(al)!=="svelte-1fm4afm"&&(al.textContent=us),Hl=e(l),Jl=J(l,"OL",{"data-svelte-h":!0}),w(Jl)!=="svelte-6zgrsn"&&(Jl.innerHTML=rs),Ll=e(l),nl=J(l,"P",{"data-svelte-h":!0}),w(nl)!=="svelte-lcweis"&&(nl.textContent=As),Pl=e(l),Tl=J(l,"P",{"data-svelte-h":!0}),w(Tl)!=="svelte-3gl5yz"&&(Tl.innerHTML=ds),Kl=e(l),T(yl.$$.fragment,l),ls=e(l),jl=J(l,"P",{}),bs(jl).forEach(t),this.h()},h(){ts(m,"name","hf:doc:metadata"),ts(m,"content",$s)},m(l,s){Fs(document.head,m),U(l,I,s),U(l,g,s),U(l,h,s),y(C,l,s),U(l,u,s),U(l,A,s),U(l,il,s),U(l,d,s),U(l,wl,s),U(l,Q,s),U(l,Cl,s),U(l,b,s),U(l,ml,s),y(B,l,s),U(l,Il,s),U(l,R,s),U(l,cl,s),U(l,E,s),U(l,ol,s),y(r,l,s),U(l,hl,s),y(G,l,s),U(l,gl,s),U(l,f,s),U(l,ul,s),y(k,l,s),U(l,rl,s),y(F,l,s),U(l,Al,s),U(l,V,s),U(l,dl,s),U(l,Y,s),U(l,Ql,s),y(Z,l,s),U(l,bl,s),y(W,l,s),U(l,Bl,s),y($,l,s),U(l,Rl,s),y(S,l,s),U(l,El,s),y(N,l,s),U(l,Gl,s),y(O,l,s),U(l,fl,s),U(l,x,s),U(l,kl,s),U(l,_,s),U(l,Fl,s),U(l,X,s),U(l,Vl,s),y(v,l,s),U(l,Yl,s),U(l,z,s),U(l,Zl,s),y(D,l,s),U(l,Wl,s),y(q,l,s),U(l,$l,s),U(l,H,s),U(l,Sl,s),y(L,l,s),U(l,Nl,s),U(l,P,s),U(l,Ol,s),y(K,l,s),U(l,xl,s),y(ll,l,s),U(l,_l,s),U(l,sl,s),U(l,Xl,s),y(tl,l,s),U(l,vl,s),U(l,Ul,s),U(l,zl,s),y(Ml,l,s),U(l,Dl,s),y(el,l,s),U(l,ql,s),U(l,al,s),U(l,Hl,s),U(l,Jl,s),U(l,Ll,s),U(l,nl,s),U(l,Pl,s),U(l,Tl,s),U(l,Kl,s),y(yl,l,s),U(l,ls,s),U(l,jl,s),ss=!0},p(l,[s]){const Qs={};s&2&&(Qs.$$scope={dirty:s,ctx:l}),r.$set(Qs)},i(l){ss||(j(C.$$.fragment,l),j(B.$$.fragment,l),j(r.$$.fragment,l),j(G.$$.fragment,l),j(k.$$.fragment,l),j(F.$$.fragment,l),j(Z.$$.fragment,l),j(W.$$.fragment,l),j($.$$.fragment,l),j(S.$$.fragment,l),j(N.$$.fragment,l),j(O.$$.fragment,l),j(v.$$.fragment,l),j(D.$$.fragment,l),j(q.$$.fragment,l),j(L.$$.fragment,l),j(K.$$.fragment,l),j(ll.$$.fragment,l),j(tl.$$.fragment,l),j(Ml.$$.fragment,l),j(el.$$.fragment,l),j(yl.$$.fragment,l),ss=!0)},o(l){p(C.$$.fragment,l),p(B.$$.fragment,l),p(r.$$.fragment,l),p(G.$$.fragment,l),p(k.$$.fragment,l),p(F.$$.fragment,l),p(Z.$$.fragment,l),p(W.$$.fragment,l),p($.$$.fragment,l),p(S.$$.fragment,l),p(N.$$.fragment,l),p(O.$$.fragment,l),p(v.$$.fragment,l),p(D.$$.fragment,l),p(q.$$.fragment,l),p(L.$$.fragment,l),p(K.$$.fragment,l),p(ll.$$.fragment,l),p(tl.$$.fragment,l),p(Ml.$$.fragment,l),p(el.$$.fragment,l),p(yl.$$.fragment,l),ss=!1},d(l){l&&(t(I),t(g),t(h),t(u),t(A),t(il),t(d),t(wl),t(Q),t(Cl),t(b),t(ml),t(Il),t(R),t(cl),t(E),t(ol),t(hl),t(gl),t(f),t(ul),t(rl),t(Al),t(V),t(dl),t(Y),t(Ql),t(bl),t(Bl),t(Rl),t(El),t(Gl),t(fl),t(x),t(kl),t(_),t(Fl),t(X),t(Vl),t(Yl),t(z),t(Zl),t(Wl),t($l),t(H),t(Sl),t(Nl),t(P),t(Ol),t(xl),t(_l),t(sl),t(Xl),t(vl),t(Ul),t(zl),t(Dl),t(ql),t(al),t(Hl),t(Jl),t(Ll),t(nl),t(Pl),t(Tl),t(Kl),t(ls),t(jl)),t(m),i(C,l),i(B,l),i(r,l),i(G,l),i(k,l),i(F,l),i(Z,l),i(W,l),i($,l),i(S,l),i(N,l),i(O,l),i(v,l),i(D,l),i(q,l),i(L,l),i(K,l),i(ll,l),i(tl,l),i(Ml,l),i(el,l),i(yl,l)}}}const $s='{"title":"文档分析图","local":"文档分析图","sections":[{"title":"管家的工作流程","local":"管家的工作流程","sections":[],"depth":2},{"title":"定义智能体的状态","local":"定义智能体的状态","sections":[],"depth":2},{"title":"准备工具","local":"准备工具","sections":[],"depth":2},{"title":"节点","local":"节点","sections":[],"depth":2},{"title":"ReAct 模式：我如何协助 Wayne 先生","local":"react-模式我如何协助-wayne-先生","sections":[],"depth":2},{"title":"管家实战示例","local":"管家实战示例","sections":[{"title":"示例1：简单计算","local":"示例1简单计算","sections":[],"depth":3},{"title":"示例 2：分析 Wayne 大师的训练文档","local":"示例-2分析-wayne-大师的训练文档","sections":[],"depth":3}],"depth":2},{"title":"关键要点","local":"关键要点","sections":[],"depth":2}],"depth":1}';function Ss(pl){return Rs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class vs extends Gs{constructor(m){super(),fs(this,m,Ss,Ws,Bs,{})}}export{vs as component};
