Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"에이전트 안내서","local":"agents---guided-tour","sections":[{"title":"에이전트 유형 선택: CodeAgent 또는 ToolCallingAgent","local":"choosing-an-agent-type:-codeagent-or-toolcallingagent","sections":[],"depth":2},{"title":"CodeAgent","local":"codeagent","sections":[{"title":"ToolCallingAgent","local":"toolcallingagent","sections":[],"depth":3}],"depth":2},{"title":"에이전트 구축","local":"building-your-agent","sections":[],"depth":2},{"title":"고급 에이전트 구성","local":"advanced-agent-configuration","sections":[{"title":"에이전트 종료 조건 맞춤 설정","local":"customizing-agent-termination-conditions","sections":[],"depth":3}],"depth":2},{"title":"에이전트 실행 검사","local":"inspecting-an-agent-run","sections":[],"depth":2},{"title":"도구","local":"tools","sections":[{"title":"기본 툴박스","local":"default-toolbox","sections":[],"depth":3},{"title":"새로운 도구 생성","local":"create-a-new-tool","sections":[],"depth":3}],"depth":2},{"title":"멀티 에이전트","local":"multi-agents","sections":[],"depth":2},{"title":"에이전트와 대화하고 멋진 Gradio 인터페이스에서 그 사고 과정을 시각화하기","local":"talk-with-your-agent-and-visualize-its-thoughts-in-a-cool-gradio-interface","sections":[],"depth":2},{"title":"다음 단계","local":"next-steps","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/smolagents/pr_2321/ko/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/entry/start.ca84f914.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/scheduler.00b97157.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/singletons.267d4408.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/index.78ea7f15.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/paths.c73d3216.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/entry/app.e212187f.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/preload-helper.ac32094c.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/index.a7c1a7a1.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/nodes/0.34d24179.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/nodes/10.4daff017.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.e24d3ba9.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/CodeBlock.418b5eaa.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/DocNotebookDropdown.be7b60e3.js"> | |
| <link rel="modulepreload" href="/docs/smolagents/pr_2321/ko/_app/immutable/chunks/HfOption.e2d9e702.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"에이전트 안내서","local":"agents---guided-tour","sections":[{"title":"에이전트 유형 선택: CodeAgent 또는 ToolCallingAgent","local":"choosing-an-agent-type:-codeagent-or-toolcallingagent","sections":[],"depth":2},{"title":"CodeAgent","local":"codeagent","sections":[{"title":"ToolCallingAgent","local":"toolcallingagent","sections":[],"depth":3}],"depth":2},{"title":"에이전트 구축","local":"building-your-agent","sections":[],"depth":2},{"title":"고급 에이전트 구성","local":"advanced-agent-configuration","sections":[{"title":"에이전트 종료 조건 맞춤 설정","local":"customizing-agent-termination-conditions","sections":[],"depth":3}],"depth":2},{"title":"에이전트 실행 검사","local":"inspecting-an-agent-run","sections":[],"depth":2},{"title":"도구","local":"tools","sections":[{"title":"기본 툴박스","local":"default-toolbox","sections":[],"depth":3},{"title":"새로운 도구 생성","local":"create-a-new-tool","sections":[],"depth":3}],"depth":2},{"title":"멀티 에이전트","local":"multi-agents","sections":[],"depth":2},{"title":"에이전트와 대화하고 멋진 Gradio 인터페이스에서 그 사고 과정을 시각화하기","local":"talk-with-your-agent-and-visualize-its-thoughts-in-a-cool-gradio-interface","sections":[],"depth":2},{"title":"다음 단계","local":"next-steps","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> <div class="flex space-x-1 " style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Colab" class="!m-0" src="https://colab.research.google.com/assets/colab-badge.svg"> </button> </div> <div class="relative colab-dropdown "> <button class=" " type="button"> <img alt="Open In Studio Lab" class="!m-0" src="https://studiolab.sagemaker.aws/studiolab.svg"> </button> </div></div> <h1 class="relative group"><a id="agents---guided-tour" 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="#agents---guided-tour"><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-19amz7s">이 안내서에서는 에이전트를 구축하는 방법, 실행하는 방법, 그리고 사용 사례에 맞게 더 잘 작동하도록 맞춤 설정하는 방법을 학습합니다.</p> <h2 class="relative group"><a id="choosing-an-agent-type:-codeagent-or-toolcallingagent" 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="#choosing-an-agent-type:-codeagent-or-toolcallingagent"><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>에이전트 유형 선택: CodeAgent 또는 ToolCallingAgent</span></h2> <p data-svelte-h="svelte-hk4w5e"><code>smolagents</code>는 <a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.CodeAgent">CodeAgent</a>와 <a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.ToolCallingAgent">ToolCallingAgent</a> 두 가지 에이전트 클래스를 제공하는데, 이 두 클래스는 각각 에이전트가 도구와 상호작용하는 방법이 다릅니다. | |
| 두 방식의 핵심 차이점은 ‘액션을 지정하고 실행’하는 방식에 있습니다: 코드 생성 vs 구조화된 도구 호출.</p> <ul><li><p data-svelte-h="svelte-r6hljf"><a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.CodeAgent">CodeAgent</a>는 도구 호출을 Python 코드 스니펫으로 생성합니다.</p> <ul><li data-svelte-h="svelte-qv49g4">코드는 로컬에서 실행되거나(잠재적으로 불안전) 보안 샌드박스에서 실행됩니다.</li> <li data-svelte-h="svelte-13eraqg">도구는 Python 함수로 노출됩니다(바인딩을 통해).</li> <li>도구 호출 예시: | |
| <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="language-py "><!-- HTML_TAG_START -->result = search_docs(<span class="hljs-string">"What is the capital of France?"</span>) | |
| <span class="hljs-built_in">print</span>(result)<!-- HTML_TAG_END --></pre></div></li> <li data-svelte-h="svelte-whtdmw">장점: | |
| <ul><li>높은 표현력: 복잡한 로직과 제어 흐름을 허용하고 도구를 결합하고, 반복하고, 변환하고, 추론할 수 있습니다.</li> <li>유연성: 모든 가능한 액션을 미리 정의할 필요가 없으며, 동적으로 새로운 액션/도구를 생성할 수 있습니다.</li> <li>창발적 추론: 다단계 문제나 동적 로직에 이상적입니다.</li></ul></li> <li data-svelte-h="svelte-1j43w19">제한사항 | |
| <ul><li>오류 위험: 구문 오류, 예외를 처리해야 합니다.</li> <li>예측성 부족: 예상치 못한 또는 안전하지 않은 출력에 더 취약합니다.</li> <li>보안 실행 환경이 필요합니다.</li></ul></li></ul></li> <li><p data-svelte-h="svelte-1h120ke"><a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.ToolCallingAgent">ToolCallingAgent</a>는 도구 호출을 구조화된 JSON으로 작성합니다.</p> <ul><li data-svelte-h="svelte-qgx10j">이는 많은 프레임워크(OpenAI API)에서 사용되는 일반적인 형식으로, 코드 실행 없이 구조화된 도구 상호작용을 가능하게 합니다.</li> <li data-svelte-h="svelte-m9mtl">도구는 JSON 스키마로 정의됩니다: 이름, 설명, 매개변수 타입 등.</li> <li>도구 호출 예시: | |
| <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="language-json "><!-- HTML_TAG_START --><span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"tool_call"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"search_docs"</span><span class="hljs-punctuation">,</span> | |
| <span class="hljs-attr">"arguments"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> | |
| <span class="hljs-attr">"query"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"What is the capital of France?"</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span> | |
| <span class="hljs-punctuation">}</span><!-- HTML_TAG_END --></pre></div></li> <li data-svelte-h="svelte-12xhwvz">장점: | |
| <ul><li>안정성: 환각이 적고, 출력이 구조화되고 검증됩니다.</li> <li>안전성: 인수가 엄격하게 검증되고, 임의의 코드가 실행될 위험이 없습니다.</li> <li>상호 운용성: 외부 API나 서비스에 쉽게 매핑됩니다.</li></ul></li> <li data-svelte-h="svelte-149tf88">제한사항: | |
| <ul><li>낮은 표현력: 결과를 동적으로 쉽게 결합하거나 변환할 수 없고, 복잡한 로직이나 제어 흐름을 수행할 수 없습니다.</li> <li>유연성 부족: 모든 가능한 액션을 미리 정의해야 하고, 사전 정의된 도구로 제한됩니다.</li> <li>코드 합성 없음: 도구 기능으로 제한됩니다.</li></ul></li></ul></li></ul> <p data-svelte-h="svelte-de5x1m">어떤 에이전트 유형을 사용할지:</p> <ul data-svelte-h="svelte-1f5cg1c"><li><p><a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.CodeAgent">CodeAgent</a>를 사용하는 경우:</p> <ul><li>추론, 연결 또는 동적 구성이 필요한 경우.</li> <li>도구가 결합할 수 있는 함수인 경우(예: 구문 분석 + 수학 + 쿼리).</li> <li>에이전트가 문제 해결자 또는 프로그래머인 경우.</li></ul></li> <li><p><a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.ToolCallingAgent">ToolCallingAgent</a>를 사용하는 경우:</p> <ul><li>단순하고 독립적인 도구가 있는 경우(예: API 호출, 문서 가져오기).</li> <li>높은 안정성과 명확한 검증을 원하는 경우.</li> <li>에이전트가 디스패처나 컨트롤러 같은 역할인 경우.</li></ul></li></ul> <h2 class="relative group"><a id="codeagent" 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="#codeagent"><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>CodeAgent</span></h2> <p data-svelte-h="svelte-na7aqd"><a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.CodeAgent">CodeAgent</a>는 액션을 수행하고 작업을 해결하기 위해 Python 코드 스니펫을 생성합니다.</p> <p data-svelte-h="svelte-65nep7">기본적으로 Python 코드 실행은 로컬 환경에서 수행됩니다. | |
| 사용자가 제공한 도구들(특히 Hugging Face 도구만 있는 경우)과 <code>print</code>나 <code>math</code> 모듈 함수 같은 사전 정의된 안전한 함수들만 호출할 수 있도록 제한되어 있어 안전합니다.</p> <p data-svelte-h="svelte-pxseez">Python 인터프리터는 기본적으로 안전 목록에 포함된 모듈만 import를 허용하므로, 대부분의 명백한 보안 공격을 방지할 수 있습니다. | |
| <a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.CodeAgent">CodeAgent</a>를 초기화할 때 <code>additional_authorized_imports</code> 인수에 문자열 목록으로 승인된 모듈을 전달하여 추가 import를 승인할 수 있습니다:</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="language-py "><!-- HTML_TAG_START -->model = InferenceClientModel() | |
| agent = CodeAgent(tools=[], model=model, additional_authorized_imports=[<span class="hljs-string">'requests'</span>, <span class="hljs-string">'bs4'</span>]) | |
| agent.run(<span class="hljs-string">"Could you get me the title of the page at url 'https://huggingface.co/blog'?"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1vsbnjm">또한 추가 보안 계층으로, import 목록에서 명시적으로 승인되지 않는 한 서브모듈에 대한 접근은 기본적으로 금지됩니다. | |
| 예를 들어, <code>numpy.random</code> 서브모듈에 접근하려면 <code>additional_authorized_imports</code> 목록에 <code>'numpy.random'</code>을 추가해야 합니다. | |
| 이는 <code>numpy</code>와 <code>numpy.random</code> 같은 모든 서브패키지 및 자체 서브패키지를 허용하는 <code>numpy.*</code>를 사용하여 승인할 수도 있습니다.</p> <blockquote class="warning" data-svelte-h="svelte-lrxuhn"><p>LLM은 실행될 임의의 코드를 생성할 수 있습니다: 안전하지 않은 import는 추가하지 마세요!</p></blockquote> <p data-svelte-h="svelte-cy0r6u">불법적인 작업을 수행하려고 시도하는 코드나 에이전트가 생성한 코드에 일반적인 Python 오류가 있는 경우 실행이 중단됩니다.</p> <p data-svelte-h="svelte-bheldg">로컬 Python 인터프리터 대신 <a href="https://e2b.dev/docs#what-is-e2-b" rel="nofollow">E2B code executor</a>나 Docker를 사용할 수도 있습니다. E2B의 경우, 먼저 <a href="https://e2b.dev/dashboard?tab=keys" rel="nofollow"><code>E2B_API_KEY</code> 환경 변수를 설정</a>한 다음 에이전트 초기화 시 <code>executor_type="e2b"</code>를 전달하세요. Docker의 경우, 초기화 중에 <code>executor_type="docker"</code>를 전달하세요.</p> <blockquote class="tip" data-svelte-h="svelte-pcp3au"><p>코드 실행에 대해 더 자세히 알아보려면 <a href="tutorials/secure_code_execution">이 튜토리얼</a>을 확인하세요.</p></blockquote> <h3 class="relative group"><a id="toolcallingagent" 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="#toolcallingagent"><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>ToolCallingAgent</span></h3> <p data-svelte-h="svelte-3rra4v"><a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.ToolCallingAgent">ToolCallingAgent</a>는 많은 프레임워크(OpenAI API)에서 사용되는 일반적인 형식인 JSON 도구 호출을 출력하여, 코드 실행 없이 구조화된 도구 상호작용을 가능하게 합니다.</p> <p data-svelte-h="svelte-ddvg9j">코드를 실행하지 않으므로 <code>additional_authorized_imports</code> 없이도 <a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.CodeAgent">CodeAgent</a>와 거의 동일한 방식으로 작동합니다:</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="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> ToolCallingAgent, WebSearchTool | |
| agent = ToolCallingAgent(tools=[WebSearchTool()], model=model) | |
| agent.run(<span class="hljs-string">"Could you get me the title of the page at url 'https://huggingface.co/blog'?"</span>)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="building-your-agent" 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="#building-your-agent"><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-jxoy5v">최소한의 에이전트를 초기화하려면 최소한 다음 두 인수가 필요합니다:</p> <ul data-svelte-h="svelte-vy868s"><li><p><code>model</code>, 에이전트를 구동하는 텍스트 생성 모델 - 에이전트는 단순한 LLM과 다르며, LLM을 엔진으로 사용하는 시스템입니다. 다음 옵션 중 하나를 사용할 수 있습니다:</p> <ul><li><a href="/docs/smolagents/pr_2321/ko/reference/models#smolagents.TransformersModel">TransformersModel</a>은 사전 초기화된 <code>transformers</code> 파이프라인을 가져와 <code>transformers</code>를 사용하여 로컬 머신에서 추론을 실행합니다.</li> <li><a href="/docs/smolagents/pr_2321/ko/reference/models#smolagents.InferenceClientModel">InferenceClientModel</a>은 내부적으로 <code>huggingface_hub.InferenceClient</code>를 활용하며 Hub의 모든 추론 제공자를 지원합니다: Cerebras, Cohere, Fal, Fireworks, HF-Inference, Hyperbolic, Nebius, Novita, Replicate, SambaNova, Together 등.</li> <li><a href="/docs/smolagents/pr_2321/ko/reference/models#smolagents.LiteLLMModel">LiteLLMModel</a>은 마찬가지로 <a href="https://docs.litellm.ai/" rel="nofollow">LiteLLM</a>을 통해 100개 이상의 다양한 모델과 제공자를 호출할 수 있습니다!</li> <li><a href="/docs/smolagents/pr_2321/ko/reference/models#smolagents.AzureOpenAIModel">AzureOpenAIModel</a>은 <a href="https://azure.microsoft.com/en-us/products/ai-services/openai-service" rel="nofollow">Azure</a>에 배포된 OpenAI 모델을 사용할 수 있게 해줍니다.</li> <li><a href="/docs/smolagents/pr_2321/ko/reference/models#smolagents.AmazonBedrockModel">AmazonBedrockModel</a>은 <a href="https://aws.amazon.com/bedrock/?nc1=h_ls" rel="nofollow">AWS</a>의 Amazon Bedrock을 사용할 수 있게 해줍니다.</li> <li><a href="/docs/smolagents/pr_2321/ko/reference/models#smolagents.MLXModel">MLXModel</a>은 로컬 머신에서 추론을 실행하기 위한 <a href="https://pypi.org/project/mlx-lm/" rel="nofollow">mlx-lm</a> 파이프라인을 생성합니다.</li></ul></li> <li><p><code>tools</code>, 에이전트가 작업 해결에 사용할 수 있는 도구 목록입니다. 빈 목록으로 설정할 수도 있습니다. add_base_tools=True 옵션을 사용하면 기본 제공되는 도구들(웹 검색, 코드 실행, 음성 인식 등)을 <code>tools</code> 목록에 추가할 수 있습니다.</p></li></ul> <p data-svelte-h="svelte-axfbel"><code>tools</code>와 <code>model</code> 두 인수를 설정하면 에이전트를 생성하고 실행할 수 있습니다. <a href="https://huggingface.co/blog/inference-providers" rel="nofollow">추론 제공자</a>, <a href="https://github.com/huggingface/transformers/" rel="nofollow">transformers</a>, <a href="https://ollama.com/" rel="nofollow">ollama</a>, <a href="https://www.litellm.ai/" rel="nofollow">LiteLLM</a>, <a href="https://azure.microsoft.com/en-us/products/ai-services/openai-service" rel="nofollow">Azure OpenAI</a>, <a href="https://aws.amazon.com/bedrock/?nc1=h_ls" rel="nofollow">Amazon Bedrock</a>, 또는 <a href="https://pypi.org/project/mlx-lm/" rel="nofollow">mlx-lm</a>을 통해 원하는 LLM을 사용할 수 있습니다.</p> <p data-svelte-h="svelte-1qby8z">모든 모델 클래스는 인스턴스화 시점에 추가 키워드 인수(예: <code>temperature</code>, <code>max_tokens</code>, <code>top_p</code> 등)를 직접 전달하는 것을 지원합니다. | |
| 이러한 매개변수는 기본 모델의 완성 호출에 자동으로 전달되어 창의성, 응답 길이, 샘플링 전략 등의 모델 동작을 구성할 수 있습니다.</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">Inference Providers </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Local Transformers Model </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">OpenAI or Anthropic API </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Ollama </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Azure OpenAI </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Amazon Bedrock </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">mlx-lm </div></div> <div class="language-select"><p data-svelte-h="svelte-2i29sm">추론 제공자는 인증을 위해 <code>HF_TOKEN</code>이 필요하지만, 무료 HF 계정에는 이미 포함된 크레딧이 제공됩니다. PRO로 업그레이드하여 포함된 크레딧을 늘리세요.</p> <p data-svelte-h="svelte-1750ji2">제한된 모델에 접근하거나 PRO 계정으로 속도 제한을 높이려면 환경 변수 <code>HF_TOKEN</code>을 설정하거나 <code>InferenceClientModel</code> 초기화 시 <code>token</code> 변수를 전달해야 합니다. <a href="https://huggingface.co/settings/tokens" rel="nofollow">설정 페이지</a>에서 토큰을 얻을 수 있습니다.</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="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel | |
| model_id = <span class="hljs-string">"meta-llama/Llama-3.3-70B-Instruct"</span> | |
| model = InferenceClientModel(model_id=model_id, token=<span class="hljs-string">"<YOUR_HUGGINGFACEHUB_API_TOKEN>"</span>) <span class="hljs-comment"># You can choose to not pass any model_id to InferenceClientModel to use a default model</span> | |
| <span class="hljs-comment"># you can also specify a particular provider e.g. provider="together" or provider="sambanova"</span> | |
| agent = CodeAgent(tools=[], model=model, add_base_tools=<span class="hljs-literal">True</span>) | |
| agent.run( | |
| <span class="hljs-string">"Could you give me the 118th number in the Fibonacci sequence?"</span>, | |
| )<!-- HTML_TAG_END --></pre></div> </div> <h2 class="relative group"><a id="advanced-agent-configuration" 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="#advanced-agent-configuration"><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="customizing-agent-termination-conditions" 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="#customizing-agent-termination-conditions"><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-18sf0i3">기본적으로 에이전트는 <code>final_answer</code> 함수를 호출하거나 최대 단계 수에 도달할 때까지 계속 실행됩니다. | |
| <code>final_answer_checks</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="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel | |
| <span class="hljs-comment"># Define a custom final answer check function</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">is_integer</span>(<span class="hljs-params">final_answer: <span class="hljs-built_in">str</span>, agent_memory=<span class="hljs-literal">None</span></span>) -> <span class="hljs-built_in">bool</span>: | |
| <span class="hljs-string">"""Return True if final_answer is an integer."""</span> | |
| <span class="hljs-keyword">try</span>: | |
| <span class="hljs-built_in">int</span>(final_answer) | |
| <span class="hljs-keyword">return</span> <span class="hljs-literal">True</span> | |
| <span class="hljs-keyword">except</span> ValueError: | |
| <span class="hljs-keyword">return</span> <span class="hljs-literal">False</span> | |
| <span class="hljs-comment"># Initialize agent with custom final answer check</span> | |
| agent = CodeAgent( | |
| tools=[], | |
| model=InferenceClientModel(), | |
| final_answer_checks=[is_integer] | |
| ) | |
| agent.run(<span class="hljs-string">"Calculate the least common multiple of 3 and 7"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-pkvesx"><code>final_answer_checks</code> 매개변수는 각각 다음과 같은 함수들의 목록을 받습니다:</p> <ul data-svelte-h="svelte-jg4how"><li>에이전트의 final_answer 문자열과 에이전트의 메모리를 매개변수로 받습니다</li> <li>final_answer가 유효한지(True) 아닌지(False)를 나타내는 불리언을 반환합니다</li></ul> <p data-svelte-h="svelte-1vhtgtu">함수 중 하나라도 <code>False</code>를 반환하면 에이전트는 오류 메시지를 로그에 기록하고 실행을 계속합니다. | |
| 이 검증 메커니즘은 다음을 가능하게 합니다:</p> <ul data-svelte-h="svelte-1yvvtux"><li>출력 형식 요구사항 강제(예: 수학 문제에 대한 숫자 답변 보장)</li> <li>도메인별 검증 규칙 구현</li> <li>자체 출력을 검증하는 더 견고한 에이전트 생성</li></ul> <h2 class="relative group"><a id="inspecting-an-agent-run" 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="#inspecting-an-agent-run"><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-xceg47">실행 후 무슨 일이 일어났는지 확인하는 데 유용한 몇 가지 속성이 있습니다:</p> <ul data-svelte-h="svelte-1qav1e5"><li><code>agent.logs</code>는 에이전트의 상세한 실행 로그를 저장합니다. 에이전트 실행의 각 단계마다 모든 정보가 딕셔너리 형태로 저장되어 <code>agent.logs</code>에 추가됩니다.</li> <li><code>agent.write_memory_to_messages()</code>는 에이전트의 메모리를 모델이 볼 수 있는 채팅 메시지 목록으로 변환합니다. 이 메소드는 로그의 각 단계를 살펴보고 중요한 내용만 메시지로 저장합니다. 예를 들어, 시스템 프롬프트와 작업을 각각 별도 메시지로 저장하고, 각 단계의 LLM 출력과 도구 호출 결과를 개별 메시지로 저장합니다. 전체적인 흐름 파악이 필요할 때 권장드립니다. 단, 모든 로그가 이 메소드를 통해 기록되는 것은 아닙니다.</li></ul> <h2 class="relative group"><a id="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="#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> <p data-svelte-h="svelte-8tmi56">도구는 에이전트가 사용할 수 있는 독립적인 함수입니다. LLM이 도구를 사용하기 위해서는 먼저 API를 구성해야하며, 또한 LLM에게 해당 도구 호출하는 방법을 설명해주어야합니다 :</p> <ul data-svelte-h="svelte-142two3"><li>이름</li> <li>설명</li> <li>입력 타입과 설명</li> <li>출력 타입</li></ul> <p data-svelte-h="svelte-1j711sa">예를 들어 <code>PythonInterpreterTool</code>을 확인할 수 있습니다: 이름, 설명, 입력 설명, 출력 타입, 그리고 액션을 수행하는 <code>forward</code> 메소드가 있습니다.</p> <p data-svelte-h="svelte-jvmnhc">에이전트가 초기화될 때 도구 속성이 에이전트의 시스템 프롬프트에 포함되는 도구 설명을 생성하는 데 사용됩니다. 이를 통해 에이전트는 사용할 수 있는 도구와 그 이유를 알 수 있습니다.</p> <p data-svelte-h="svelte-zl5tzb"><strong>스키마 정보</strong>: <code>output_schema</code>가 정의된 도구(구조화된 출력을 가진 MCP 도구 등)의 경우, <code>CodeAgent</code> 시스템 프롬프트에 자동으로 JSON 스키마 정보가 포함됩니다. 이는 에이전트가 도구 출력의 예상 구조를 이해하고 데이터에 적절히 접근할 수 있도록 도와줍니다.</p> <h3 class="relative group"><a id="default-toolbox" 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="#default-toolbox"><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-1rdhx1y">“toolkit” extra와 함께 <code>smolagents</code>를 설치하면 에이전트를 강화하는 기본 툴박스가 함께 제공되며, <code>add_base_tools=True</code> 인수로 초기화 시 에이전트에 추가할 수 있습니다:</p> <ul data-svelte-h="svelte-x301vv"><li><strong>DuckDuckGo 웹 검색*</strong>: DuckDuckGo 브라우저를 사용하여 웹 검색을 수행합니다.</li> <li><strong>Python 코드 인터프리터</strong>: 보안 환경에서 LLM이 생성한 Python 코드를 실행합니다. 이 도구는 코드 기반 에이전트가 이미 기본적으로 Python 코드를 실행할 수 있으므로 <code>add_base_tools=True</code>로 초기화할 때만 <a href="/docs/smolagents/pr_2321/ko/reference/agents#smolagents.ToolCallingAgent">ToolCallingAgent</a>에 추가됩니다.</li> <li><strong>Transcriber</strong>: 오디오를 텍스트로 변환하는 Whisper-Turbo 기반의 음성-텍스트 파이프라인입니다.</li></ul> <p data-svelte-h="svelte-1fqntez">인수와 함께 호출하여 도구를 수동으로 사용할 수 있습니다.</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="language-python "><!-- HTML_TAG_START --><span class="hljs-comment"># !pip install smolagents[toolkit]</span> | |
| <span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> WebSearchTool | |
| search_tool = WebSearchTool() | |
| <span class="hljs-built_in">print</span>(search_tool(<span class="hljs-string">"Who's the current president of Russia?"</span>))<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="create-a-new-tool" 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="#create-a-new-tool"><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-122bhdj">Hugging Face의 기본 도구가 다루지 않는 사용 사례를 위해 자신만의 도구를 만들 수 있습니다. | |
| 예를 들어, Hub에서 주어진 작업에 대해 가장 많이 다운로드된 모델을 반환하는 도구를 만들어보겠습니다.</p> <p data-svelte-h="svelte-ezzxi4">아래 코드부터 시작하겠습니다.</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="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> list_models | |
| task = <span class="hljs-string">"text-classification"</span> | |
| most_downloaded_model = <span class="hljs-built_in">next</span>(<span class="hljs-built_in">iter</span>(list_models(<span class="hljs-built_in">filter</span>=task, sort=<span class="hljs-string">"downloads"</span>, direction=-<span class="hljs-number">1</span>))) | |
| <span class="hljs-built_in">print</span>(most_downloaded_model.<span class="hljs-built_in">id</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1f8v5mb">이 코드는 함수로 만들고 <code>tool</code> 데코레이터를 추가하여 간단히 도구로 변환할 수 있습니다. | |
| 하지만 이것이 도구를 만드는 유일한 방법은 아닙니다. [Tool]의 하위 클래스로 직접 정의하는 방법도 있으며, 이 방식은 더 많은 유연성을 제공합니다. 예를 들어 리소스 집약적인 클래스 속성을 초기화할 때 유용합니다.</p> <p data-svelte-h="svelte-1bwbi9n">두 옵션 모두에서 어떻게 작동하는지 살펴보겠습니다:</p> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">Decorate a function with @tool </div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Subclass Tool </div></div> <div class="language-select"><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="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> tool | |
| <span class="hljs-meta">@tool</span> | |
| <span class="hljs-keyword">def</span> <span class="hljs-title function_">model_download_tool</span>(<span class="hljs-params">task: <span class="hljs-built_in">str</span></span>) -> <span class="hljs-built_in">str</span>: | |
| <span class="hljs-string">""" | |
| This is a tool that returns the most downloaded model of a given task on the Hugging Face Hub. | |
| It returns the name of the checkpoint. | |
| Args: | |
| task: The task for which to get the download count. | |
| """</span> | |
| most_downloaded_model = <span class="hljs-built_in">next</span>(<span class="hljs-built_in">iter</span>(list_models(<span class="hljs-built_in">filter</span>=task, sort=<span class="hljs-string">"downloads"</span>, direction=-<span class="hljs-number">1</span>))) | |
| <span class="hljs-keyword">return</span> most_downloaded_model.<span class="hljs-built_in">id</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-p8y8sb">함수에는 다음이 필요합니다:</p> <ul data-svelte-h="svelte-1b9cebw"><li>명확한 이름. 이름은 에이전트를 구동하는 LLM이 이해할 수 있도록 이 도구가 무엇을 하는지 충분히 설명적이어야 합니다. 이 도구는 작업에 대해 가장 많이 다운로드된 모델을 반환하므로 <code>model_download_tool</code>이라고 명명하겠습니다.</li> <li>입력과 출력 모두에 대한 타입 힌트</li> <li>각 인수가 설명되는 ‘Args:’ 부분을 포함하는 설명(이번에는 타입 표시 없이, 타입 힌트에서 가져옵니다). 도구 이름과 마찬가지로, 이 설명은 에이전트를 구동하는 LLM을 위한 설명서이므로 소홀히 하지 마세요.</li></ul> <p data-svelte-h="svelte-18wyxrd">이 모든 요소는 초기화 시 에이전트의 시스템 프롬프트에 자동으로 포함됩니다: 따라서 최대한 명확하게 만들도록 노력하세요!</p> <blockquote class="tip" data-svelte-h="svelte-1hyy8mg"><p>이 정의 형식은 <code>apply_chat_template</code>에서 사용되는 도구 스키마와 동일하며, 유일한 차이점은 추가된 <code>tool</code> 데코레이터입니다: 도구 사용 API에 대해 더 자세히 알아보려면 <a href="https://huggingface.co/blog/unified-tool-use#passing-tools-to-a-chat-template" rel="nofollow">여기</a>를 읽어보세요.</p></blockquote> <p data-svelte-h="svelte-1fsfnk9">그런 다음 에이전트를 직접 초기화할 수 있습니다:</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="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel | |
| agent = CodeAgent(tools=[model_download_tool], model=InferenceClientModel()) | |
| agent.run( | |
| <span class="hljs-string">"Can you give me the name of the model that has the most downloads in the 'text-to-video' task on the Hugging Face Hub?"</span> | |
| )<!-- HTML_TAG_END --></pre></div> </div> <p data-svelte-h="svelte-tunl0y">다음 로그를 얻습니다:</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="language-text "><!-- HTML_TAG_START -->╭──────────────────────────────────────── New run ─────────────────────────────────────────╮ | |
| │ │ | |
| │ Can you give me the name of the model that has the most downloads in the 'text-to-video' │ | |
| │ task on the Hugging Face Hub? │ | |
| │ │ | |
| ╰─ InferenceClientModel - Qwen/Qwen2.5-Coder-32B-Instruct ───────────────────────────────────────────╯ | |
| ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 0 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | |
| ╭─ Executing this code: ───────────────────────────────────────────────────────────────────╮ | |
| │ 1 model_name = model_download_tool(task="text-to-video") │ | |
| │ 2 print(model_name) │ | |
| ╰──────────────────────────────────────────────────────────────────────────────────────────╯ | |
| Execution logs: | |
| ByteDance/AnimateDiff-Lightning | |
| Out: None | |
| [Step 0: Duration 0.27 seconds| Input tokens: 2,069 | Output tokens: 60] | |
| ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | |
| ╭─ Executing this code: ───────────────────────────────────────────────────────────────────╮ | |
| │ 1 final_answer("ByteDance/AnimateDiff-Lightning") │ | |
| ╰──────────────────────────────────────────────────────────────────────────────────────────╯ | |
| Out - Final answer: ByteDance/AnimateDiff-Lightning | |
| [Step 1: Duration 0.10 seconds| Input tokens: 4,288 | Output tokens: 148] | |
| Out[20]: 'ByteDance/AnimateDiff-Lightning'<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-1ibre0g"><p>도구에 대해 더 자세히 알아보려면 <a href="./tutorials/tools#what-is-a-tool-and-how-to-build-one">전용 튜토리얼</a>을 읽어보세요.</p></blockquote> <h2 class="relative group"><a id="multi-agents" 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="#multi-agents"><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-e3xte0">멀티 에이전트 시스템은 Microsoft의 프레임워크 <a href="https://huggingface.co/papers/2308.08155" rel="nofollow">Autogen</a>과 함께 도입되었습니다.</p> <p data-svelte-h="svelte-r80hcc">이러한 프레임워크에서는 단일 에이전트 대신 여러 에이전트가 협력하여 작업을 해결합니다. | |
| 실제로 대부분의 벤치마크에서 더 우수한 성능을 보여줍니다. 성능이 향상되는 이유는 개념적으로 단순합니다. 많은 작업에서 모든 기능을 담당하는 범용 시스템보다는 특정 하위 작업에 특화된 전문 단위를 사용하는 것이 더 효과적이기 때문입니다. 서로 다른 도구와 메모리를 가진 에이전트들을 활용하면 효율적인 역할 분담이 가능합니다. 예를 들어, 웹 검색 에이전트가 수집한 모든 웹페이지 내용을 코드 생성 에이전트의 메모리에까지 저장할 필요가 있을까요? 각자의 역할에 맞게 분리해서 운영하는 것이 훨씬 효율적입니다.</p> <p data-svelte-h="svelte-1omuaip"><code>smolagents</code>로 계층적 멀티 에이전트 시스템을 쉽게 구축할 수 있습니다.</p> <p data-svelte-h="svelte-982dee">이를 위해서는 에이전트에 <code>name</code>과 <code>description</code> 속성만 있으면 되며, 이는 도구와 마찬가지로 관리자 에이전트의 시스템 프롬프트에 포함되어 관리되는 에이전트를 호출하는 방법을 알려줍니다. | |
| 그런 다음 관리자 에이전트를 초기화할 때 <code>managed_agents</code> 매개변수에 이 관리되는 에이전트를 전달할 수 있습니다.</p> <p data-svelte-h="svelte-54l33b">다음은 네이티브 <code>WebSearchTool</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="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> CodeAgent, InferenceClientModel, WebSearchTool | |
| model = InferenceClientModel() | |
| web_agent = CodeAgent( | |
| tools=[WebSearchTool()], | |
| model=model, | |
| name=<span class="hljs-string">"web_search_agent"</span>, | |
| description=<span class="hljs-string">"Runs web searches for you. Give it your query as an argument."</span> | |
| ) | |
| manager_agent = CodeAgent( | |
| tools=[], model=model, managed_agents=[web_agent] | |
| ) | |
| manager_agent.run(<span class="hljs-string">"Who is the CEO of Hugging Face?"</span>)<!-- HTML_TAG_END --></pre></div> <blockquote class="tip" data-svelte-h="svelte-2fjgwv"><p>효율적인 멀티 에이전트 구현의 심화 예제를 보려면 <a href="https://huggingface.co/blog/beating-gaia" rel="nofollow">멀티 에이전트 시스템을 GAIA 리더보드 상위권으로 끌어올린 방법</a>을 확인하세요.</p></blockquote> <h2 class="relative group"><a id="talk-with-your-agent-and-visualize-its-thoughts-in-a-cool-gradio-interface" 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="#talk-with-your-agent-and-visualize-its-thoughts-in-a-cool-gradio-interface"><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>에이전트와 대화하고 멋진 Gradio 인터페이스에서 그 사고 과정을 시각화하기</span></h2> <p data-svelte-h="svelte-140jjfh"><code>GradioUI</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="language-py "><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> ( | |
| load_tool, | |
| CodeAgent, | |
| InferenceClientModel, | |
| GradioUI | |
| ) | |
| <span class="hljs-comment"># Import tool from Hub</span> | |
| image_generation_tool = load_tool(<span class="hljs-string">"m-ric/text-to-image"</span>, trust_remote_code=<span class="hljs-literal">True</span>) | |
| model = InferenceClientModel(model_id=model_id) | |
| <span class="hljs-comment"># Initialize the agent with the image generation tool</span> | |
| agent = CodeAgent(tools=[image_generation_tool], model=model) | |
| GradioUI(agent).launch()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1oh1cz1">내부적으로 사용자가 새로운 요청을 입력하면 에이전트는 <code>agent.run(user_request, reset=False)</code>로 실행됩니다. | |
| <code>reset=False</code> 플래그는 이 새로운 작업을 실행하기 전에 에이전트의 메모리가 플러시되지 않음을 의미하며, 이를 통해 대화가 계속될 수 있습니다.</p> <p data-svelte-h="svelte-1e71kfx">다른 에이전트 애플리케이션에서도 이 <code>reset=False</code> 인수를 사용하여 대화를 계속할 수 있습니다.</p> <p data-svelte-h="svelte-ydn6vq">Gradio UI에서 사용자가 실행 중인 에이전트를 중단할 수 있도록 하려면 <code>agent.interrupt()</code> 메소드를 트리거하는 버튼으로 이를 수행할 수 있습니다. | |
| 이렇게 하면 현재 단계가 끝날 때 에이전트가 중지되고 오류가 발생합니다.</p> <h2 class="relative group"><a id="next-steps" 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="#next-steps"><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-1qenioq">마지막으로 에이전트를 필요에 맞게 구성했다면 Hub에 공유할 수 있습니다!</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="language-py "><!-- HTML_TAG_START -->agent.push_to_hub(<span class="hljs-string">"m-ric/my_agent"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-gg25wv">마찬가지로, 도구의 코드를 신뢰한다면 Hub에 업로드된 에이전트를 불러오려면 다음을 사용하세요:</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="language-py "><!-- HTML_TAG_START -->agent.from_hub(<span class="hljs-string">"m-ric/my_agent"</span>, trust_remote_code=<span class="hljs-literal">True</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1lhz2mw">더 자세한 활용법을 원한다면 다음 튜토리얼들을 참고하세요:</p> <ul data-svelte-h="svelte-1dm99ui"><li><a href="./tutorials/secure_code_execution">코드 에이전트가 작동하는 방법에 대한 설명</a></li> <li><a href="./tutorials/building_good_agents">좋은 에이전트를 구축하는 방법에 대한 가이드</a>.</li> <li><a href="./tutorials/building_good_agents">도구 사용에 대한 상세 가이드</a>.</li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/smolagents/blob/main/docs/source/ko/guided_tour.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_h301i3 = { | |
| assets: "/docs/smolagents/pr_2321/ko", | |
| base: "/docs/smolagents/pr_2321/ko", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/smolagents/pr_2321/ko/_app/immutable/entry/start.ca84f914.js"), | |
| import("/docs/smolagents/pr_2321/ko/_app/immutable/entry/app.e212187f.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 10], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 80.4 kB
- Xet hash:
- 565472418e02077aab378ddca08210555439a8df04e173688b4f3411aab0ee1e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.