import{s as Zs,o as Ws,n as $s}from"../chunks/scheduler.37c15a92.js";import{S as ks,i as vs,g as M,s as a,r as p,A as Es,h as i,f as t,c as n,j as Gs,u as y,x as T,k as as,y as xs,a as e,v as o,d as w,t as j,w as J,m as As,n as fs}from"../chunks/index.2bf4358c.js";import{T as Ys}from"../chunks/Tip.363c041f.js";import{C as c}from"../chunks/CodeBlock.4f5fc1ad.js";import{H as h}from"../chunks/Heading.8ada512a.js";import{E as Rs}from"../chunks/EditOnGithub.9958bcdc.js";function Xs(Jl){let m,r,u="this notebook",d;return{c(){m=As("You can follow the code in "),r=M("a"),r.textContent=u,d=As(" that you can run using Google Colab."),this.h()},l(U){m=fs(U,"You can follow the code in "),r=i(U,"A",{href:!0,target:!0,"data-svelte-h":!0}),T(r)!=="svelte-12bw6nz"&&(r.textContent=u),d=fs(U," that you can run using Google Colab."),this.h()},h(){as(r,"href","https://huggingface.co/agents-course/notebooks/blob/main/unit2/langgraph/agent.ipynb"),as(r,"target","_blank")},m(U,I){e(U,m,I),e(U,r,I),e(U,d,I)},p:$s,d(U){U&&(t(m),t(r),t(d))}}}function Fs(Jl){let m,r,u,d,U,I,b,ns="Alfred at your service. As Mr. Wayne’s trusted butler, I’ve taken the liberty of documenting how I assist Mr Wayne with his various documentary needs. While he’s out attending to his… nighttime activities, I ensure all his paperwork, training schedules, and nutritional plans are properly analyzed and organized.",Tl,g,Ms="Before leaving, he left a note with his week training program. I then took the responsability to come up with a <strong>menu</strong> for tomorrow’s meals.",Ul,B,is="For future such event, let’s create a document analysis system using LangGraph to serve Mister Wayne’s needs. This system can:",ml,G,ps="<li>Process images document</li> <li>Extract text using vision models (Vision Language Model)</li> <li>Perform calculations when needed (to demonstrate normal tools)</li> <li>Analyze content and provide concise summaries</li> <li>Execute specific instructions related to documents</li>",rl,A,hl,f,ys="The workflow we’ll build, follows a structured this schema:",cl,Z,os='<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"/>',dl,C,ul,W,Il,$,Cl,k,ws="and imports :",bl,v,gl,E,Bl,x,js=`This state is a little more complex than the previous ones we have seen.
AnyMessage is a class from langchain that define messages and the add_messages is an operator that add the latest message rather than overwritting it with the latest state.`,Gl,Y,Js="This is a new concept in LangGraph, where you can add operators in your state to define the way they should interact together.",Al,R,fl,X,Zl,F,Wl,S,$l,N,kl,V,vl,Q,Ts="Allow me to explain the approach in this agent. The agent follows what’s known as the ReAct pattern (Reason-Act-Observe)",El,_,Us="<li><strong>Reason</strong> about his documents and requests</li> <li><strong>Act</strong> by using appropriate tools</li> <li><strong>Observe</strong> the results</li> <li><strong>Repeat</strong> as necessary until I’ve fully addressed his needs</li>",xl,H,ms="This is a simple implementation of an agent using langGraph.",Yl,z,Rl,q,rs='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/Agent.png" alt="ReAct Pattern"/>',Xl,L,Fl,P,Sl,D,hs="In the following example, we added this divide example just as a",Nl,K,Vl,O,cs="The conversation would proceed:",Ql,ll,_l,sl,Hl,tl,ds="When Master Wayne leaves his training and meal notes:",zl,el,ql,al,us="The interaction would proceed:",Ll,nl,Pl,Ml,Dl,il,Is="Should you wish to create your own document analysis butler, here are key considerations:",Kl,pl,Cs="<li><strong>Define clear tools</strong> for specific document-related tasks</li> <li><strong>Create a robust state tracker</strong> to maintain context between tool calls</li> <li><strong>Consider error handling</strong> for tools fails</li> <li><strong>Maintain contextual awareness</strong> of previous interactions (ensured by the operator add_messages)</li>",Ol,yl,bs="With these principles, you too can provide exemplary document analysis service worthy of Wayne Manor.",ls,ol,gs="<em>I trust this explanation has been satisfactory. Now, if you’ll excuse me, Master Wayne’s cape requires pressing before tonight’s activities.</em>",ss,wl,ts,jl,es;return U=new h({props:{title:"Document Analysis Graph",local:"document-analysis-graph",headingTag:"h1"}}),A=new h({props:{title:"The Butler’s Workflow",local:"the-butlers-workflow",headingTag:"h2"}}),C=new Ys({props:{$$slots:{default:[Xs]},$$scope:{ctx:Jl}}}),W=new h({props:{title:"Setting Up the environment",local:"setting-up-the-environment",headingTag:"h2"}}),$=new c({props:{code:"JTI1cGlwJTIwaW5zdGFsbCUyMGxhbmdncmFwaCUyMGxhbmdjaGFpbl9vcGVuYWklMjBQaWxsb3clMjBiYXNlNjQlMjBsYW5nY2hhaW5fY29yZQ==",highlighted:"%pip install langgraph langchain_openai Pillow base64 langchain_core",wrap:!1}}),v=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}}),E=new h({props:{title:"Defining Agent’s State",local:"defining-agents-state",headingTag:"h2"}}),R=new c({props:{code:"Y2xhc3MlMjBBZ2VudFN0YXRlKFR5cGVkRGljdCklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUaGUlMjBkb2N1bWVudCUyMHByb3ZpZGVkJTBBJTIwJTIwJTIwJTIwaW5wdXRfZmlsZSUzQSUyME9wdGlvbmFsJTVCc3RyJTVEJTIwJTIwJTIzJTIwQ29udGFpbnMlMjBmaWxlJTIwcGF0aCUyMChQREYlMkZQTkcpJTBBJTIwJTIwJTIwJTIwbWVzc2FnZXMlM0ElMjBBbm5vdGF0ZWQlNUJsaXN0JTVCQW55TWVzc2FnZSU1RCUyQyUyMGFkZF9tZXNzYWdlcyU1RA==",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"># The document provided</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}}),X=new h({props:{title:"Preparing Tools",local:"preparing-tools",headingTag:"h2"}}),F=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"># Read image and encode as 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"># Prepare the prompt including the base64 image data</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"># Call the vision-capable model</span>
        response = vision_llm.invoke(message)

        <span class="hljs-comment"># Append extracted text</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"># A butler should handle errors gracefully</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"># Equip the butler with tools</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 h({props:{title:"The nodes",local:"the-nodes",headingTag:"h2"}}),N=new c({props:{code:"ZGVmJTIwYXNzaXN0YW50KHN0YXRlJTNBJTIwQWdlbnRTdGF0ZSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBTeXN0ZW0lMjBtZXNzYWdlJTBBJTIwJTIwJTIwJTIwdGV4dHVhbF9kZXNjcmlwdGlvbl9vZl90b29sJTNEJTIyJTIyJTIyJTBBZXh0cmFjdF90ZXh0KGltZ19wYXRoJTNBJTIwc3RyKSUyMC0lM0UlMjBzdHIlM0ElMEElMjAlMjAlMjAlMjBFeHRyYWN0JTIwdGV4dCUyMGZyb20lMjBhbiUyMGltYWdlJTIwZmlsZSUyMHVzaW5nJTIwYSUyMG11bHRpbW9kYWwlMjBtb2RlbC4lMEElMEElMjAlMjAlMjAlMjBBcmdzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW1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JTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybWVzc2FnZXMlMjIlM0ElMjAlNUJsbG1fd2l0aF90b29scy5pbnZva2UoJTVCc3lzX21zZyU1RCUyMCUyQiUyMHN0YXRlJTVCJTIybWVzc2FnZXMlMjIlNUQpJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyaW5wdXRfZmlsZSUyMiUzQSUyMHN0YXRlJTVCJTIyaW5wdXRfZmlsZSUyMiU1RCUwQSUyMCUyMCUyMCUyMCU3RA==",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"># System message</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}}),V=new h({props:{title:"The ReAct Pattern: How I Assist Mr. Wayne",local:"the-react-pattern-how-i-assist-mr-wayne",headingTag:"h2"}}),z=new c({props:{code:"JTIzJTIzJTIwVGhlJTIwZ3JhcGglMEFidWlsZGVyJTIwJTNEJTIwU3RhdGVHcmFwa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comment">## The graph</span>
builder = StateGraph(AgentState)

<span class="hljs-comment"># Define nodes: these do the work</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"># Define edges: these determine how the control flow moves</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"># If the latest message requires a tool, route to tools</span>
    <span class="hljs-comment"># Otherwise, provide a direct response</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"># Show the butler&#x27;s thought process</span>
display(Image(react_graph.get_graph(xray=<span class="hljs-literal">True</span>).draw_mermaid_png()))`,wrap:!1}}),L=new h({props:{title:"The Butler in Action",local:"the-butler-in-action",headingTag:"h2"}}),P=new h({props:{title:"Example 1: Simple Calculations",local:"example-1-simple-calculations",headingTag:"h3"}}),K=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}}),ll=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}}),sl=new h({props:{title:"Example 2: Analyzing Master Wayne’s Training Documents",local:"example-2-analyzing-master-waynes-training-documents",headingTag:"h3"}}),el=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}}),nl=new c({props:{code:"SHVtYW4lM0ElMjBBY2NvcmRpbmclMjB0byUyMHRoZSUyMG5vdGUlMjBwcm92aWRlZCUyMGJ5JTIwTXIuJTIwV2F5bmUlMjBpbiUyMHRoZSUyMHByb3ZpZGVkJTIwaW1hZ2VzLiUyMFdoYXQncyUyMHRoZSUyMGxpc3QlMjBvZiUyMGl0ZW1zJTIwSSUyMHNob3VsZCUyMGJ1eSUyMGZvciUyMHRoZSUyMGRpbm5lciUyMG1lbnUlM0YlMEElMEFBSSUyMFRvb2wlMjBDYWxsJTNBJTIwZXh0cmFjdF90ZXh0KGltZ19wYXRoJTNEJTIyQmF0bWFuX3RyYWluaW5nX2FuZF9tZWFscy5wbmclMjIpJTBBJTBBVG9vbCUyMFJlc3BvbnNlJTNBJTIwJTVCRXh0cmFjdGVkJTIwdGV4dCUyMHdpdGglMjB0cmFpbmluZyUyMHNjaGVkdWxlJTIwYW5kJTIwbWVudSUyMGRldGFpbHMlNUQlMEElMEFBbGZyZWQlM0ElMjBGb3IlMjB0aGUlMjBkaW5uZXIlMjBtZW51JTJDJTIweW91JTIwc2hvdWxkJTIwYnV5JTIwdGhlJTIwZm9sbG93aW5nJTIwaXRlbXMlM0ElMEElMEExLiUyMEdyYXNzLWZlZCUyMGxvY2FsJTIwc2lybG9pbiUyMHN0ZWFrJTBBMi4lMjBPcmdhbmljJTIwc3BpbmFjaCUwQTMuJTIwUGlxdWlsbG8lMjBwZXBwZXJzJTBBNC4lMjBQb3RhdG9lcyUyMChmb3IlMjBvdmVuLWJha2VkJTIwZ29sZGVuJTIwaGVyYiUyMHBvdGF0byklMEE1LiUyMEZpc2glMjBvaWwlMjAoMiUyMGdyYW1zKSUwQSUwQUVuc3VyZSUyMHRoZSUyMHN0ZWFrJTIwaXMlMjBncmFzcy1mZWQlMjBhbmQlMjB0aGUlMjBzcGluYWNoJTIwYW5kJTIwcGVwcGVycyUyMGFyZSUyMG9yZ2FuaWMlMjBmb3IlMjB0aGUlMjBiZXN0JTIwcXVhbGl0eSUyMG1lYWwu",highlighted:`<span class="hljs-symbol">Human:</span> According <span class="hljs-keyword">to</span> the note provided <span class="hljs-keyword">by</span> Mr. Wayne <span class="hljs-keyword">in</span> the provided images. What<span class="hljs-comment">&#x27;s the list of items I should buy for the dinner menu?</span>

AI Tool <span class="hljs-keyword">Call</span>: extract_text(img_path=<span class="hljs-string">&quot;Batman_training_and_meals.png&quot;</span>)

Tool Response: [Extracted <span class="hljs-keyword">text</span> <span class="hljs-keyword">with</span> training schedule <span class="hljs-built_in">and</span> menu details]

<span class="hljs-symbol">Alfred:</span> <span class="hljs-keyword">For</span> the dinner menu, you should buy the following items:

<span class="hljs-number">1</span>. Grass-fed local sirloin steak
<span class="hljs-number">2</span>. Organic spinach
<span class="hljs-number">3</span>. Piquillo peppers
<span class="hljs-number">4</span>. Potatoes (<span class="hljs-keyword">for</span> oven-baked golden herb potato)
<span class="hljs-number">5</span>. Fish oil (<span class="hljs-number">2</span> grams)

Ensure the steak <span class="hljs-built_in">is</span> grass-fed <span class="hljs-built_in">and</span> the spinach <span class="hljs-built_in">and</span> peppers are organic <span class="hljs-keyword">for</span> the best quality meal.`,wrap:!1}}),Ml=new h({props:{title:"Key Takeaways",local:"key-takeaways",headingTag:"h2"}}),wl=new Rs({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/en/unit2/langgraph/document_analysis_agent.mdx"}}),{c(){m=M("meta"),r=a(),u=M("p"),d=a(),p(U.$$.fragment),I=a(),b=M("p"),b.textContent=ns,Tl=a(),g=M("p"),g.innerHTML=Ms,Ul=a(),B=M("p"),B.textContent=is,ml=a(),G=M("ol"),G.innerHTML=ps,rl=a(),p(A.$$.fragment),hl=a(),f=M("p"),f.textContent=ys,cl=a(),Z=M("p"),Z.innerHTML=os,dl=a(),p(C.$$.fragment),ul=a(),p(W.$$.fragment),Il=a(),p($.$$.fragment),Cl=a(),k=M("p"),k.textContent=ws,bl=a(),p(v.$$.fragment),gl=a(),p(E.$$.fragment),Bl=a(),x=M("p"),x.textContent=js,Gl=a(),Y=M("p"),Y.textContent=Js,Al=a(),p(R.$$.fragment),fl=a(),p(X.$$.fragment),Zl=a(),p(F.$$.fragment),Wl=a(),p(S.$$.fragment),$l=a(),p(N.$$.fragment),kl=a(),p(V.$$.fragment),vl=a(),Q=M("p"),Q.textContent=Ts,El=a(),_=M("ol"),_.innerHTML=Us,xl=a(),H=M("p"),H.textContent=ms,Yl=a(),p(z.$$.fragment),Rl=a(),q=M("p"),q.innerHTML=rs,Xl=a(),p(L.$$.fragment),Fl=a(),p(P.$$.fragment),Sl=a(),D=M("p"),D.textContent=hs,Nl=a(),p(K.$$.fragment),Vl=a(),O=M("p"),O.textContent=cs,Ql=a(),p(ll.$$.fragment),_l=a(),p(sl.$$.fragment),Hl=a(),tl=M("p"),tl.textContent=ds,zl=a(),p(el.$$.fragment),ql=a(),al=M("p"),al.textContent=us,Ll=a(),p(nl.$$.fragment),Pl=a(),p(Ml.$$.fragment),Dl=a(),il=M("p"),il.textContent=Is,Kl=a(),pl=M("ol"),pl.innerHTML=Cs,Ol=a(),yl=M("p"),yl.textContent=bs,ls=a(),ol=M("p"),ol.innerHTML=gs,ss=a(),p(wl.$$.fragment),ts=a(),jl=M("p"),this.h()},l(l){const s=Es("svelte-u9bgzb",document.head);m=i(s,"META",{name:!0,content:!0}),s.forEach(t),r=n(l),u=i(l,"P",{}),Gs(u).forEach(t),d=n(l),y(U.$$.fragment,l),I=n(l),b=i(l,"P",{"data-svelte-h":!0}),T(b)!=="svelte-11xka8s"&&(b.textContent=ns),Tl=n(l),g=i(l,"P",{"data-svelte-h":!0}),T(g)!=="svelte-t4bjwl"&&(g.innerHTML=Ms),Ul=n(l),B=i(l,"P",{"data-svelte-h":!0}),T(B)!=="svelte-17vvsed"&&(B.textContent=is),ml=n(l),G=i(l,"OL",{"data-svelte-h":!0}),T(G)!=="svelte-gyca7w"&&(G.innerHTML=ps),rl=n(l),y(A.$$.fragment,l),hl=n(l),f=i(l,"P",{"data-svelte-h":!0}),T(f)!=="svelte-p4eu2y"&&(f.textContent=ys),cl=n(l),Z=i(l,"P",{"data-svelte-h":!0}),T(Z)!=="svelte-g7cpwr"&&(Z.innerHTML=os),dl=n(l),y(C.$$.fragment,l),ul=n(l),y(W.$$.fragment,l),Il=n(l),y($.$$.fragment,l),Cl=n(l),k=i(l,"P",{"data-svelte-h":!0}),T(k)!=="svelte-1ey17wx"&&(k.textContent=ws),bl=n(l),y(v.$$.fragment,l),gl=n(l),y(E.$$.fragment,l),Bl=n(l),x=i(l,"P",{"data-svelte-h":!0}),T(x)!=="svelte-1d1vtsq"&&(x.textContent=js),Gl=n(l),Y=i(l,"P",{"data-svelte-h":!0}),T(Y)!=="svelte-s7exkc"&&(Y.textContent=Js),Al=n(l),y(R.$$.fragment,l),fl=n(l),y(X.$$.fragment,l),Zl=n(l),y(F.$$.fragment,l),Wl=n(l),y(S.$$.fragment,l),$l=n(l),y(N.$$.fragment,l),kl=n(l),y(V.$$.fragment,l),vl=n(l),Q=i(l,"P",{"data-svelte-h":!0}),T(Q)!=="svelte-18vru10"&&(Q.textContent=Ts),El=n(l),_=i(l,"OL",{"data-svelte-h":!0}),T(_)!=="svelte-1s296x7"&&(_.innerHTML=Us),xl=n(l),H=i(l,"P",{"data-svelte-h":!0}),T(H)!=="svelte-7iqp0"&&(H.textContent=ms),Yl=n(l),y(z.$$.fragment,l),Rl=n(l),q=i(l,"P",{"data-svelte-h":!0}),T(q)!=="svelte-1nhlurw"&&(q.innerHTML=rs),Xl=n(l),y(L.$$.fragment,l),Fl=n(l),y(P.$$.fragment,l),Sl=n(l),D=i(l,"P",{"data-svelte-h":!0}),T(D)!=="svelte-1ex6163"&&(D.textContent=hs),Nl=n(l),y(K.$$.fragment,l),Vl=n(l),O=i(l,"P",{"data-svelte-h":!0}),T(O)!=="svelte-eegy09"&&(O.textContent=cs),Ql=n(l),y(ll.$$.fragment,l),_l=n(l),y(sl.$$.fragment,l),Hl=n(l),tl=i(l,"P",{"data-svelte-h":!0}),T(tl)!=="svelte-k6gec7"&&(tl.textContent=ds),zl=n(l),y(el.$$.fragment,l),ql=n(l),al=i(l,"P",{"data-svelte-h":!0}),T(al)!=="svelte-gpwkjm"&&(al.textContent=us),Ll=n(l),y(nl.$$.fragment,l),Pl=n(l),y(Ml.$$.fragment,l),Dl=n(l),il=i(l,"P",{"data-svelte-h":!0}),T(il)!=="svelte-17u0oai"&&(il.textContent=Is),Kl=n(l),pl=i(l,"OL",{"data-svelte-h":!0}),T(pl)!=="svelte-1qddtr0"&&(pl.innerHTML=Cs),Ol=n(l),yl=i(l,"P",{"data-svelte-h":!0}),T(yl)!=="svelte-1tc3qgy"&&(yl.textContent=bs),ls=n(l),ol=i(l,"P",{"data-svelte-h":!0}),T(ol)!=="svelte-1ik86s0"&&(ol.innerHTML=gs),ss=n(l),y(wl.$$.fragment,l),ts=n(l),jl=i(l,"P",{}),Gs(jl).forEach(t),this.h()},h(){as(m,"name","hf:doc:metadata"),as(m,"content",Ss)},m(l,s){xs(document.head,m),e(l,r,s),e(l,u,s),e(l,d,s),o(U,l,s),e(l,I,s),e(l,b,s),e(l,Tl,s),e(l,g,s),e(l,Ul,s),e(l,B,s),e(l,ml,s),e(l,G,s),e(l,rl,s),o(A,l,s),e(l,hl,s),e(l,f,s),e(l,cl,s),e(l,Z,s),e(l,dl,s),o(C,l,s),e(l,ul,s),o(W,l,s),e(l,Il,s),o($,l,s),e(l,Cl,s),e(l,k,s),e(l,bl,s),o(v,l,s),e(l,gl,s),o(E,l,s),e(l,Bl,s),e(l,x,s),e(l,Gl,s),e(l,Y,s),e(l,Al,s),o(R,l,s),e(l,fl,s),o(X,l,s),e(l,Zl,s),o(F,l,s),e(l,Wl,s),o(S,l,s),e(l,$l,s),o(N,l,s),e(l,kl,s),o(V,l,s),e(l,vl,s),e(l,Q,s),e(l,El,s),e(l,_,s),e(l,xl,s),e(l,H,s),e(l,Yl,s),o(z,l,s),e(l,Rl,s),e(l,q,s),e(l,Xl,s),o(L,l,s),e(l,Fl,s),o(P,l,s),e(l,Sl,s),e(l,D,s),e(l,Nl,s),o(K,l,s),e(l,Vl,s),e(l,O,s),e(l,Ql,s),o(ll,l,s),e(l,_l,s),o(sl,l,s),e(l,Hl,s),e(l,tl,s),e(l,zl,s),o(el,l,s),e(l,ql,s),e(l,al,s),e(l,Ll,s),o(nl,l,s),e(l,Pl,s),o(Ml,l,s),e(l,Dl,s),e(l,il,s),e(l,Kl,s),e(l,pl,s),e(l,Ol,s),e(l,yl,s),e(l,ls,s),e(l,ol,s),e(l,ss,s),o(wl,l,s),e(l,ts,s),e(l,jl,s),es=!0},p(l,[s]){const Bs={};s&2&&(Bs.$$scope={dirty:s,ctx:l}),C.$set(Bs)},i(l){es||(w(U.$$.fragment,l),w(A.$$.fragment,l),w(C.$$.fragment,l),w(W.$$.fragment,l),w($.$$.fragment,l),w(v.$$.fragment,l),w(E.$$.fragment,l),w(R.$$.fragment,l),w(X.$$.fragment,l),w(F.$$.fragment,l),w(S.$$.fragment,l),w(N.$$.fragment,l),w(V.$$.fragment,l),w(z.$$.fragment,l),w(L.$$.fragment,l),w(P.$$.fragment,l),w(K.$$.fragment,l),w(ll.$$.fragment,l),w(sl.$$.fragment,l),w(el.$$.fragment,l),w(nl.$$.fragment,l),w(Ml.$$.fragment,l),w(wl.$$.fragment,l),es=!0)},o(l){j(U.$$.fragment,l),j(A.$$.fragment,l),j(C.$$.fragment,l),j(W.$$.fragment,l),j($.$$.fragment,l),j(v.$$.fragment,l),j(E.$$.fragment,l),j(R.$$.fragment,l),j(X.$$.fragment,l),j(F.$$.fragment,l),j(S.$$.fragment,l),j(N.$$.fragment,l),j(V.$$.fragment,l),j(z.$$.fragment,l),j(L.$$.fragment,l),j(P.$$.fragment,l),j(K.$$.fragment,l),j(ll.$$.fragment,l),j(sl.$$.fragment,l),j(el.$$.fragment,l),j(nl.$$.fragment,l),j(Ml.$$.fragment,l),j(wl.$$.fragment,l),es=!1},d(l){l&&(t(r),t(u),t(d),t(I),t(b),t(Tl),t(g),t(Ul),t(B),t(ml),t(G),t(rl),t(hl),t(f),t(cl),t(Z),t(dl),t(ul),t(Il),t(Cl),t(k),t(bl),t(gl),t(Bl),t(x),t(Gl),t(Y),t(Al),t(fl),t(Zl),t(Wl),t($l),t(kl),t(vl),t(Q),t(El),t(_),t(xl),t(H),t(Yl),t(Rl),t(q),t(Xl),t(Fl),t(Sl),t(D),t(Nl),t(Vl),t(O),t(Ql),t(_l),t(Hl),t(tl),t(zl),t(ql),t(al),t(Ll),t(Pl),t(Dl),t(il),t(Kl),t(pl),t(Ol),t(yl),t(ls),t(ol),t(ss),t(ts),t(jl)),t(m),J(U,l),J(A,l),J(C,l),J(W,l),J($,l),J(v,l),J(E,l),J(R,l),J(X,l),J(F,l),J(S,l),J(N,l),J(V,l),J(z,l),J(L,l),J(P,l),J(K,l),J(ll,l),J(sl,l),J(el,l),J(nl,l),J(Ml,l),J(wl,l)}}}const Ss='{"title":"Document Analysis Graph","local":"document-analysis-graph","sections":[{"title":"The Butler’s Workflow","local":"the-butlers-workflow","sections":[],"depth":2},{"title":"Setting Up the environment","local":"setting-up-the-environment","sections":[],"depth":2},{"title":"Defining Agent’s State","local":"defining-agents-state","sections":[],"depth":2},{"title":"Preparing Tools","local":"preparing-tools","sections":[],"depth":2},{"title":"The nodes","local":"the-nodes","sections":[],"depth":2},{"title":"The ReAct Pattern: How I Assist Mr. Wayne","local":"the-react-pattern-how-i-assist-mr-wayne","sections":[],"depth":2},{"title":"The Butler in Action","local":"the-butler-in-action","sections":[{"title":"Example 1: Simple Calculations","local":"example-1-simple-calculations","sections":[],"depth":3},{"title":"Example 2: Analyzing Master Wayne’s Training Documents","local":"example-2-analyzing-master-waynes-training-documents","sections":[],"depth":3}],"depth":2},{"title":"Key Takeaways","local":"key-takeaways","sections":[],"depth":2}],"depth":1}';function Ns(Jl){return Ws(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ls extends ks{constructor(m){super(),vs(this,m,Ns,Fs,Zs,{})}}export{Ls as component};
