import{s as As,o as Zs,n as fs}from"../chunks/scheduler.889ebb13.js";import{S as Ws,i as $s,g as M,s as a,r as y,m as es,A as ks,h as i,f as t,c as n,j as Gs,u as p,x as T,n as as,k as ts,y as vs,a as e,v as o,d as w,t as j,w as J}from"../chunks/index.ca18042b.js";import{T as Es}from"../chunks/Tip.b8116e3c.js";import{C as h}from"../chunks/CodeBlock.1db71023.js";import{H as c}from"../chunks/Heading.3daa581c.js";import{E as xs}from"../chunks/EditOnGithub.2e95618d.js";function Ys(jl){let m,r,I="this notebook",d;return{c(){m=es("You can follow the code in "),r=M("a"),r.textContent=I,d=es(" that you can run using Google Colab."),this.h()},l(U){m=as(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=I),d=as(U," that you can run using Google Colab."),this.h()},h(){ts(r,"href","https://huggingface.co/agents-course/notebooks/blob/main/unit2/langgraph/agent.ipynb"),ts(r,"target","_blank")},m(U,u){e(U,m,u),e(U,r,u),e(U,d,u)},p:fs,d(U){U&&(t(m),t(r),t(d))}}}function Rs(jl){let m,r,I,d,U,u,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.",Jl,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.",Tl,B,is="For future such event, let’s create a document analysis system using LangGraph to serve Mister Wayne’s needs. This system can:",Ul,G,ys="<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>",ml,A,rl,Z,ps="The workflow we’ll build, follows a structured this schema:",hl,f,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"/>',cl,C,dl,W,Il,$,ws="and imports :",ul,k,Cl,v,bl,E,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,x,Js="This a new concept in langGraph, where, you can add operators in you state to define the way they should interact together.",Bl,Y,Gl,R,Al,X,Zl,F,fl,S,Wl,N,$l,V,Ts="Allow me to explain the approach in this agent. The agent follows what’s known as the ReAct pattern (Reason-Act-Observe)",kl,Q,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>",vl,_,ms="This is a simple implementation of an agent using langGraph.",El,H,xl,z,rs='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/Agent.png" alt="ReAct Pattern"/>',Yl,q,Rl,L,Xl,P,hs="In the following example, we added this divide example just as a",Fl,D,Sl,K,cs="The conversation would proceed:",Nl,O,Vl,ll,Ql,sl,ds="When Master Wayne leaves his training and meal notes:",_l,tl,Hl,el,Is="The interaction would proceed:",zl,al,ql,nl,Ll,Ml,us="Should you wish to create your own document analysis butler, here are key considerations:",Pl,il,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>",Dl,yl,bs="With these principles, you too can provide exemplary document analysis service worthy of Wayne Manor.",Kl,pl,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>",Ol,ol,ls,wl,ss;return U=new c({props:{title:"Document Analysis Graph",local:"document-analysis-graph",headingTag:"h1"}}),A=new c({props:{title:"The Butler’s Workflow",local:"the-butlers-workflow",headingTag:"h2"}}),C=new Es({props:{$$slots:{default:[Ys]},$$scope:{ctx:jl}}}),W=new h({props:{code:"JTI1cGlwJTIwaW5zdGFsbCUyMGxhbmdncmFwaCUyMGxhbmdjaGFpbl9vcGVuYWklMjBQaWxsb3clMjBiYXNlNjQlMjBsYW5nY2hhaW5fY29yZQ==",highlighted:"%pip install langgraph langchain_openai Pillow base64 langchain_core",wrap:!1}}),k=new h({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}}),v=new c({props:{title:"Defining Agent’s State",local:"defining-agents-state",headingTag:"h2"}}),Y=new h({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}}),R=new c({props:{title:"Preparing Tools",local:"preparing-tools",headingTag:"h2"}}),X=new h({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}}),F=new c({props:{title:"The nodes",local:"the-nodes",headingTag:"h2"}}),S=new h({props:{code:"ZGVmJTIwYXNzaXN0YW50KHN0YXRlJTNBJTIwQWdlbnRTdGF0ZSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBTeXN0ZW0lMjBtZXNzYWdlJTBBJTIwJTIwJTIwJTIwdGV4dHVhbF9kZXNjcmlwdGlvbl9vZl90b29sJTNEJTIyJTIyJTIyJTBBZXh0cmFjdF90ZXh0KGltZ19wYXRoJTNBJTIwc3RyKSUyMC0lM0UlMjBzdHIlM0ElMEElMjAlMjAlMjAlMjBFeHRyYWN0JTIwdGV4dCUyMGZyb20lMjBhbiUyMGltYWdlJTIwZmlsZSUyMHVzaW5nJTIwYSUyMG11bHRpbW9kYWwlMjBtb2RlbC4lMEElMEElMjAlMjAlMjAlMjBBcmdzJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW1nX3BhdGglM0ElMjBBJTIwbG9jYWwlMjBpbWFnZSUyMGZpbGUlMjBwYXRoJTIwKHN0cmluZ3MpLiUwQSUwQSUyMCUyMCUyMCUyMFJldHVybnMlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBBJTIwc2luZ2xlJTIwc3RyaW5nJTIwY29udGFpbmluZyUyMHRoZSUyMGNvbmNhdGVuYXRlZCUyMHRleHQlMjBleHRyYWN0ZWQlMjBmcm9tJTIwZWFjaCUyMGltYWdlLiUwQWRpdmlkZShhJTNBJTIwaW50JTJDJTIwYiUzQSUyMGludCklMjAtJTNFJTIwZmxvYXQlM0ElMEElMjAlMjAlMjAlMjBEaXZpZGUlMjBhJTIwYW5kJTIwYiUwQSUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMGltYWdlJTNEc3RhdGUlNUIlMjJpbnB1dF9maWxlJTIyJTVEJTBBJTIwJTIwJTIwJTIwc3lzX21zZyUyMCUzRCUyMFN5c3RlbU1lc3NhZ2UoY29udGVudCUzRGYlMjJZb3UlMjBhcmUlMjBhbiUyMGhlbHBmdWwlMjBidXRsZXIlMjBuYW1lZCUyMEFsZnJlZCUyMHRoYXQlMjBzZXJ2ZXMlMjBNci4lMjBXYXluZSUyMGFuZCUyMEJhdG1hbi4lMjBZb3UlMjBjYW4lMjBhbmFseXNlJTIwZG9jdW1lbnRzJTIwYW5kJTIwcnVuJTIwY29tcHV0YXRpb25zJTIwd2l0aCUyMHByb3ZpZGVkJTIwdG9vbHMlM0ElNUNuJTdCdGV4dHVhbF9kZXNjcmlwdGlvbl9vZl90b29sJTdEJTIwJTVDbiUyMFlvdSUyMGhhdmUlMjBhY2Nlc3MlMjB0byUyMHNvbWUlMjBvcHRpb25hbCUyMGltYWdlcy4lMjBDdXJyZW50bHklMjB0aGUlMjBsb2FkZWQlMjBpbWFnZSUyMGlzJTNBJTIwJTdCaW1hZ2UlN0QlMjIpJTBBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIybWVzc2FnZXMlMjIlM0ElMjAlNUJsbG1fd2l0aF90b29scy5pbnZva2UoJTVCc3lzX21zZyU1RCUyMCUyQiUyMHN0YXRlJTVCJTIybWVzc2FnZXMlMjIlNUQpJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyaW5wdXRfZmlsZSUyMiUzQSUyMHN0YXRlJTVCJTIyaW5wdXRfZmlsZSUyMiU1RCUwQSUyMCUyMCUyMCUyMCU3RA==",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}}),N=new c({props:{title:"The ReAct Pattern: How I Assist Mr. Wayne",local:"the-react-pattern-how-i-assist-mr-wayne",headingTag:"h2"}}),H=new h({props:{code:"JTIzJTIzJTIwVGhlJTIwZ3JhcGglMEFidWlsZGVyJTIwJTNEJTIwU3RhdGVHcmFwaChBZ2VudFN0YXRlKSUwQSUwQSUyMyUyMERlZmluZSUyMG5vZGVzJTNBJTIwdGhlc2UlMjBkbyUyMHRoZSUyMHdvcmslMEFidWlsZGVyLmFkZF9ub2RlKCUyMmFzc2lzdGFudCUyMiUyQyUyMGFzc2lzdGFudCklMEFidWlsZGVyLmFkZF9ub2RlKCUyMnRvb2xzJTIyJTJDJTIwVG9vbE5vZGUodG9vbHMpKSUwQSUwQSUyMyUyMERlZmluZSUyMGVkZ2VzJTNBJTIwdGhlc2UlMjBkZXRlcm1pbmUlMjBob3clMjB0aGUlMjBjb250cm9sJTIwZmxvdyUyMG1vdmVzJTBBYnVpbGRlci5hZGRfZWRnZShTVEFSVCUyQyUyMCUyMmFzc2lzdGFudCUyMiklMEFidWlsZGVyLmFkZF9jb25kaXRpb25hbF9lZGdlcyglMEElMjAlMjAlMjAlMjAlMjJhc3Npc3RhbnQlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjMlMjBJZiUyMHRoZSUyMGxhdGVzdCUyMG1lc3NhZ2UlMjByZXF1aXJlcyUyMGElMjB0b29sJTJDJTIwcm91dGUlMjB0byUyMHRvb2xzJTBBJTIwJTIwJTIwJTIwJTIzJTIwT3RoZXJ3aXNlJTJDJTIwcHJvdmlkZSUyMGElMjBkaXJlY3QlMjByZXNwb25zZSUwQSUyMCUyMCUyMCUyMHRvb2xzX2NvbmRpdGlvbiUyQyUwQSklMEFidWlsZGVyLmFkZF9lZGdlKCUyMnRvb2xzJTIyJTJDJTIwJTIyYXNzaXN0YW50JTIyKSUwQXJlYWN0X2dyYXBoJTIwJTNEJTIwYnVpbGRlci5jb21waWxlKCklMEElMEElMjMlMjBTaG93JTIwdGhlJTIwYnV0bGVyJ3MlMjB0aG91Z2h0JTIwcHJvY2VzcyUwQWRpc3BsYXkoSW1hZ2UocmVhY3RfZ3JhcGguZ2V0X2dyYXBoKHhyYXklM0RUcnVlKS5kcmF3X21lcm1haWRfcG5nKCkpKQ==",highlighted:`<span class="hljs-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}}),q=new c({props:{title:"The Butler in Action",local:"the-butler-in-action",headingTag:"h2"}}),L=new c({props:{title:"Example 1: Simple Calculations",local:"example-1-simple-calculations",headingTag:"h3"}}),D=new h({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}}),O=new h({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 c({props:{title:"Example 2: Analyzing Master Wayne’s Training Documents",local:"example-2-analyzing-master-waynes-training-documents",headingTag:"h3"}}),tl=new h({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}}),al=new h({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}}),nl=new c({props:{title:"Key Takeaways",local:"key-takeaways",headingTag:"h2"}}),ol=new xs({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/en/unit2/langgraph/document_analysis_agent.mdx"}}),{c(){m=M("meta"),r=a(),I=M("p"),d=a(),y(U.$$.fragment),u=a(),b=M("p"),b.textContent=ns,Jl=a(),g=M("p"),g.innerHTML=Ms,Tl=a(),B=M("p"),B.textContent=is,Ul=a(),G=M("ol"),G.innerHTML=ys,ml=a(),y(A.$$.fragment),rl=a(),Z=M("p"),Z.textContent=ps,hl=a(),f=M("p"),f.innerHTML=os,cl=a(),y(C.$$.fragment),dl=es(`
## Setting Up the environment

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

	`),p(W.$$.fragment,l),Il=n(l),$=i(l,"P",{"data-svelte-h":!0}),T($)!=="svelte-1ey17wx"&&($.textContent=ws),ul=n(l),p(k.$$.fragment,l),Cl=n(l),p(v.$$.fragment,l),bl=n(l),E=i(l,"P",{"data-svelte-h":!0}),T(E)!=="svelte-1d1vtsq"&&(E.textContent=js),gl=n(l),x=i(l,"P",{"data-svelte-h":!0}),T(x)!=="svelte-1d3cijs"&&(x.textContent=Js),Bl=n(l),p(Y.$$.fragment,l),Gl=n(l),p(R.$$.fragment,l),Al=n(l),p(X.$$.fragment,l),Zl=n(l),p(F.$$.fragment,l),fl=n(l),p(S.$$.fragment,l),Wl=n(l),p(N.$$.fragment,l),$l=n(l),V=i(l,"P",{"data-svelte-h":!0}),T(V)!=="svelte-18vru10"&&(V.textContent=Ts),kl=n(l),Q=i(l,"OL",{"data-svelte-h":!0}),T(Q)!=="svelte-1s296x7"&&(Q.innerHTML=Us),vl=n(l),_=i(l,"P",{"data-svelte-h":!0}),T(_)!=="svelte-7iqp0"&&(_.textContent=ms),El=n(l),p(H.$$.fragment,l),xl=n(l),z=i(l,"P",{"data-svelte-h":!0}),T(z)!=="svelte-1nhlurw"&&(z.innerHTML=rs),Yl=n(l),p(q.$$.fragment,l),Rl=n(l),p(L.$$.fragment,l),Xl=n(l),P=i(l,"P",{"data-svelte-h":!0}),T(P)!=="svelte-1ex6163"&&(P.textContent=hs),Fl=n(l),p(D.$$.fragment,l),Sl=n(l),K=i(l,"P",{"data-svelte-h":!0}),T(K)!=="svelte-eegy09"&&(K.textContent=cs),Nl=n(l),p(O.$$.fragment,l),Vl=n(l),p(ll.$$.fragment,l),Ql=n(l),sl=i(l,"P",{"data-svelte-h":!0}),T(sl)!=="svelte-k6gec7"&&(sl.textContent=ds),_l=n(l),p(tl.$$.fragment,l),Hl=n(l),el=i(l,"P",{"data-svelte-h":!0}),T(el)!=="svelte-gpwkjm"&&(el.textContent=Is),zl=n(l),p(al.$$.fragment,l),ql=n(l),p(nl.$$.fragment,l),Ll=n(l),Ml=i(l,"P",{"data-svelte-h":!0}),T(Ml)!=="svelte-17u0oai"&&(Ml.textContent=us),Pl=n(l),il=i(l,"OL",{"data-svelte-h":!0}),T(il)!=="svelte-1qddtr0"&&(il.innerHTML=Cs),Dl=n(l),yl=i(l,"P",{"data-svelte-h":!0}),T(yl)!=="svelte-1tc3qgy"&&(yl.textContent=bs),Kl=n(l),pl=i(l,"P",{"data-svelte-h":!0}),T(pl)!=="svelte-1ik86s0"&&(pl.innerHTML=gs),Ol=n(l),p(ol.$$.fragment,l),ls=n(l),wl=i(l,"P",{}),Gs(wl).forEach(t),this.h()},h(){ts(m,"name","hf:doc:metadata"),ts(m,"content",Xs)},m(l,s){vs(document.head,m),e(l,r,s),e(l,I,s),e(l,d,s),o(U,l,s),e(l,u,s),e(l,b,s),e(l,Jl,s),e(l,g,s),e(l,Tl,s),e(l,B,s),e(l,Ul,s),e(l,G,s),e(l,ml,s),o(A,l,s),e(l,rl,s),e(l,Z,s),e(l,hl,s),e(l,f,s),e(l,cl,s),o(C,l,s),e(l,dl,s),o(W,l,s),e(l,Il,s),e(l,$,s),e(l,ul,s),o(k,l,s),e(l,Cl,s),o(v,l,s),e(l,bl,s),e(l,E,s),e(l,gl,s),e(l,x,s),e(l,Bl,s),o(Y,l,s),e(l,Gl,s),o(R,l,s),e(l,Al,s),o(X,l,s),e(l,Zl,s),o(F,l,s),e(l,fl,s),o(S,l,s),e(l,Wl,s),o(N,l,s),e(l,$l,s),e(l,V,s),e(l,kl,s),e(l,Q,s),e(l,vl,s),e(l,_,s),e(l,El,s),o(H,l,s),e(l,xl,s),e(l,z,s),e(l,Yl,s),o(q,l,s),e(l,Rl,s),o(L,l,s),e(l,Xl,s),e(l,P,s),e(l,Fl,s),o(D,l,s),e(l,Sl,s),e(l,K,s),e(l,Nl,s),o(O,l,s),e(l,Vl,s),o(ll,l,s),e(l,Ql,s),e(l,sl,s),e(l,_l,s),o(tl,l,s),e(l,Hl,s),e(l,el,s),e(l,zl,s),o(al,l,s),e(l,ql,s),o(nl,l,s),e(l,Ll,s),e(l,Ml,s),e(l,Pl,s),e(l,il,s),e(l,Dl,s),e(l,yl,s),e(l,Kl,s),e(l,pl,s),e(l,Ol,s),o(ol,l,s),e(l,ls,s),e(l,wl,s),ss=!0},p(l,[s]){const Bs={};s&2&&(Bs.$$scope={dirty:s,ctx:l}),C.$set(Bs)},i(l){ss||(w(U.$$.fragment,l),w(A.$$.fragment,l),w(C.$$.fragment,l),w(W.$$.fragment,l),w(k.$$.fragment,l),w(v.$$.fragment,l),w(Y.$$.fragment,l),w(R.$$.fragment,l),w(X.$$.fragment,l),w(F.$$.fragment,l),w(S.$$.fragment,l),w(N.$$.fragment,l),w(H.$$.fragment,l),w(q.$$.fragment,l),w(L.$$.fragment,l),w(D.$$.fragment,l),w(O.$$.fragment,l),w(ll.$$.fragment,l),w(tl.$$.fragment,l),w(al.$$.fragment,l),w(nl.$$.fragment,l),w(ol.$$.fragment,l),ss=!0)},o(l){j(U.$$.fragment,l),j(A.$$.fragment,l),j(C.$$.fragment,l),j(W.$$.fragment,l),j(k.$$.fragment,l),j(v.$$.fragment,l),j(Y.$$.fragment,l),j(R.$$.fragment,l),j(X.$$.fragment,l),j(F.$$.fragment,l),j(S.$$.fragment,l),j(N.$$.fragment,l),j(H.$$.fragment,l),j(q.$$.fragment,l),j(L.$$.fragment,l),j(D.$$.fragment,l),j(O.$$.fragment,l),j(ll.$$.fragment,l),j(tl.$$.fragment,l),j(al.$$.fragment,l),j(nl.$$.fragment,l),j(ol.$$.fragment,l),ss=!1},d(l){l&&(t(r),t(I),t(d),t(u),t(b),t(Jl),t(g),t(Tl),t(B),t(Ul),t(G),t(ml),t(rl),t(Z),t(hl),t(f),t(cl),t(dl),t(Il),t($),t(ul),t(Cl),t(bl),t(E),t(gl),t(x),t(Bl),t(Gl),t(Al),t(Zl),t(fl),t(Wl),t($l),t(V),t(kl),t(Q),t(vl),t(_),t(El),t(xl),t(z),t(Yl),t(Rl),t(Xl),t(P),t(Fl),t(Sl),t(K),t(Nl),t(Vl),t(Ql),t(sl),t(_l),t(Hl),t(el),t(zl),t(ql),t(Ll),t(Ml),t(Pl),t(il),t(Dl),t(yl),t(Kl),t(pl),t(Ol),t(ls),t(wl)),t(m),J(U,l),J(A,l),J(C,l),J(W,l),J(k,l),J(v,l),J(Y,l),J(R,l),J(X,l),J(F,l),J(S,l),J(N,l),J(H,l),J(q,l),J(L,l),J(D,l),J(O,l),J(ll,l),J(tl,l),J(al,l),J(nl,l),J(ol,l)}}}const Xs='{"title":"Document Analysis Graph","local":"document-analysis-graph","sections":[{"title":"The Butler’s Workflow","local":"the-butlers-workflow","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 Fs(jl){return Zs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zs extends Ws{constructor(m){super(),$s(this,m,Fs,Rs,As,{})}}export{zs as component};
