Buckets:

rtrm's picture
download
raw
27.6 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;๐Ÿ“š ์—์ด์ „ํŠธ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ&quot;,&quot;local&quot;:&quot;-manage-your-agents-memory&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;์—์ด์ „ํŠธ ๋ฉ”๋ชจ๋ฆฌ ์žฌ์ƒ&quot;,&quot;local&quot;:&quot;replay-your-agents-memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;์—์ด์ „ํŠธ ๋ฉ”๋ชจ๋ฆฌ ๋™์  ๋ณ€๊ฒฝ&quot;,&quot;local&quot;:&quot;dynamically-change-the-agents-memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;์—์ด์ „ํŠธ๋ฅผ ๋‹จ๊ณ„๋ณ„๋กœ ์‹คํ–‰&quot;,&quot;local&quot;:&quot;run-agents-one-step-at-a-time&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:1}">
<link href="/docs/smolagents/pr_2060/ko/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/entry/start.f21eb17e.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/scheduler.00b97157.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/singletons.956410eb.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/index.78ea7f15.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/paths.0924b2d9.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/entry/app.43bd0d34.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/preload-helper.a0a022f1.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/index.a7c1a7a1.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/nodes/0.ab3c5f86.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/each.e59479a4.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/nodes/18.1fac388c.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.8d2aa6d9.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/CodeBlock.74fa11a7.js">
<link rel="modulepreload" href="/docs/smolagents/pr_2060/ko/_app/immutable/chunks/DocNotebookDropdown.be7b60e3.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;๐Ÿ“š ์—์ด์ „ํŠธ ๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ&quot;,&quot;local&quot;:&quot;-manage-your-agents-memory&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;์—์ด์ „ํŠธ ๋ฉ”๋ชจ๋ฆฌ ์žฌ์ƒ&quot;,&quot;local&quot;:&quot;replay-your-agents-memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;์—์ด์ „ํŠธ ๋ฉ”๋ชจ๋ฆฌ ๋™์  ๋ณ€๊ฒฝ&quot;,&quot;local&quot;:&quot;dynamically-change-the-agents-memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;์—์ด์ „ํŠธ๋ฅผ ๋‹จ๊ณ„๋ณ„๋กœ ์‹คํ–‰&quot;,&quot;local&quot;:&quot;run-agents-one-step-at-a-time&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;: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="-manage-your-agents-memory" 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="#-manage-your-agents-memory"><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-ton0ak">๊ฒฐ๊ตญ ์—์ด์ „ํŠธ๋Š” ๋„๊ตฌ์™€ ํ”„๋กฌํ”„ํŠธ๋กœ ์ด๋ฃจ์–ด์ง„ ๋‹จ์ˆœํ•œ ๊ตฌ์„ฑ์š”์†Œ๋กœ ์ •์˜๋ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋ฌด์—‡๋ณด๋‹ค ์ค‘์š”ํ•œ ๊ฒƒ์€ ์—์ด์ „ํŠธ๊ฐ€ ๊ณผ๊ฑฐ ๋‹จ๊ณ„์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์–ด ๊ณ„ํš, ์‹คํ–‰, ์˜ค๋ฅ˜์˜ ์ด๋ ฅ์„ ์ถ”์ ํ•œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค.</p> <h3 class="relative group"><a id="replay-your-agents-memory" 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="#replay-your-agents-memory"><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-1h50h00">๊ณผ๊ฑฐ ์‹คํ–‰๋œ ์—์ด์ „ํŠธ๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ๋ช‡ ๊ฐ€์ง€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-dnn1cu"><a href="./inspect_runs">๊ณ„์ธก ๊ฐ€์ด๋“œ</a>์—์„œ ์–ธ๊ธ‰ํ•œ ๋ฐ”์™€ ๊ฐ™์ด, ์—์ด์ „ํŠธ ์‹คํ–‰์„ ๊ณ„์ธกํ•˜์—ฌ ํŠน์ • ๋‹จ๊ณ„๋ฅผ ํ™•๋Œ€ํ•˜๊ฑฐ๋‚˜ ์ถ•์†Œํ•  ์ˆ˜ ์žˆ๋Š” ์šฐ์ˆ˜ํ•œ UI๋กœ ์‹œ๊ฐํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-iux67r">๋˜ํ•œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด <code>agent.replay()</code>๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-lh7ekp">์—์ด์ „ํŠธ๋ฅผ ์‹คํ–‰ํ•œ ํ›„,</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> smolagents <span class="hljs-keyword">import</span> InferenceClientModel, CodeAgent
agent = CodeAgent(tools=[], model=InferenceClientModel(), verbosity_level=<span class="hljs-number">0</span>)
result = agent.run(<span class="hljs-string">&quot;What&#x27;s the 20th Fibonacci number?&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-12x9pal">์ด ๋งˆ์ง€๋ง‰ ์‹คํ–‰์„ ๋‹ค์‹œ ์žฌ์ƒํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.</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 -->agent.replay()<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="dynamically-change-the-agents-memory" 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="#dynamically-change-the-agents-memory"><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-1lq08uo">๋งŽ์€ ๊ณ ๊ธ‰ ์‚ฌ์šฉ ์‚ฌ๋ก€์—์„œ๋Š” ์—์ด์ „ํŠธ์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋™์ ์œผ๋กœ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-lnzmi9">์—์ด์ „ํŠธ์˜ ๋ฉ”๋ชจ๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</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> smolagents <span class="hljs-keyword">import</span> ActionStep
system_prompt_step = agent.memory.system_prompt
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;The system prompt given to the agent was:&quot;</span>)
<span class="hljs-built_in">print</span>(system_prompt_step.system_prompt)
task_step = agent.memory.steps[<span class="hljs-number">0</span>]
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;\n\nThe first task step was:&quot;</span>)
<span class="hljs-built_in">print</span>(task_step.task)
<span class="hljs-keyword">for</span> step <span class="hljs-keyword">in</span> agent.memory.steps:
<span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(step, ActionStep):
<span class="hljs-keyword">if</span> step.error <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\nStep <span class="hljs-subst">{step.step_number}</span> got this error:\n<span class="hljs-subst">{step.error}</span>\n&quot;</span>)
<span class="hljs-keyword">else</span>:
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\nStep <span class="hljs-subst">{step.step_number}</span> got these observations:\n<span class="hljs-subst">{step.observations}</span>\n&quot;</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-gjznic"><code>agent.memory.get_full_steps()</code>๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ „์ฒด ๋‹จ๊ณ„๋ฅผ ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-hasgpe">๋˜ํ•œ ๋‹จ๊ณ„ ์ฝœ๋ฐฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์—์ด์ „ํŠธ์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-hno0dy">๋‹จ๊ณ„ ์ฝœ๋ฐฑ์€ ์ธ์ž๋กœ <code>agent</code> ๊ฐ์ฒด ์ž์ฒด์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ์œ„์—์„œ ์„ค๋ช…ํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ชจ๋“  ๋ฉ”๋ชจ๋ฆฌ ๋‹จ๊ณ„์— ์ ‘๊ทผํ•˜์—ฌ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์›น ๋ธŒ๋ผ์šฐ์ € ์—์ด์ „ํŠธ๊ฐ€ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฐ ๋‹จ๊ณ„์˜ ์Šคํฌ๋ฆฐ์ƒท์„ ๊ด€์ฐฐํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ ์ตœ์‹  ์Šคํฌ๋ฆฐ์ƒท์€ ์œ ์ง€ํ•˜๋ฉด์„œ ํ† ํฐ ๋น„์šฉ์„ ์ ˆ์•ฝํ•˜๊ธฐ ์œ„ํ•ด ์ด์ „ ๋‹จ๊ณ„์˜ ์ด๋ฏธ์ง€๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</p> <p data-svelte-h="svelte-1ie0c2b">์ด ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
<em>์ฃผ์˜: ์ด ์ฝ”๋“œ๋Š” ๊ฐ„๊ฒฐํ•จ์„ ์œ„ํ•ด ์ผ๋ถ€ ์ž„ํฌํŠธ ๋ฐ ๊ฐ์ฒด ์ •์˜๊ฐ€ ์ƒ๋žต๋œ ๋ถˆ์™„์ „ํ•œ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. ์ „์ฒด ์ž‘๋™ ๋ฒ„์ „์˜ ์ฝ”๋“œ๋Š” <a href="https://github.com/huggingface/smolagents/blob/main/src/smolagents/vision_web_browser.py" rel="nofollow">์›๋ณธ ์Šคํฌ๋ฆฝํŠธ</a>์—์„œ ํ™•์ธํ•˜์„ธ์š”.</em></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> helium
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO
<span class="hljs-keyword">from</span> time <span class="hljs-keyword">import</span> sleep
<span class="hljs-keyword">def</span> <span class="hljs-title function_">update_screenshot</span>(<span class="hljs-params">memory_step: ActionStep, agent: CodeAgent</span>) -&gt; <span class="hljs-literal">None</span>:
sleep(<span class="hljs-number">1.0</span>) <span class="hljs-comment"># JavaScript ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์™„๋ฃŒ๋œ ํ›„์— ์Šคํฌ๋ฆฐ์ƒท์„ ์ฐ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.</span>
driver = helium.get_driver()
latest_step = memory_step.step_number
<span class="hljs-keyword">for</span> previous_memory_step <span class="hljs-keyword">in</span> agent.memory.steps: <span class="hljs-comment"># ์ด์ „ ์Šคํฌ๋ฆฐ์ƒท์„ ๋กœ๊ทธ์—์„œ ์ œ๊ฑฐํ•˜์—ฌ ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ๊ฐ„์†Œํ™”ํ•ฉ๋‹ˆ๋‹ค.</span>
<span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(previous_memory_step, ActionStep) <span class="hljs-keyword">and</span> previous_memory_step.step_number &lt;= latest_step - <span class="hljs-number">2</span>:
previous_memory_step.observations_images = <span class="hljs-literal">None</span>
png_bytes = driver.get_screenshot_as_png()
image = Image.<span class="hljs-built_in">open</span>(BytesIO(png_bytes))
memory_step.observations_images = [image.copy()]<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-v7yafc">๊ทธ ๋‹ค์Œ ์—์ด์ „ํŠธ๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ๋•Œ ์ด ํ•จ์ˆ˜๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด <code>step_callbacks</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 -->CodeAgent(
tools=[WebSearchTool(), go_back, close_popups, search_item_ctrl_f],
model=model,
additional_authorized_imports=[<span class="hljs-string">&quot;helium&quot;</span>],
step_callbacks=[update_screenshot],
max_steps=<span class="hljs-number">20</span>,
verbosity_level=<span class="hljs-number">2</span>,
)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-luwqat">์ „์ฒด ์ž‘๋™ ์˜ˆ์‹œ๋Š” <a href="https://github.com/huggingface/smolagents/blob/main/src/smolagents/vision_web_browser.py" rel="nofollow">๋น„์ „ ์›น ๋ธŒ๋ผ์šฐ์ € ์ฝ”๋“œ</a>์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</p> <h3 class="relative group"><a id="run-agents-one-step-at-a-time" 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="#run-agents-one-step-at-a-time"><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-3f8ynb">์ด ๊ธฐ๋Šฅ์€ ๋„๊ตฌ ํ˜ธ์ถœ์— ์˜ค๋žœ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋Š” ๊ฒฝ์šฐ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
์—์ด์ „ํŠธ๋ฅผ ํ•œ ๋‹จ๊ณ„์”ฉ ์‹คํ–‰ํ•˜๋ฉด์„œ ๊ฐ ๋‹จ๊ณ„์—์„œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</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> smolagents <span class="hljs-keyword">import</span> InferenceClientModel, CodeAgent, ActionStep, TaskStep
agent = CodeAgent(tools=[], model=InferenceClientModel(), verbosity_level=<span class="hljs-number">1</span>)
agent.python_executor.send_tools({**agent.tools})
<span class="hljs-built_in">print</span>(agent.memory.system_prompt)
task = <span class="hljs-string">&quot;What is the 20th Fibonacci number?&quot;</span>
<span class="hljs-comment"># ํ•„์š”์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์—์ด์ „ํŠธ์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋ถˆ๋Ÿฌ์™€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.</span>
<span class="hljs-comment"># agent.memory.steps = previous_agent.memory.steps</span>
<span class="hljs-comment"># ์ƒˆ๋กœ์šด ์ž‘์—…์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค!</span>
agent.memory.steps.append(TaskStep(task=task, task_images=[]))
final_answer = <span class="hljs-literal">None</span>
step_number = <span class="hljs-number">1</span>
<span class="hljs-keyword">while</span> final_answer <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">and</span> step_number &lt;= <span class="hljs-number">10</span>:
memory_step = ActionStep(
step_number=step_number,
observations_images=[],
)
<span class="hljs-comment"># ํ•œ ๋‹จ๊ณ„๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.</span>
final_answer = agent.step(memory_step)
agent.memory.steps.append(memory_step)
step_number += <span class="hljs-number">1</span>
<span class="hljs-comment"># ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ˆ˜์ •ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค</span>
<span class="hljs-comment"># ์˜ˆ๋ฅผ ๋“ค์–ด ์ตœ์‹  ๋‹จ๊ณ„๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค:</span>
<span class="hljs-comment"># agent.memory.steps[-1] = ...</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;The final answer is:&quot;</span>, final_answer)<!-- HTML_TAG_END --></pre></div> <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/tutorials/memory.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_9tuyt9 = {
assets: "/docs/smolagents/pr_2060/ko",
base: "/docs/smolagents/pr_2060/ko",
env: {}
};
const element = document.currentScript.parentElement;
const data = [null,null];
Promise.all([
import("/docs/smolagents/pr_2060/ko/_app/immutable/entry/start.f21eb17e.js"),
import("/docs/smolagents/pr_2060/ko/_app/immutable/entry/app.43bd0d34.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 18],
data,
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
27.6 kB
ยท
Xet hash:
ca0151c41d35445f2d16870019e5be0870d2a84647d9faf5037e2074540d1cee

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