Buckets:

hf-doc-build/doc / cookbook /main /ko /multiagent_web_assistant.html
rtrm's picture
download
raw
36 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;다중 에이전트 계층 구조에서 여러 에이전트가 협업하도록 하기&quot;,&quot;local&quot;:&quot;다중-에이전트-계층-구조에서-여러-에이전트가-협업하도록-하기&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;🔍 웹 검색 도구 만들기&quot;,&quot;local&quot;:&quot;-웹-검색-도구-만들기&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;다중 에이전트 시스템 구축하기 🤖🤝🤖&quot;,&quot;local&quot;:&quot;다중-에이전트-시스템-구축하기-&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}">
<link href="/docs/cookbook/main/ko/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/entry/start.4b65b044.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/scheduler.e0212c12.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/singletons.a4069010.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/paths.d649b3de.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/entry/app.b90033ef.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/preload-helper.1e412078.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/index.a585a37c.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/nodes/0.64193f5f.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/nodes/9.bdc37ae9.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.2ba1ebea.js">
<link rel="modulepreload" href="/docs/cookbook/main/ko/_app/immutable/chunks/DocNotebookDropdown.26e1fda8.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;다중 에이전트 계층 구조에서 여러 에이전트가 협업하도록 하기&quot;,&quot;local&quot;:&quot;다중-에이전트-계층-구조에서-여러-에이전트가-협업하도록-하기&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;🔍 웹 검색 도구 만들기&quot;,&quot;local&quot;:&quot;-웹-검색-도구-만들기&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;다중 에이전트 시스템 구축하기 🤖🤝🤖&quot;,&quot;local&quot;:&quot;다중-에이전트-시스템-구축하기-&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="flex space-x-1 absolute z-10 right-0 top-0" style=""> <a href="https://colab.research.google.com/github/huggingface/cookbook/blob/main/notebooks/ko/multiagent_web_assistant.ipynb" target="_blank"><img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"></a> </div> <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="다중-에이전트-계층-구조에서-여러-에이전트가-협업하도록-하기" 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="#다중-에이전트-계층-구조에서-여러-에이전트가-협업하도록-하기"><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-151a8cs"><em>작성자: <a href="https://huggingface.co/m-ric" rel="nofollow">Aymeric Roucher</a>, 번역: <a href="https://github.com/harheem" rel="nofollow">김하림</a></em></p> <blockquote data-svelte-h="svelte-1jzmr1c"><p>이 튜토리얼은 고급 수준이므로, 시작하기 전에 <a href="agents">이 에이전트 쿡북</a>에서 다루는 기본 개념을 알고가는 것이 좋습니다!</p></blockquote> <p data-svelte-h="svelte-1rq6psu">우리는 이 노트북에서 <strong>다중 에이전트 웹 브라우저를 만들 것입니다. 여러 에이전트가 웹을 사용하여 문제를 해결하기 위해 협업하는 에이전트 시스템입니다!</strong></p> <p data-svelte-h="svelte-1cm8dk5">이 시스템은 간단한 계층 구조로 되어있습니다. 여기서 <code>ManagedAgent</code> 객체를 사용하여 웹 검색 에이전트를 관리합니다. 이 구조를 통해 웹 검색 에이전트의 기능을 효과적으로 제어하고 조정할 수 있습니다.</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-string"> 관리자 에이전트 </span>|
+-----------------+
|<span class="hljs-string">
_______________</span>|______________
|<span class="hljs-string"> </span>|
코드 인터프리터 +--------------------------------+
도구 |<span class="hljs-string"> 관리되는 에이전트 </span>|
|<span class="hljs-string"> +------------------+ </span>|
|<span class="hljs-string"> </span>|<span class="hljs-string"> 웹 검색 에이전트 </span>|<span class="hljs-string"> </span>|
|<span class="hljs-string"> +------------------+ </span>|
|<span class="hljs-string"> </span>|<span class="hljs-string"> </span>|<span class="hljs-string"> </span>|
|<span class="hljs-string"> 웹 검색 도구 </span>|<span class="hljs-string"> </span>|
|<span class="hljs-string"> 웹페이지 방문 도구 </span>|
+--------------------------------+
<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1qh6bl4">환경 구성부터 시작해보겠습니다.</p> <p data-svelte-h="svelte-1mqxkgx">다음 명령어를 실행하여 필요한 패키지를 설치하세요.</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 -->!pip install markdownify duckduckgo-search <span class="hljs-string">&quot;transformers[agents]&quot;</span> --upgrade -q<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-uc9qvf">Hugging Face Hub API를 사용하기 위해서는 로그인이 필요합니다.</p> <p data-svelte-h="svelte-1y3bx5h">아래 코드를 실행하여 로그인해주세요.</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">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login
notebook_login()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-8qemab">⚡️ 우리의 에이전트는 <a href="https://huggingface.co/Qwen/Qwen2.5-72B-Instruct" rel="nofollow">Qwen/Qwen2.5-72B-Instruct</a> 모델을 사용합니다. 이 모델은 <code>HfApiEngine</code> 클래스를 통해 Hugging Face의 Inference API로 호출됩니다. Inference API를 활용하면 다양한 오픈 소스 모델을 빠르고 쉽게 실행할 수 있습니다.</p> <p data-svelte-h="svelte-d3h3oh"><em>Note:</em> Inference API는 다양한 기준에 따라 모델을 호스팅하며, 배포된 모델은 사전 통지 없이 업데이트되거나 교체될 수 있으므로 <a href="https://huggingface.co/docs/api-inference/supported-models" rel="nofollow">여기</a>에서 자세한 내용을 확인해보세요.</p> <p data-svelte-h="svelte-9blwox"><em>역주:</em> 이 노트북을 실행하려면 Hugging Face에서 발급받은 HF_TOKEN을 Google Colab의 보안 변수(Secrets)로 등록해야 합니다. 또한, 여기서 사용되는 모델들은 Hugging Face의 Pro 구독이 필요합니다. 무료 계정으로는 접근이 제한될 수 있으니 주의해 주세요.</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 -->model = <span class="hljs-string">&quot;Qwen/Qwen2.5-72B-Instruct&quot;</span><!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="-웹-검색-도구-만들기" 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="#-웹-검색-도구-만들기"><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></h3> <p data-svelte-h="svelte-1d96w2l">웹 브라우징을 위해 우리는 기존에 있는 <a href="https://github.com/huggingface/transformers/blob/main/src/transformers/agents/search.py" rel="nofollow"><code>DuckDuckGoSearchTool</code></a> 도구를 사용할 것입니다. 이 도구는 Google 검색과 비슷한 기능을 제공합니다.</p> <p data-svelte-h="svelte-a9vu1x">그러나 <code>DuckDuckGoSearchTool</code>이 찾은 웹페이지의 내용을 자세히 볼 수 있는 기능도 필요합니다.
이를 위해 라이브러리에 있는 <code>VisitWebpageTool</code>을 사용할 수도 있지만, 우리는 이 도구를 직접 만들어보며 그 과정을 이해해 보려고 합니다.</p> <p data-svelte-h="svelte-3svhn6">그래서 <code>markdownify</code>를 사용하여 <code>VisitWebpageTool</code> 도구를 처음부터 만들어 보도록 하겠습니다.</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> re
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> markdownify <span class="hljs-keyword">import</span> markdownify <span class="hljs-keyword">as</span> md
<span class="hljs-keyword">from</span> requests.exceptions <span class="hljs-keyword">import</span> RequestException
<span class="hljs-keyword">from</span> transformers.agents <span class="hljs-keyword">import</span> tool
<span class="hljs-keyword">from</span> urllib.parse <span class="hljs-keyword">import</span> unquote
<span class="hljs-meta">@tool</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">visit_webpage</span>(<span class="hljs-params">url: <span class="hljs-built_in">str</span></span>) -&gt; <span class="hljs-built_in">str</span>:
<span class="hljs-string">&quot;&quot;&quot;주어진 URL 웹페이지를 방문하고 그 내용을 마크다운 문자열로 반환합니다.
Args:
url: 방문할 웹페이지의 URL
Returns:
마크다운으로 변환된 웹페이지 내용, 또는 요청 실패 시 오류 메시지
&quot;&quot;&quot;</span>
<span class="hljs-keyword">try</span>:
<span class="hljs-comment"># URL로 GET 요청 보내기</span>
response = requests.get(url)
response.raise_for_status() <span class="hljs-comment"># 잘못된 상태 코드에 대한 예외 처리</span>
<span class="hljs-comment"># HTML 내용을 마크다운으로 변환하기</span>
markdown_content = md(response.text).strip()
<span class="hljs-comment"># 중복된 개행 문자 제거하기</span>
markdown_content = re.sub(<span class="hljs-string">r&quot;\n{3,}&quot;</span>, <span class="hljs-string">&quot;\n\n&quot;</span>, markdown_content)
<span class="hljs-comment"># URL 디코딩하기</span>
markdown_content = re.sub(<span class="hljs-string">r&#x27;\((.*?)\)&#x27;</span>, <span class="hljs-keyword">lambda</span> m: <span class="hljs-string">&#x27;(&#x27;</span> + unquote(m.group(<span class="hljs-number">1</span>)) + <span class="hljs-string">&#x27;)&#x27;</span>, markdown_content)
<span class="hljs-keyword">return</span> markdown_content
<span class="hljs-keyword">except</span> RequestException <span class="hljs-keyword">as</span> e:
<span class="hljs-keyword">return</span> <span class="hljs-string">f&quot;웹페이지 가져오기 오류: <span class="hljs-subst">{<span class="hljs-built_in">str</span>(e)}</span>&quot;</span>
<span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
<span class="hljs-keyword">return</span> <span class="hljs-string">f&quot;예상치 못한 오류 발생: <span class="hljs-subst">{<span class="hljs-built_in">str</span>(e)}</span>&quot;</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-54f9ee">이제, 우리의 도구를 테스트해봅시다!</p> <p data-svelte-h="svelte-1330jez"><em>역주:</em> 한글이 포함된 URL의 디코딩을 처리하기 위해 코드를 추가하였습니다.</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-meta">&gt;&gt;&gt; </span><span class="hljs-built_in">print</span>(visit_webpage(<span class="hljs-string">&quot;https://ko.wikipedia.org/wiki/Hugging_Face&quot;</span>)[:<span class="hljs-number">500</span>])<!-- HTML_TAG_END --></pre></div> <pre data-svelte-h="svelte-1mmwo4j">허깅 페이스 \- 위키백과, 우리 모두의 백과사전
[본문으로 이동](#bodyContent)
주 메뉴
주 메뉴
사이드바로 이동
숨기기
둘러보기
* [대문](/wiki/위키백과:대문 &quot;대문으로 가기 [z]&quot;)
* [최근 바뀜](/wiki/특수:최근바뀜 &quot;위키의 최근 바뀐 목록 [r]&quot;)
* [요즘 화제](/wiki/포털:요즘_화제 &quot;최근의 소식 알아 보기&quot;)
* [임의의 문서로](/wiki/특수:임의문서 &quot;무작위로 선택된 문서 불러오기 [x]&quot;)
사용자 모임
* [사랑방](/wiki/위키백과:사랑방)
* [사용자 모임](/wiki/위키백과:사용자_모임 &quot;위키백과 참여자를 위한 토론/대화 공간입니다.&quot;)
* [관리 요청](/wiki/위키백과:요청)
편집 안내
* [소개](/wiki/도움말:소개)
* [도움말](/wiki/위키백과:도움말 &quot;도움말&quot;)
* [정책과 지침](/wiki/위키백과:정책과_지침)
* [질문방](/wiki/위키백과:질문방)
[![](
</pre> <h2 class="relative group"><a id="다중-에이전트-시스템-구축하기-" 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="#다중-에이전트-시스템-구축하기-"><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-1l9poz6">이제 <code>search</code><code>visit_webpage</code> 도구를 모두 갖추었으니, 이를 이용해 웹 에이전트를 만들 수 있습니다.</p> <p data-svelte-h="svelte-1o9d5th">이 에이전트를 어떻게 구성하는 것이 좋을까요?</p> <ul data-svelte-h="svelte-12g3itt"><li>웹 브라우징은 병렬 도구 호출이 필요 없는 단일 타임라인 작업이므로, JSON 도구 호출이 적합합니다. 따라서 <code>ReactJsonAgent</code>를 선택합니다.</li> <li>또한, 웹 검색은 때때로 정확한 답변을 찾기 위해 여러 페이지를 탐색해야 할 수 있으므로, <code>max_iterations</code>를 10으로 늘리는 것이 좋습니다.</li></ul> <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">from</span> transformers.agents <span class="hljs-keyword">import</span> (
ReactCodeAgent,
ReactJsonAgent,
HfApiEngine,
ManagedAgent,
)
<span class="hljs-keyword">from</span> transformers.agents.search <span class="hljs-keyword">import</span> DuckDuckGoSearchTool
llm_engine = HfApiEngine(model)
web_agent = ReactJsonAgent(
tools=[DuckDuckGoSearchTool(), visit_webpage],
llm_engine=llm_engine,
max_iterations=<span class="hljs-number">10</span>,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-12x4qmq">그런 다음 이 웹 검색 에이전트를 <code>ManagedAgent</code>로 감싸줍니다. 이렇게 하면 상위의 관리자 에이전트가 이 에이전트를 쉽게 제어할 수 있습니다.</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 -->managed_web_agent = ManagedAgent(
agent=web_agent,
name=<span class="hljs-string">&quot;search&quot;</span>,
description=<span class="hljs-string">&quot;Runs web searches for you. Give it your query as an argument.&quot;</span>,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1edug1w">이제 관리자 에이전트를 생성합니다. 이때 <code>managed_agents</code> 매개변수에 우리가 만든 관리 받는 에이전트를 전달합니다.</p> <p data-svelte-h="svelte-n9p3mq">관리자 에이전트는 전체적인 계획 수립과 복잡한 사고를 담당해야 하므로, 고급 추론 능력이 필요합니다. 이런 이유로 <code>ReactCodeAgent</code>를 사용하는 것이 가장 적합할 것 같습니다.</p> <p data-svelte-h="svelte-gnjyuk">마지막으로, 현재 연도와 관련된 질문을 처리하기 위해 <code>additional_authorized_imports=[&quot;time&quot;, &quot;datetime&quot;]</code>을 설정에 추가합니다. 이렇게 하면 에이전트가 시간과 관련 정보를 다룰 수 있게 됩니다.</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 -->manager_agent = ReactCodeAgent(
tools=[],
llm_engine=llm_engine,
managed_agents=[managed_web_agent],
additional_authorized_imports=[<span class="hljs-string">&quot;time&quot;</span>, <span class="hljs-string">&quot;datetime&quot;</span>],
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-iplqe1">이것으로 모든 준비가 끝났습니다! 이제 우리의 시스템을 실행해봅시다.
계산이 필요한 질문을 던져보겠습니다.</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 -->manager_agent.run(<span class="hljs-string">&quot;Stripe는 몇 년 전에 설립되었나요?&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1c1jqbg">이렇게 에이전트들이 협력하여 과제를 해결했습니다! ✅</p> <p data-svelte-h="svelte-1n4xu6m">💡 이 시스템은 쉽게 더 많은 에이전트로 확장될 수 있습니다. 예를 들어, 한 에이전트는 코드 실행을 담당하고, 다른 에이전트는 웹 검색을, 또 다른 에이전트는 파일 로딩을 처리하는 식으로 말이죠.</p> <p data-svelte-h="svelte-id0r8g">🤔💭 더 나아가 복잡한 트리 구조의 계층을 생각해볼 수도 있습니다. 최고 경영자(CEO) 에이전트가 여러 중간 관리자를 관리하고, 각 중간 관리자는 다시 여러 부하 직원을 관리하는 구조를 만들 수 있죠.</p> <p data-svelte-h="svelte-12eyo28">심지어 더 많은 중간 관리 계층을 추가하고, 매일 여러 번의 회의를 하고, 스크럼 마스터와 함께 애자일 방식을 도입할 수도 있습니다. 그리고 각 새로운 구성 요소는 충분한 마찰을 추가하여 결국 아무 일도 완수되지 않도록 할 수 있겠죠… 음, 잠깐만요. 그건 아니겠네요. 우리의 단순한 구조를 유지하는 것이 좋겠습니다.</p> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/cookbook/blob/main/notebooks/ko/multiagent_web_assistant.md" 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_1d6oska = {
assets: "/docs/cookbook/main/ko",
base: "/docs/cookbook/main/ko",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/cookbook/main/ko/_app/immutable/entry/start.4b65b044.js"),
import("/docs/cookbook/main/ko/_app/immutable/entry/app.b90033ef.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 9],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
36 kB
·
Xet hash:
95b41ecca9556a65fe20e7a6760e0630e84c42cd8c81c07fab58b9ddb2883297

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.