Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"문서 분석 그래프","local":"document-analysis-graph","sections":[{"title":"집사의 워크플로우","local":"the-butlers-workflow","sections":[],"depth":2},{"title":"환경 설정","local":"setting-up-the-environment","sections":[],"depth":2},{"title":"에이전트 상태 정의","local":"defining-agent’s-state","sections":[],"depth":2},{"title":"툴 준비하기","local":"preparing-tools","sections":[],"depth":2},{"title":"노드","local":"the-nodes","sections":[],"depth":2},{"title":"ReAct 패턴: 집사의 지원 방식","local":"the-react-pattern-how-i-assist-mr-wayne","sections":[],"depth":2},{"title":"집사의 실제 활용 예시","local":"the-butler-in-action","sections":[{"title":"예시 1: 간단한 계산","local":"example-1-simple-calculations","sections":[],"depth":3},{"title":"예시 2: Wayne 주인님의 훈련 문서 분석","local":"example-2-analyzing-master-waynes-training-documents","sections":[],"depth":3}],"depth":2},{"title":"핵심 요약","local":"key-takeaways","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/agents-course/pr_673/ko/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/entry/start.4b87fc53.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/scheduler.cc52f4b9.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/singletons.57c73006.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/index.5033808a.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/paths.55e428b8.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/entry/app.a753447f.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/preload-helper.8c0a2f65.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/index.1e918bfb.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/nodes/0.8ef9eef5.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/nodes/26.1c93a18d.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/Tip.d0a39104.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/CopyLLMTxtMenu.b63a2943.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.0a16bc89.js"> | |
| <link rel="modulepreload" href="/docs/agents-course/pr_673/ko/_app/immutable/chunks/CodeBlock.81901540.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"문서 분석 그래프","local":"document-analysis-graph","sections":[{"title":"집사의 워크플로우","local":"the-butlers-workflow","sections":[],"depth":2},{"title":"환경 설정","local":"setting-up-the-environment","sections":[],"depth":2},{"title":"에이전트 상태 정의","local":"defining-agent’s-state","sections":[],"depth":2},{"title":"툴 준비하기","local":"preparing-tools","sections":[],"depth":2},{"title":"노드","local":"the-nodes","sections":[],"depth":2},{"title":"ReAct 패턴: 집사의 지원 방식","local":"the-react-pattern-how-i-assist-mr-wayne","sections":[],"depth":2},{"title":"집사의 실제 활용 예시","local":"the-butler-in-action","sections":[{"title":"예시 1: 간단한 계산","local":"example-1-simple-calculations","sections":[],"depth":3},{"title":"예시 2: Wayne 주인님의 훈련 문서 분석","local":"example-2-analyzing-master-waynes-training-documents","sections":[],"depth":3}],"depth":2},{"title":"핵심 요약","local":"key-takeaways","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="document-analysis-graph" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#document-analysis-graph"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>문서 분석 그래프</span></h1> <p data-svelte-h="svelte-cblthb">저 알프레드는 Mr.웨인님의 신뢰받는 집사로서, 그분의 다양한 문서 업무를 어떻게 지원할지 기록해두었습니다. 그가 밤 활동을 하러 나간 동안, 저는 모든 서류, 훈련 일정, 영양 계획을 분석하고 정리합니다.</p> <p data-svelte-h="svelte-viu86a">그분이 외출하기 전, 이번 주 훈련 프로그램이 적힌 쪽지를 남기셨습니다. 그 쪽지를 보고 저는 내일 식사를 위한 <strong>메뉴</strong>를 직접 짜기로 했죠.</p> <p data-svelte-h="svelte-fjtg1j">앞으로도 이런 일이 있을 때를 대비해, LangGraph를 활용해 웨인님을 위한 문서 분석 시스템을 만들어봅시다. 이 시스템은 다음을 수행 할 수 있습니다:</p> <ol data-svelte-h="svelte-adpod1"><li>이미지 문서 처리</li> <li>비전 모델(비전 언어 모델)로 텍스트 추출</li> <li>필요시 계산 수행(일반 툴 시연)</li> <li>내용 분석 및 요약 제공</li> <li>문서 관련 특정 지시 실행</li></ol> <h2 class="relative group"><a id="the-butlers-workflow" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-butlers-workflow"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>집사의 워크플로우</span></h2> <p data-svelte-h="svelte-jxgs08">만들 워크플로우의 구조는 다음과 같습니다:</p> <p data-svelte-h="svelte-14hs3l"><img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/alfred_flow.png" alt="집사의 문서 분석 워크플로우"></p> <blockquote class="tip"><a href="https://huggingface.co/agents-course/notebooks/blob/main/unit2/langgraph/agent.ipynb" target="_blank" data-svelte-h="svelte-98exwx">이 노트북</a>을 따라가며 Google Colab에서 코드를 실행해볼 수 있습니다.</blockquote> <h2 class="relative group"><a id="setting-up-the-environment" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#setting-up-the-environment"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>환경 설정</span></h2> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->%pip install langgraph langchain_openai langchain_core<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1jdgh3y">임포트 :</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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_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, HumanMessage | |
| <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> ToolNode, tools_condition | |
| <span class="hljs-keyword">from</span> IPython.display <span class="hljs-keyword">import</span> Image, display<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="defining-agent’s-state" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#defining-agent’s-state"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>에이전트 상태 정의</span></h2> <p data-svelte-h="svelte-1u9qk55">이 상태는 앞서 본 것보다 조금 더 복잡합니다. | |
| <code>AnyMessage</code>는 Langchain의 메시지 클래스이고, <code>add_messages</code>는 최신 메시지를 누적하는 연산자입니다.</p> <p data-svelte-h="svelte-g7ml96">LangGraph에서는 상태에 연산자를 추가해 상호작용 방식을 정의할 수 있습니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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"># 파일 경로(PDF/PNG)</span> | |
| messages: Annotated[<span class="hljs-built_in">list</span>[AnyMessage], add_messages]<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="preparing-tools" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#preparing-tools"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>툴 준비하기</span></h2> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->vision_llm = ChatOpenAI(model=<span class="hljs-string">"gpt-4o"</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>) -> <span class="hljs-built_in">str</span>: | |
| <span class="hljs-string">""" | |
| 멀티모달 모델로 이미지 파일에서 텍스트 추출 | |
| Wayne 주인님은 종종 훈련 일정이나 식단이 적힌 쪽지를 남깁니다. | |
| 이 기능으로 내용을 제대로 분석할 수 있습니다. | |
| """</span> | |
| all_text = <span class="hljs-string">""</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">"rb"</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">"utf-8"</span>) | |
| <span class="hljs-comment"># base64 이미지 데이터를 포함한 프롬프트 준비</span> | |
| message = [ | |
| HumanMessage( | |
| content=[ | |
| { | |
| <span class="hljs-string">"type"</span>: <span class="hljs-string">"text"</span>, | |
| <span class="hljs-string">"text"</span>: ( | |
| <span class="hljs-string">"이 이미지에서 모든 텍스트를 추출하세요. 설명 없이 추출된 텍스트만 반환하세요."</span> | |
| ), | |
| }, | |
| { | |
| <span class="hljs-string">"type"</span>: <span class="hljs-string">"image_url"</span>, | |
| <span class="hljs-string">"image_url"</span>: { | |
| <span class="hljs-string">"url"</span>: <span class="hljs-string">f"data:image/png;base64,<span class="hljs-subst">{image_base64}</span>"</span> | |
| }, | |
| }, | |
| ] | |
| ) | |
| ] | |
| <span class="hljs-comment"># 비전 모델 호출</span> | |
| response = vision_llm.invoke(message) | |
| <span class="hljs-comment"># 추출된 텍스트 추가</span> | |
| all_text += response.content + <span class="hljs-string">"\n\n"</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"텍스트 추출 오류: <span class="hljs-subst">{<span class="hljs-built_in">str</span>(e)}</span>"</span> | |
| <span class="hljs-built_in">print</span>(error_msg) | |
| <span class="hljs-keyword">return</span> <span class="hljs-string">""</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>) -> <span class="hljs-built_in">float</span>: | |
| <span class="hljs-string">"""주인님의 계산 요청을 위한 나눗셈 함수"""</span> | |
| <span class="hljs-keyword">return</span> a / b | |
| <span class="hljs-comment"># 집사, 도구(tool) 장착</span> | |
| tools = [ | |
| divide, | |
| extract_text | |
| ] | |
| llm = ChatOpenAI(model=<span class="hljs-string">"gpt-4o"</span>) | |
| llm_with_tools = llm.bind_tools(tools, parallel_tool_calls=<span class="hljs-literal">False</span>)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="the-nodes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-nodes"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>노드</span></h2> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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">""" | |
| extract_text(img_path: str) -> str: | |
| 멀티모달 모델로 이미지 파일에서 텍스트 추출 | |
| Args: | |
| img_path: 로컬 이미지 파일 경로(문자열) | |
| Returns: | |
| 각 이미지에서 추출된 텍스트를 합친 문자열 | |
| divide(a: int, b: int) -> float: | |
| a를 b로 나눔 | |
| """</span> | |
| image=state[<span class="hljs-string">"input_file"</span>] | |
| sys_msg = SystemMessage(content=<span class="hljs-string">f"당신은 Mr. Wayne과 배트맨을 섬기는 친절한 집사 알프레드입니다. 아래 도구로 문서를 분석하고 계산을 수행할 수 있습니다:\n<span class="hljs-subst">{textual_description_of_tool}</span> \n 현재 로드된 이미지는: <span class="hljs-subst">{image}</span>"</span>) | |
| <span class="hljs-keyword">return</span> { | |
| <span class="hljs-string">"messages"</span>: [llm_with_tools.invoke([sys_msg] + state[<span class="hljs-string">"messages"</span>])], | |
| <span class="hljs-string">"input_file"</span>: state[<span class="hljs-string">"input_file"</span>] | |
| }<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="the-react-pattern-how-i-assist-mr-wayne" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-react-pattern-how-i-assist-mr-wayne"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>ReAct 패턴: 집사의 지원 방식</span></h2> <p data-svelte-h="svelte-tooonh">이 에이전트는 ReAct 패턴(Reason-Act-Observe)을 따릅니다.</p> <ol data-svelte-h="svelte-1lff9t0"><li>문서와 요청을 <strong>이해(Reason)</strong></li> <li>적절한 도구를 <strong>실행(Act)</strong></li> <li>결과를 <strong>관찰(Observe)</strong></li> <li>필요시 반복</li></ol> <p data-svelte-h="svelte-1ys4ip3">아주 간단한 LangGraph 에이전트 구현 예시입니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># 그래프 생성</span> | |
| builder = StateGraph(AgentState) | |
| <span class="hljs-comment"># 노드 정의: 실제 작업을 수행</span> | |
| builder.add_node(<span class="hljs-string">"assistant"</span>, assistant) | |
| builder.add_node(<span class="hljs-string">"tools"</span>, ToolNode(tools)) | |
| <span class="hljs-comment"># 엣지 정의: 제어 흐름 결정</span> | |
| builder.add_edge(START, <span class="hljs-string">"assistant"</span>) | |
| builder.add_conditional_edges( | |
| <span class="hljs-string">"assistant"</span>, | |
| <span class="hljs-comment"># 최신 메시지가 도구를 필요로 하면 tools로 라우팅</span> | |
| <span class="hljs-comment"># 아니면 직접 응답</span> | |
| tools_condition, | |
| ) | |
| builder.add_edge(<span class="hljs-string">"tools"</span>, <span class="hljs-string">"assistant"</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()))<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1f8sc1n"><code>tools</code> 노드는 도구 리스트를, <code>assistant</code> 노드는 도구가 바인딩된 모델을 의미합니다. | |
| 그래프에는 <code>assistant</code>와 <code>tools</code> 노드가 있습니다.</p> <p data-svelte-h="svelte-bkefn0"><code>tools_condition</code> 엣지는 모델이 도구를 호출하면 tools로, 아니면 End로 흐름을 보냅니다.</p> <p data-svelte-h="svelte-gw4r0l">이제 한 단계 더 추가합니다:</p> <p data-svelte-h="svelte-1ufie4w"><code>tools</code> 노드를 다시 <code>assistant</code>로 연결해 루프를 만듭니다.</p> <ul data-svelte-h="svelte-1raxzab"><li><code>assistant</code> 노드 실행 후, <code>tools_condition</code>이 모델 출력이 도구 호출인지 확인합니다.</li> <li>도구 호출이면 흐름이 <code>tools</code> 노드로 이동합니다.</li> <li><code>tools</code> 노드는 다시 <code>assistant</code>로 연결됩니다.</li> <li>이 루프는 모델이 도구 호출을 결정하는 한 계속됩니다.</li> <li>모델 응답이 도구 호출이 아니면 흐름이 END로 이동해 프로세스가 종료됩니다.</li></ul> <p data-svelte-h="svelte-s4mege"><img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/LangGraph/Agent.png" alt="ReAct 패턴"></p> <h2 class="relative group"><a id="the-butler-in-action" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-butler-in-action"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>집사의 실제 활용 예시</span></h2> <h3 class="relative group"><a id="example-1-simple-calculations" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#example-1-simple-calculations"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>예시 1: 간단한 계산</span></h3> <p data-svelte-h="svelte-zt9lue">아래는 LangGraph에서 도구를 사용하는 간단한 예시입니다.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->messages = [HumanMessage(content=<span class="hljs-string">"6790을 5로 나눠줘"</span>)] | |
| messages = react_graph.invoke({<span class="hljs-string">"messages"</span>: messages, <span class="hljs-string">"input_file"</span>: <span class="hljs-literal">None</span>}) | |
| <span class="hljs-comment"># 메시지 출력</span> | |
| <span class="hljs-keyword">for</span> m <span class="hljs-keyword">in</span> messages[<span class="hljs-string">'messages'</span>]: | |
| m.pretty_print()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-yds0rq">대화 예시:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-attribute">Human</span>: <span class="hljs-number">6790</span>을 <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>: <span class="hljs-number">6790</span>을 <span class="hljs-number">5</span>로 나누면 <span class="hljs-number">1358</span>.<span class="hljs-number">0</span>입니다.<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="example-2-analyzing-master-waynes-training-documents" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#example-2-analyzing-master-waynes-training-documents"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>예시 2: Wayne 주인님의 훈련 문서 분석</span></h3> <p data-svelte-h="svelte-16iv0k1">주인님이 훈련 및 식단 쪽지를 남겼을 때:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->messages = [HumanMessage(content=<span class="hljs-string">"제공된 이미지에 있는 Wayne 주인님의 쪽지에 따라 저녁 메뉴에 필요한 재료 목록을 알려줘."</span>)] | |
| messages = react_graph.invoke({<span class="hljs-string">"messages"</span>: messages, <span class="hljs-string">"input_file"</span>: <span class="hljs-string">"Batman_training_and_meals.png"</span>})<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-yds0rq">대화 예시:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->Human: 제공된 이미지에 있는 Wayne 주인님의 쪽지에 따라 저녁 메뉴에 필요한 재료 목록을 알려줘. | |
| AI<span class="hljs-built_in"> Tool </span>Call: extract_text(<span class="hljs-attribute">img_path</span>=<span class="hljs-string">"Batman_training_and_meals.png"</span>) | |
| <span class="hljs-built_in"> | |
| Tool </span>Response: [훈련 일정 및 메뉴 세부 정보가 추출됨] | |
| Alfred: 저녁 메뉴를 위해 다음 재료를 구입하세요: | |
| 1. 목초 사육 소고기 등심 스테이크 | |
| 2. 유기농 시금치 | |
| 3. 피키요 고추 | |
| 4. 감자(오븐에 구울 허브 감자용) | |
| 5. 피쉬 오일(2그램) | |
| 스테이크는 목초 사육, 시금치와 고추는 유기농으로 준비하면 최고의 식사가 됩니다.<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="key-takeaways" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#key-takeaways"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>핵심 요약</span></h2> <p data-svelte-h="svelte-orjj0w">나만의 문서 분석 집사를 만들고 싶다면 다음을 고려하세요:</p> <ol data-svelte-h="svelte-sqycpg"><li><strong>문서 관련 작업별로 명확한 도구 정의</strong></li> <li><strong>도구 호출 간 맥락 유지를 위한 견고한 상태 추적기</strong></li> <li><strong>도구 실패 시 오류 처리 고려</strong></li> <li><strong>이전 상호작용 맥락 유지(add_messages 연산자 활용)</strong></li></ol> <p data-svelte-h="svelte-16civ19">이 원칙을 따르면 Wayne 저택에 어울리는 문서 분석 서비스를 제공할 수 있습니다.</p> <p data-svelte-h="svelte-w2j95j"><em>이 설명이 도움이 되었길 바랍니다. 이제 주인님의 망토를 다림질하러 가보겠습니다.</em></p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/agents-course/blob/main/units/ko/unit2/langgraph/document_analysis_agent.mdx" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_1wfgh18 = { | |
| assets: "/docs/agents-course/pr_673/ko", | |
| base: "/docs/agents-course/pr_673/ko", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/agents-course/pr_673/ko/_app/immutable/entry/start.4b87fc53.js"), | |
| import("/docs/agents-course/pr_673/ko/_app/immutable/entry/app.a753447f.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 26], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 48.1 kB
- Xet hash:
- 4c76a2cc60ae4f678738bfff93575ded5f9e0d746d121c0bab93d35aa80fd738
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.