import{S as Bu,i as Mu,s as Wu,e as a,k as h,w as m,t as l,M as Fu,c as r,d as t,m as p,a as s,x as d,h as i,b as u,N as et,G as o,g as f,y as g,q as v,o as w,B as y,v as Uu,L as Yu}from"../chunks/vendor-hf-doc-builder.js";import{T as lh}from"../chunks/Tip-hf-doc-builder.js";import{I as B}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as T}from"../chunks/CodeBlock-hf-doc-builder.js";function zu(ce){let _,k;return{c(){_=a("p"),k=l(`Transformers Agent is an experimental API which is subject to change at any time. Results returned by the agents
can vary as the APIs or underlying models are prone to change.`)},l($){_=r($,"P",{});var b=s(_);k=i(b,`Transformers Agent is an experimental API which is subject to change at any time. Results returned by the agents
can vary as the APIs or underlying models are prone to change.`),b.forEach(t)},m($,b){f($,_,b),o(_,k)},d($){$&&t(_)}}}function Qu(ce){let _,k;return{c(){_=a("p"),k=l(`StarCoder and OpenAssistant are free to use and perform admirably well on simple tasks. However, the checkpoints
don\u2019t hold up when handling more complex prompts. If you\u2019re facing such an issue, we recommend trying out the OpenAI
model which, while sadly not open-source, performs better at this given time.`)},l($){_=r($,"P",{});var b=s(_);k=i(b,`StarCoder and OpenAssistant are free to use and perform admirably well on simple tasks. However, the checkpoints
don\u2019t hold up when handling more complex prompts. If you\u2019re facing such an issue, we recommend trying out the OpenAI
model which, while sadly not open-source, performs better at this given time.`),b.forEach(t)},m($,b){f($,_,b),o(_,k)},d($){$&&t(_)}}}function Ku(ce){let _,k,$,b,W,I,tt,F,N,j,H,U,P,ot,X,O,at,M,rt,st,S,nt,lt,ee,L,it,te,q,me;return b=new T({props:{code:'agent.run("Draw me the picture of a capybara swimming in the sea")',highlighted:'agent.run(<span class="hljs-string">&quot;Draw me the picture of a capybara swimming in the sea&quot;</span>)'}}),q=new T({props:{code:'agent.run("Draw me a picture of the `prompt`", prompt="a capybara swimming in the sea")',highlighted:'agent.run(<span class="hljs-string">&quot;Draw me a picture of the `prompt`&quot;</span>, prompt=<span class="hljs-string">&quot;a capybara swimming in the sea&quot;</span>)'}}),{c(){_=a("p"),k=l("This can be helpful when the model is unable to understand your request and mixes tools. An example would be:"),$=h(),m(b.$$.fragment),W=h(),I=a("p"),tt=l("Here, the model could interpret in two ways:"),F=h(),N=a("ul"),j=a("li"),H=l("Have the "),U=a("code"),P=l("text-to-image"),ot=l(" generate a capybara swimming in the sea"),X=h(),O=a("li"),at=l("Or, have the "),M=a("code"),rt=l("text-to-image"),st=l(" generate capybara, then use the "),S=a("code"),nt=l("image-transformation"),lt=l(" tool to have it swim in the sea"),ee=h(),L=a("p"),it=l("In case you would like to force the first scenario, you could do so by passing it the prompt as an argument:"),te=h(),m(q.$$.fragment)},l(c){_=r(c,"P",{});var x=s(_);k=i(x,"This can be helpful when the model is unable to understand your request and mixes tools. An example would be:"),x.forEach(t),$=p(c),d(b.$$.fragment,c),W=p(c),I=r(c,"P",{});var ft=s(I);tt=i(ft,"Here, the model could interpret in two ways:"),ft.forEach(t),F=p(c),N=r(c,"UL",{});var R=s(N);j=r(R,"LI",{});var Y=s(j);H=i(Y,"Have the "),U=r(Y,"CODE",{});var z=s(U);P=i(z,"text-to-image"),z.forEach(t),ot=i(Y," generate a capybara swimming in the sea"),Y.forEach(t),X=p(R),O=r(R,"LI",{});var C=s(O);at=i(C,"Or, have the "),M=r(C,"CODE",{});var de=s(M);rt=i(de,"text-to-image"),de.forEach(t),st=i(C," generate capybara, then use the "),S=r(C,"CODE",{});var Jt=s(S);nt=i(Jt,"image-transformation"),Jt.forEach(t),lt=i(C," tool to have it swim in the sea"),C.forEach(t),R.forEach(t),ee=p(c),L=r(c,"P",{});var Xt=s(L);it=i(Xt,"In case you would like to force the first scenario, you could do so by passing it the prompt as an argument:"),Xt.forEach(t),te=p(c),d(q.$$.fragment,c)},m(c,x){f(c,_,x),o(_,k),f(c,$,x),g(b,c,x),f(c,W,x),f(c,I,x),o(I,tt),f(c,F,x),f(c,N,x),o(N,j),o(j,H),o(j,U),o(U,P),o(j,ot),o(N,X),o(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ljs-string">&quot;Caption the following image&quot;</span>, image=image)'}}),pt=new T({props:{code:'agent.run("Read the following text out loud", text=text)',highlighted:'agent.run(<span class="hljs-string">&quot;Read the following text out loud&quot;</span>, text=text)'}}),dt=new T({props:{code:`agent.run(
    "In the following \`document\`, where will the TRRF Scientific Advisory Council Meeting take place?",
    document=document,
)`,highlighted:`agent.run(
    <span class="hljs-string">&quot;In the following \`document\`, where will the TRRF Scientific Advisory Council Meeting take place?&quot;</span>,
    document=document,
)`}}),wt=new B({}),yt=new T({props:{code:"pip install transformers[agents]",highlighted:"pip install transformers[agents]"}}),_t=new T({props:{code:"pip install openai",highlighted:"pip install openai"}}),$t=new T({props:{code:`from transformers import OpenAiAgent

agent = OpenAiAgent(model="text-davinci-003", api_key="<your_api_key>")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> OpenAiAgent

agent = OpenAiAgent(model=<span class="hljs-string">&quot;text-davinci-003&quot;</span>, api_key=<span class="hljs-string">&quot;&lt;your_api_key&gt;&quot;</span>)`}}),bt=new T({props:{code:`from huggingface_hub import login

login("<YOUR_TOKEN>")`,highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> login

login(<span class="hljs-string">&quot;&lt;YOUR_TOKEN&gt;&quot;</span>)`}}),Et=new T({props:{code:`from transformers import HfAgent

# Starcoder
agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")
# StarcoderBase
# agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoderbase")
# OpenAssistant
# agent = HfAgent(url_endpoint="https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> HfAgent

<span class="hljs-comment"># Starcoder</span>
agent = HfAgent(<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigcode/starcoder&quot;</span>)
<span class="hljs-comment"># StarcoderBase</span>
<span class="hljs-comment"># agent = HfAgent(&quot;https://api-inference.huggingface.co/models/bigcode/starcoderbase&quot;)</span>
<span class="hljs-comment"># OpenAssistant</span>
<span class="hljs-comment"># agent = HfAgent(url_endpoint=&quot;https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5&quot;)</span>`}}),$e=new lh({props:{$$slots:{default:[Qu]},$$scope:{ctx:ce}}}),xt=new B({}),At=new T({props:{code:'agent.run("Draw me a picture of rivers and lakes.")',highlighted:'agent.run(<span class="hljs-string">&quot;Draw me a picture of rivers and lakes.&quot;</span>)'}}),kt=new T({props:{code:'agent.run("Draw me a picture of the sea then transform the picture to add an island")',highlighted:'agent.run(<span class="hljs-string">&quot;Draw me a picture of the sea then transform the picture to add an island&quot;</span>)'}}),It=new T({props:{code:'picture = agent.run("Generate a picture of rivers and lakes.")\nupdated_picture = agent.run("Transform the image in `picture` to add an island to it.", picture=picture)',highlighted:'picture = agent.run(<span class="hljs-string">&quot;Generate a picture of rivers and lakes.&quot;</span>)\nupdated_picture = agent.run(<span class="hljs-string">&quot;Transform the image in `picture` to add an island to it.&quot;</span>, picture=picture)'}}),Ae=new lh({props:{$$slots:{default:[Ku]},$$scope:{ctx:ce}}}),qt=new B({}),Ot=new T({props:{code:'agent.chat("Generate a picture of rivers and lakes")',highlighted:'agent.chat(<span class="hljs-string">&quot;Generate a picture of rivers and lakes&quot;</span>)'}}),Lt=new T({props:{code:'agent.chat("Transform the picture so that there is a rock in there")',highlighted:'agent.chat(<span class="hljs-string">&quot;Transform the picture so that there is a rock in there&quot;</span>)'}}),Nt=new B({}),Ht=new T({props:{code:'agent.run("Draw me a picture of rivers and lakes", remote=True)',highlighted:'agent.run(<span class="hljs-string">&quot;Draw me a picture of rivers and lakes&quot;</span>, remote=<span class="hljs-literal">True</span>)'}}),Ct=new T({props:{code:'agent.chat("Draw me a picture of rivers and lakes", remote=True)',highlighted:'agent.chat(<span class="hljs-string">&quot;Draw me a picture of rivers and lakes&quot;</span>, remote=<span class="hljs-literal">True</span>)'}}),Dt=new B({}),Gt=new B({}),Bt=new B({}),Mt=new B({}),Wt=new B({}),Ft=new T({props:{code:`from transformers import load_tool

tool = load_tool("text-to-speech")
audio = tool("This is a text to speech tool")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> load_tool

tool = load_tool(<span class="hljs-string">&quot;text-to-speech&quot;</span>)
audio = tool(<span class="hljs-string">&quot;This is a text to speech tool&quot;</span>)`}}),Ut=new B({}),Qt=new B({}),Kt=new T({props:{code:'agent.run("Draw me a picture of rivers and lakes", return_code=True)',highlighted:'agent.run(<span class="hljs-string">&quot;Draw me a picture of rivers and lakes&quot;</span>, return_code=<span class="hljs-literal">True</span>)'}}),Vt=new T({props:{code:`from transformers import load_tool

image_generator = load_tool("huggingface-tools/text-to-image")

image = image_generator(prompt="rivers and lakes")`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> load_tool

image_generator = load_tool(<span class="hljs-string">&quot;huggingface-tools/text-to-image&quot;</span>)

image = image_generator(prompt=<span class="hljs-string">&quot;rivers and lakes&quot;</span>)`}}),{c(){_=a("meta"),k=h(),$=a("h1"),b=a("a"),W=a("span"),m(I.$$.fragment),tt=h(),F=a("span"),N=l("Transformers Agent"),j=h(),m(H.$$.fragment),U=h(),P=a("p"),ot=l("Transformers version v4.29.0, building on the concept of "),X=a("em"),O=l("tools"),at=l(" and "),M=a("em"),rt=l("agents"),st=l(`. You can play with in
`),S=a("a"),nt=l("this colab"),lt=l("."),ee=h(),L=a("p"),it=l(`In short, it provides a natural language API on top of transformers: we define a set of curated tools and design an
agent to interpret natural language and to use these tools. It is extensible by design; we curated some relevant tools,
but we\u2019ll show you how the system can be extended easily to use any tool developed by the community.`),te=h(),q=a("p"),me=l(`Let\u2019s start with a few examples of what can be achieved with this new API. It is particularly powerful when it comes
to multimodal tasks, so let\u2019s take it for a spin to generate images and read text out loud.`),c=h(),m(x.$$.fragment),ft=h(),R=a("table"),Y=a("thead"),z=a("tr"),C=a("th"),de=a("strong"),Jt=l("Input"),Xt=h(),aa=a("th"),ra=a("strong"),Nn=l("Output"),jn=h(),sa=a("tbody"),ht=a("tr"),na=a("td"),eo=a("img"),Hn=h(),la=a("td"),Cn=l("A beaver is swimming in the water"),Pr=h(),Ir=a("hr"),qr=h(),m(pt.$$.fragment),Or=h(),ge=a("table"),ia=a("thead"),ut=a("tr"),fa=a("th"),ha=a("strong"),Dn=l("Input"),Gn=h(),pa=a("th"),ua=a("strong"),Bn=l("Output"),Mn=h(),ca=a("tbody"),ct=a("tr"),ma=a("td"),Wn=l("A beaver is swimming in the water"),Fn=h(),da=a("td"),mt=a("audio"),to=a("source"),Un=l(" your browser does not support the audio element. </audio>"),Sr=h(),Lr=a("hr"),Rr=h(),m(dt.$$.fragment),Nr=h(),ve=a("table"),ga=a("thead"),gt=a("tr"),va=a("th"),wa=a("strong"),Yn=l("Input"),zn=h(),ya=a("th"),_a=a("strong"),Qn=l("Output"),Kn=h(),$a=a("tbody"),vt=a("tr"),ba=a("td"),oo=a("img"),Vn=h(),Ea=a("td"),Zn=l("ballroom foyer"),jr=h(),oe=a("h2"),we=a("a"),xa=a("span"),m(wt.$$.fragment),Jn=h(),Aa=a("span"),Xn=l("Quickstart"),Hr=h(),ye=a("p"),el=l("Before being able to use "),Ta=a("code"),tl=l("agent.run"),ol=l(`, you will need to instantiate an agent, which is a large language model (LLM).
We provide support for openAI models as well as opensource alternatives from BigCode and OpenAssistant. The openAI
models perform better (but require you to have an openAI API key, so cannot be used for free); Hugging Face is
providing free access to endpoints for BigCode and OpenAssistant models.`),Cr=h(),_e=a("p"),al=l("To start with, please install the "),ka=a("code"),rl=l("agents"),sl=l(" extras in order to install all default dependencies."),Dr=h(),m(yt.$$.fragment),Gr=h(),Q=a("p"),nl=l("To use openAI models, you instantiate an "),ao=a("a"),ll=l("OpenAiAgent"),il=l(" after installing the "),Pa=a("code"),fl=l("openai"),hl=l(" dependency:"),Br=h(),m(_t.$$.fragment),Mr=h(),m($t.$$.fragment),Wr=h(),ro=a("p"),pl=l("To use BigCode or OpenAssistant, start by logging in to have access to the Inference API:"),Fr=h(),m(bt.$$.fragment),Ur=h(),so=a("p"),ul=l("Then, instantiate the agent"),Yr=h(),m(Et.$$.fragment),zr=h(),no=a("p"),cl=l(`This is using the inference API that Hugging Face provides for free at the moment. If you have your own inference
endpoint for this model (or another one) you can replace the URL above with your URL endpoint.`),Qr=h(),m($e.$$.fragment),Kr=h(),lo=a("p"),ml=l("You\u2019re now good to go! Let\u2019s dive into the two APIs that you now have at your disposal."),Vr=h(),ae=a("h3"),be=a("a"),Ia=a("span"),m(xt.$$.fragment),dl=h(),qa=a("span"),gl=l("Single execution (run)"),Zr=h(),Ee=a("p"),vl=l("The single execution method is when using the "),io=a("a"),wl=l("run()"),yl=l(" method of the agent:"),Jr=h(),m(At.$$.fragment),Xr=h(),Tt=a("img"),es=h(),fo=a("p"),_l=l(`It automatically selects the tool (or tools) appropriate for the task you want to perform and runs them appropriately. It
can perform one or several tasks in the same instruction (though the more complex your instruction, the more likely
the agent is to fail).`),ts=h(),m(kt.$$.fragment),os=h(),Pt=a("img"),as=h(),rs=a("br"),ss=h(),xe=a("p"),$l=l("Every "),ho=a("a"),bl=l("run()"),El=l(" operation is independent, so you can run it several times in a row with different tasks."),ns=h(),K=a("p"),xl=l("Note that your "),Oa=a("code"),Al=l("agent"),Tl=l(` is just a large-language model, so small variations in your prompt might yield completely
different results. It\u2019s important to explain as clearly as possible the task you want to perform. We go more in-depth
on how to write good prompts `),po=a("a"),kl=l("here"),Pl=l("."),ls=h(),uo=a("p"),Il=l(`If you\u2019d like to keep a state across executions or to pass non-text objects to the agent, you can do so by specifying
variables that you would like the agent to use. For example, you could generate the first image of rivers and lakes,
and ask the model to update that picture to add an island by doing the following:`),is=h(),m(It.$$.fragment),fs=h(),m(Ae.$$.fragment),hs=h(),re=a("h3"),Te=a("a"),Sa=a("span"),m(qt.$$.fragment),ql=h(),La=a("span"),Ol=l("Chat-based execution (chat)"),ps=h(),ke=a("p"),Sl=l("The agent also has a chat-based approach, using the "),co=a("a"),Ll=l("chat()"),Rl=l(" method:"),us=h(),m(Ot.$$.fragment),cs=h(),St=a("img"),ms=h(),m(Lt.$$.fragment),ds=h(),Rt=a("img"),gs=h(),vs=a("br"),ws=h(),Pe=a("p"),Nl=l(`This is an interesting approach when you want to keep the state across instructions. It\u2019s better for experimentation,
but will tend to be much better at single instructions rather than complex instructions (which the `),mo=a("a"),jl=l("run()"),Hl=l(`
method is better at handling).`),ys=h(),go=a("p"),Cl=l("This method can also take arguments if you would like to pass non-text types or specific prompts."),_s=h(),se=a("h3"),Ie=a("a"),Ra=a("span"),m(Nt.$$.fragment),Dl=h(),Na=a("span"),Gl=l("\u26A0\uFE0F Remote execution"),$s=h(),V=a("p"),Bl=l(`For demonstration purposes and so that this can be used with all setups, we have created remote executors for several
of the default tools the agent has access. These are created using
`),jt=a("a"),Ml=l("inference endpoints"),Wl=l(`. To see how to set up remote executors tools yourself,
we recommend reading the `),vo=a("a"),Fl=l("custom tool guide"),Ul=l("."),bs=h(),D=a("p"),Yl=l("In order to run with remote tools, specifying "),ja=a("code"),zl=l("remote=True"),Ql=l(" to either "),wo=a("a"),Kl=l("run()"),Vl=l(" or "),yo=a("a"),Zl=l("chat()"),Jl=l(" is sufficient."),Es=h(),_o=a("p"),Xl=l("For example, the following command could be run on any device efficiently, without needing significant RAM or GPU:"),xs=h(),m(Ht.$$.fragment),As=h(),qe=a("p"),ei=l("The same can be said for "),$o=a("a"),ti=l("chat()"),oi=l(":"),Ts=h(),m(Ct.$$.fragment),ks=h(),ne=a("h3"),Oe=a("a"),Ha=a("span"),m(Dt.$$.fragment),ai=h(),Ca=a("span"),ri=l("What's happening here? What are tools, and what are agents?"),Ps=h(),bo=a("img"),Is=h(),le=a("h4"),Se=a("a"),Da=a("span"),m(Gt.$$.fragment),si=h(),Ga=a("span"),ni=l("Agents"),qs=h(),Eo=a("p"),li=l("The \u201Cagent\u201D here is a large language model, and we\u2019re prompting it so that it has access to a specific set of tools."),Os=h(),xo=a("p"),ii=l(`LLMs are pretty good at generating small samples of code, so this API takes advantage of that by prompting the
LLM gives a small sample of code performing a task with a set of tools. This prompt is then completed by the
task you give your agent and the description of the tools you give it. This way it gets access to the doc of the
tools you are using, especially their expected inputs and outputs, and can generate the relevant code.`),Ss=h(),ie=a("h4"),Le=a("a"),Ba=a("span"),m(Bt.$$.fragment),fi=h(),Ma=a("span"),hi=l("Tools"),Ls=h(),Ao=a("p"),pi=l(`Tools are very simple: they\u2019re a single function, with a name, and a description. We then use these tools\u2019 descriptions
to prompt the agent. Through the prompt, we show the agent how it would leverage tools to perform what was
requested in the query.`),Rs=h(),To=a("p"),ui=l(`This is using brand-new tools and not pipelines, because the agent writes better code with very atomic tools.
Pipelines are more refactored and often combine several tasks in one. Tools are meant to be focused on
one very simple task only.`),Ns=h(),fe=a("h4"),Re=a("a"),Wa=a("span"),m(Mt.$$.fragment),ci=h(),Fa=a("span"),mi=l("Code-execution?!"),js=h(),ko=a("p"),di=l(`This code is then executed with our small Python interpreter on the set of inputs passed along with your tools.
We hear you screaming \u201CArbitrary code execution!\u201D in the back, but let us explain why that is not the case.`),Hs=h(),Po=a("p"),gi=l(`The only functions that can be called are the tools you provided and the print function, so you\u2019re already
limited in what can be executed. You should be safe if it\u2019s limited to Hugging Face tools.`),Cs=h(),Io=a("p"),vi=l(`Then, we don\u2019t allow any attribute lookup or imports (which shouldn\u2019t be needed anyway for passing along
inputs/outputs to a small set of functions) so all the most obvious attacks (and you\u2019d need to prompt the LLM
to output them anyway) shouldn\u2019t be an issue. If you want to be on the super safe side, you can execute the
run() method with the additional argument return_code=True, in which case the agent will just return the code
to execute and you can decide whether to do it or not.`),Ds=h(),qo=a("p"),wi=l(`The execution will stop at any line trying to perform an illegal operation or if there is a regular Python error
with the code generated by the agent.`),Gs=h(),he=a("h3"),Ne=a("a"),Ua=a("span"),m(Wt.$$.fragment),yi=h(),Ya=a("span"),_i=l("A curated set of tools"),Bs=h(),je=a("p"),$i=l(`We identify a set of tools that can empower such agents. Here is an updated list of the tools we have integrated
in `),za=a("code"),bi=l("transformers"),Ei=l(":"),Ms=h(),E=a("ul"),He=a("li"),Qa=a("strong"),xi=l("Document question answering"),Ai=l(": given a document (such as a PDF) in image format, answer a question on this document ("),Oo=a("a"),Ti=l("Donut"),ki=l(")"),Pi=h(),Ce=a("li"),Ka=a("strong"),Ii=l("Text question answering"),qi=l(": given a long text and a question, answer the question in the text ("),So=a("a"),Oi=l("Flan-T5"),Si=l(")"),Li=h(),De=a("li"),Va=a("strong"),Ri=l("Unconditional image captioning"),Ni=l(": Caption the image! ("),Lo=a("a"),ji=l("BLIP"),Hi=l(")"),Ci=h(),Ge=a("li"),Za=a("strong"),Di=l("Image question answering"),Gi=l(": given an image, answer a question on this image ("),Ro=a("a"),Bi=l("VILT"),Mi=l(")"),Wi=h(),Be=a("li"),Ja=a("strong"),Fi=l("Image segmentation"),Ui=l(": given an image and a prompt, output the segmentation mask of that prompt ("),No=a("a"),Yi=l("CLIPSeg"),zi=l(")"),Qi=h(),Me=a("li"),Xa=a("strong"),Ki=l("Speech to text"),Vi=l(": given an audio recording of a person talking, transcribe the speech into text ("),jo=a("a"),Zi=l("Whisper"),Ji=l(")"),Xi=h(),We=a("li"),er=a("strong"),ef=l("Text to speech"),tf=l(": convert text to speech ("),Ho=a("a"),of=l("SpeechT5"),af=l(")"),rf=h(),Fe=a("li"),tr=a("strong"),sf=l("Zero-shot text classification"),nf=l(": given a text and a list of labels, identify to which label the text corresponds the most ("),Co=a("a"),lf=l("BART"),ff=l(")"),hf=h(),Ue=a("li"),or=a("strong"),pf=l("Text summarization"),uf=l(": summarize a long text in one or a few sentences ("),Do=a("a"),cf=l("BART"),mf=l(")"),df=h(),Ye=a("li"),ar=a("strong"),gf=l("Translation"),vf=l(": translate the text into a given language ("),Go=a("a"),wf=l("NLLB"),yf=l(")"),Ws=h(),Bo=a("p"),_f=l("These tools have an integration in transformers, and can be used manually as well, for example:"),Fs=h(),m(Ft.$$.fragment),Us=h(),pe=a("h3"),ze=a("a"),rr=a("span"),m(Ut.$$.fragment),$f=h(),sr=a("span"),bf=l("Custom tools"),Ys=h(),Mo=a("p"),Ef=l(`While we identify a curated set of tools, we strongly believe that the main value provided by this implementation is
the ability to quickly create and share custom tools.`),zs=h(),Z=a("p"),xf=l(`By pushing the code of a tool to a Hugging Face Space or a model repository, you\u2019re then able to leverage the tool
directly with the agent. We\u2019ve added a few
`),nr=a("strong"),Af=l("transformers-agnostic"),Tf=l(" tools to the "),Qe=a("a"),lr=a("code"),kf=l("huggingface-tools"),Pf=l(" organization"),If=l(":"),Qs=h(),G=a("ul"),Wo=a("li"),ir=a("strong"),qf=l("Text downloader"),Of=l(": to download a text from a web URL"),Sf=h(),Fo=a("li"),fr=a("strong"),Lf=l("Text to image"),Rf=l(": generate an image according to a prompt, leveraging stable diffusion"),Nf=h(),Uo=a("li"),hr=a("strong"),jf=l("Image transformation"),Hf=l(": modify an image given an initial image and a prompt, leveraging instruct pix2pix stable diffusion"),Cf=h(),Yo=a("li"),pr=a("strong"),Df=l("Text to video"),Gf=l(": generate a small video according to a prompt, leveraging damo-vilab"),Ks=h(),Ke=a("p"),Bf=l(`The text-to-image tool we have been using since the beginning is a remote tool that lives in
`),Yt=a("a"),ur=a("em"),Mf=l("huggingface-tools/text-to-image"),Wf=l(`! We will
continue releasing such tools on this and other organizations, to further supercharge this implementation.`),Vs=h(),J=a("p"),Ff=l("The agents have by default access to tools that reside on "),zt=a("a"),cr=a("code"),Uf=l("huggingface-tools"),Yf=l(`.
We explain how to you can write and share your tools as well as leverage any custom tool that resides on the Hub in `),zo=a("a"),zf=l("following guide"),Qf=l("."),Zs=h(),ue=a("h3"),Ve=a("a"),mr=a("span"),m(Qt.$$.fragment),Kf=h(),dr=a("span"),Vf=l("Code generation"),Js=h(),Qo=a("p"),Zf=l(`So far we have shown how to use the agents to perform actions for you. However, the agent is only generating code
that we then execute using a very restricted Python interpreter. In case you would like to use the code generated in
a different setting, the agent can be prompted to return the code, along with tool definition and accurate imports.`),Xs=h(),Ko=a("p"),Jf=l("For example, the following instruction"),en=h(),m(Kt.$$.fragment),tn=h(),Vo=a("p"),Xf=l("returns the following code"),on=h(),m(Vt.$$.fragment),an=h(),Zo=a("p"),eh=l("that you can then modify and execute yourself."),this.h()},l(e){const n=Fu('[data-svelte="svelte-1phssyn"]',document.head);_=r(n,"META",{name:!0,content:!0}),n.forEach(t),k=p(e),$=r(e,"H1",{class:!0});var Zt=s($);b=r(Zt,"A",{id:!0,class:!0,href:!0});var gr=s(b);W=r(gr,"SPAN",{});var vr=s(W);d(I.$$.fragment,vr),vr.forEach(t),gr.forEach(t),tt=p(Zt),F=r(Zt,"SPAN",{});var gh=s(F);N=i(gh,"Transformers Agent"),gh.forEach(t),Zt.forEach(t),j=p(e),d(H.$$.fragment,e),U=p(e),P=r(e,"P",{});var Ze=s(P);ot=i(Ze,"Transformers version v4.29.0, building on the concept of "),X=r(Ze,"EM",{});var vh=s(X);O=i(vh,"tools"),vh.forEach(t),at=i(Ze," and "),M=r(Ze,"EM",{});var wh=s(M);rt=i(wh,"agents"),wh.forEach(t),st=i(Ze,`. You can play with in
`),S=r(Ze,"A",{href:!0,rel:!0});var yh=s(S);nt=i(yh,"this colab"),yh.forEach(t),lt=i(Ze,"."),Ze.forEach(t),ee=p(e),L=r(e,"P",{});var _h=s(L);it=i(_h,`In short, it provides a natural language API on top of transformers: we define a set of curated tools and design an
agent to interpret natural language and to use these tools. It is extensible by design; we curated some relevant tools,
but we\u2019ll show you how the system can be extended easily to use any tool developed by the community.`),_h.forEach(t),te=p(e),q=r(e,"P",{});var $h=s(q);me=i($h,`Let\u2019s start with a few examples of what can be achieved with this new API. It is particularly powerful when it comes
to multimodal tasks, so let\u2019s take it for a spin to generate images and read text out loud.`),$h.forEach(t),c=p(e),d(x.$$.fragment,e),ft=p(e),R=r(e,"TABLE",{});var sn=s(R);Y=r(sn,"THEAD",{});var bh=s(Y);z=r(bh,"TR",{});var nn=s(z);C=r(nn,"TH",{});var Eh=s(C);de=r(Eh,"STRONG",{});var xh=s(de);Jt=i(xh,"Input"),xh.forEach(t),Eh.forEach(t),Xt=p(nn),aa=r(nn,"TH",{});var Ah=s(aa);ra=r(Ah,"STRONG",{});var Th=s(ra);Nn=i(Th,"Output"),Th.forEach(t),Ah.forEach(t),nn.forEach(t),bh.forEach(t),jn=p(sn),sa=r(sn,"TBODY",{});var kh=s(sa);ht=r(kh,"TR",{});var ln=s(ht);na=r(ln,"TD",{});var Ph=s(na);eo=r(Ph,"IMG",{src:!0,width:!0}),Ph.forEach(t),Hn=p(ln),la=r(ln,"TD",{});var Ih=s(la);Cn=i(Ih,"A beaver is swimming in the water"),Ih.forEach(t),ln.forEach(t),kh.forEach(t),sn.forEach(t),Pr=p(e),Ir=r(e,"HR",{}),qr=p(e),d(pt.$$.fragment,e),Or=p(e),ge=r(e,"TABLE",{});var fn=s(ge);ia=r(fn,"THEAD",{});var qh=s(ia);ut=r(qh,"TR",{});var hn=s(ut);fa=r(hn,"TH",{});var Oh=s(fa);ha=r(Oh,"STRONG",{});var Sh=s(ha);Dn=i(Sh,"Input"),Sh.forEach(t),Oh.forEach(t),Gn=p(hn),pa=r(hn,"TH",{});var Lh=s(pa);ua=r(Lh,"STRONG",{});var Rh=s(ua);Bn=i(Rh,"Output"),Rh.forEach(t),Lh.forEach(t),hn.forEach(t),qh.forEach(t),Mn=p(fn),ca=r(fn,"TBODY",{});var Nh=s(ca);ct=r(Nh,"TR",{});var pn=s(ct);ma=r(pn,"TD",{});var jh=s(ma);Wn=i(jh,"A beaver is swimming in the water"),jh.forEach(t),Fn=p(pn),da=r(pn,"TD",{});var Hh=s(da);mt=r(Hh,"AUDIO",{});var th=s(mt);to=r(th,"SOURCE",{src:!0,type:!0}),Un=i(th," your browser does not support the audio element. </audio>"),th.forEach(t),Hh.forEach(t),pn.forEach(t),Nh.forEach(t),fn.forEach(t),Sr=p(e),Lr=r(e,"HR",{}),Rr=p(e),d(dt.$$.fragment,e),Nr=p(e),ve=r(e,"TABLE",{});var un=s(ve);ga=r(un,"THEAD",{});var Ch=s(ga);gt=r(Ch,"TR",{});var cn=s(gt);va=r(cn,"TH",{});var Dh=s(va);wa=r(Dh,"STRONG",{});var Gh=s(wa);Yn=i(Gh,"Input"),Gh.forEach(t),Dh.forEach(t),zn=p(cn),ya=r(cn,"TH",{});var Bh=s(ya);_a=r(Bh,"STRONG",{});var Mh=s(_a);Qn=i(Mh,"Output"),Mh.forEach(t),Bh.forEach(t),cn.forEach(t),Ch.forEach(t),Kn=p(un),$a=r(un,"TBODY",{});var Wh=s($a);vt=r(Wh,"TR",{});var mn=s(vt);ba=r(mn,"TD",{});var Fh=s(ba);oo=r(Fh,"IMG",{src:!0,width:!0}),Fh.forEach(t),Vn=p(mn),Ea=r(mn,"TD",{});var Uh=s(Ea);Zn=i(Uh,"ballroom foyer"),Uh.forEach(t),mn.forEach(t),Wh.forEach(t),un.forEach(t),jr=p(e),oe=r(e,"H2",{class:!0});var dn=s(oe);we=r(dn,"A",{id:!0,class:!0,href:!0});var Yh=s(we);xa=r(Yh,"SPAN",{});var zh=s(xa);d(wt.$$.fragment,zh),zh.forEach(t),Yh.forEach(t),Jn=p(dn),Aa=r(dn,"SPAN",{});var Qh=s(Aa);Xn=i(Qh,"Quickstart"),Qh.forEach(t),dn.forEach(t),Hr=p(e),ye=r(e,"P",{});var gn=s(ye);el=i(gn,"Before being able to use "),Ta=r(gn,"CODE",{});var Kh=s(Ta);tl=i(Kh,"agent.run"),Kh.forEach(t),ol=i(gn,`, you will need to instantiate an agent, which is a large language model (LLM).
We provide support for openAI models as well as opensource alternatives from BigCode and OpenAssistant. The openAI
models perform better (but require you to have an openAI API key, so cannot be used for free); Hugging Face is
providing free access to endpoints for BigCode and OpenAssistant models.`),gn.forEach(t),Cr=p(e),_e=r(e,"P",{});var vn=s(_e);al=i(vn,"To start with, please install the "),ka=r(vn,"CODE",{});var Vh=s(ka);rl=i(Vh,"agents"),Vh.forEach(t),sl=i(vn," extras in order to install all default dependencies."),vn.forEach(t),Dr=p(e),d(yt.$$.fragment,e),Gr=p(e),Q=r(e,"P",{});var Jo=s(Q);nl=i(Jo,"To use openAI models, you instantiate an "),ao=r(Jo,"A",{href:!0});var Zh=s(ao);ll=i(Zh,"OpenAiAgent"),Zh.forEach(t),il=i(Jo," after installing the "),Pa=r(Jo,"CODE",{});var Jh=s(Pa);fl=i(Jh,"openai"),Jh.forEach(t),hl=i(Jo," dependency:"),Jo.forEach(t),Br=p(e),d(_t.$$.fragment,e),Mr=p(e),d($t.$$.fragment,e),Wr=p(e),ro=r(e,"P",{});var Xh=s(ro);pl=i(Xh,"To use BigCode or OpenAssistant, start by logging in to have access to the Inference API:"),Xh.forEach(t),Fr=p(e),d(bt.$$.fragment,e),Ur=p(e),so=r(e,"P",{});var ep=s(so);ul=i(ep,"Then, instantiate the agent"),ep.forEach(t),Yr=p(e),d(Et.$$.fragment,e),zr=p(e),no=r(e,"P",{});var tp=s(no);cl=i(tp,`This is using the inference API that Hugging Face provides for free at the moment. If you have your own inference
endpoint for this model (or another one) you can replace the URL above with your URL endpoint.`),tp.forEach(t),Qr=p(e),d($e.$$.fragment,e),Kr=p(e),lo=r(e,"P",{});var op=s(lo);ml=i(op,"You\u2019re now good to go! Let\u2019s dive into the two APIs that you now have at your disposal."),op.forEach(t),Vr=p(e),ae=r(e,"H3",{class:!0});var wn=s(ae);be=r(wn,"A",{id:!0,class:!0,href:!0});var ap=s(be);Ia=r(ap,"SPAN",{});var rp=s(Ia);d(xt.$$.fragment,rp),rp.forEach(t),ap.forEach(t),dl=p(wn),qa=r(wn,"SPAN",{});var sp=s(qa);gl=i(sp,"Single execution (run)"),sp.forEach(t),wn.forEach(t),Zr=p(e),Ee=r(e,"P",{});var yn=s(Ee);vl=i(yn,"The single execution method is when using the "),io=r(yn,"A",{href:!0});var np=s(io);wl=i(np,"run()"),np.forEach(t),yl=i(yn," method of the agent:"),yn.forEach(t),Jr=p(e),d(At.$$.fragment,e),Xr=p(e),Tt=r(e,"IMG",{src:!0,width:!0}),es=p(e),fo=r(e,"P",{});var lp=s(fo);_l=i(lp,`It automatically selects the tool (or tools) appropriate for the task you want to perform and runs them appropriately. It
can perform one or several tasks in the same instruction (though the more complex your instruction, the more likely
the agent is to fail).`),lp.forEach(t),ts=p(e),d(kt.$$.fragment,e),os=p(e),Pt=r(e,"IMG",{src:!0,width:!0}),as=p(e),rs=r(e,"BR",{}),ss=p(e),xe=r(e,"P",{});var _n=s(xe);$l=i(_n,"Every "),ho=r(_n,"A",{href:!0});var ip=s(ho);bl=i(ip,"run()"),ip.forEach(t),El=i(_n," operation is independent, so you can run it several times in a row with different tasks."),_n.forEach(t),ns=p(e),K=r(e,"P",{});var Xo=s(K);xl=i(Xo,"Note that your "),Oa=r(Xo,"CODE",{});var fp=s(Oa);Al=i(fp,"agent"),fp.forEach(t),Tl=i(Xo,` is just a large-language model, so small variations in your prompt might yield completely
different results. It\u2019s important to explain as clearly as possible the task you want to perform. We go more in-depth
on how to write good prompts `),po=r(Xo,"A",{href:!0});var hp=s(po);kl=i(hp,"here"),hp.forEach(t),Pl=i(Xo,"."),Xo.forEach(t),ls=p(e),uo=r(e,"P",{});var pp=s(uo);Il=i(pp,`If you\u2019d like to keep a state across executions or to pass non-text objects to the agent, you can do so by specifying
variables that you would like the agent to use. For example, you could generate the first image of rivers and lakes,
and ask the model to update that picture to add an island by doing the following:`),pp.forEach(t),is=p(e),d(It.$$.fragment,e),fs=p(e),d(Ae.$$.fragment,e),hs=p(e),re=r(e,"H3",{class:!0});var $n=s(re);Te=r($n,"A",{id:!0,class:!0,href:!0});var up=s(Te);Sa=r(up,"SPAN",{});var cp=s(Sa);d(qt.$$.fragment,cp),cp.forEach(t),up.forEach(t),ql=p($n),La=r($n,"SPAN",{});var mp=s(La);Ol=i(mp,"Chat-based execution (chat)"),mp.forEach(t),$n.forEach(t),ps=p(e),ke=r(e,"P",{});var bn=s(ke);Sl=i(bn,"The agent also has a chat-based approach, using the "),co=r(bn,"A",{href:!0});var dp=s(co);Ll=i(dp,"chat()"),dp.forEach(t),Rl=i(bn," method:"),bn.forEach(t),us=p(e),d(Ot.$$.fragment,e),cs=p(e),St=r(e,"IMG",{src:!0,width:!0}),ms=p(e),d(Lt.$$.fragment,e),ds=p(e),Rt=r(e,"IMG",{src:!0,width:!0}),gs=p(e),vs=r(e,"BR",{}),ws=p(e),Pe=r(e,"P",{});var En=s(Pe);Nl=i(En,`This is an interesting approach when you want to keep the state across instructions. It\u2019s better for experimentation,
but will tend to be much better at single instructions rather than complex instructions (which the `),mo=r(En,"A",{href:!0});var gp=s(mo);jl=i(gp,"run()"),gp.forEach(t),Hl=i(En,`
method is better at handling).`),En.forEach(t),ys=p(e),go=r(e,"P",{});var vp=s(go);Cl=i(vp,"This method can also take arguments if you would like to pass non-text types or specific prompts."),vp.forEach(t),_s=p(e),se=r(e,"H3",{class:!0});var xn=s(se);Ie=r(xn,"A",{id:!0,class:!0,href:!0});var wp=s(Ie);Ra=r(wp,"SPAN",{});var yp=s(Ra);d(Nt.$$.fragment,yp),yp.forEach(t),wp.forEach(t),Dl=p(xn),Na=r(xn,"SPAN",{});var _p=s(Na);Gl=i(_p,"\u26A0\uFE0F Remote execution"),_p.forEach(t),xn.forEach(t),$s=p(e),V=r(e,"P",{});var ea=s(V);Bl=i(ea,`For demonstration purposes and so that this can be used with all setups, we have created remote executors for several
of the default tools the agent has access. These are created using
`),jt=r(ea,"A",{href:!0,rel:!0});var $p=s(jt);Ml=i($p,"inference endpoints"),$p.forEach(t),Wl=i(ea,`. To see how to set up remote executors tools yourself,
we recommend reading the `),vo=r(ea,"A",{href:!0});var bp=s(vo);Fl=i(bp,"custom tool guide"),bp.forEach(t),Ul=i(ea,"."),ea.forEach(t),bs=p(e),D=r(e,"P",{});var Je=s(D);Yl=i(Je,"In order to run with remote tools, specifying "),ja=r(Je,"CODE",{});var Ep=s(ja);zl=i(Ep,"remote=True"),Ep.forEach(t),Ql=i(Je," to either "),wo=r(Je,"A",{href:!0});var xp=s(wo);Kl=i(xp,"run()"),xp.forEach(t),Vl=i(Je," or "),yo=r(Je,"A",{href:!0});var Ap=s(yo);Zl=i(Ap,"chat()"),Ap.forEach(t),Jl=i(Je," is sufficient."),Je.forEach(t),Es=p(e),_o=r(e,"P",{});var Tp=s(_o);Xl=i(Tp,"For example, the following command could be run on any device efficiently, without needing significant RAM or GPU:"),Tp.forEach(t),xs=p(e),d(Ht.$$.fragment,e),As=p(e),qe=r(e,"P",{});var An=s(qe);ei=i(An,"The same can be said for "),$o=r(An,"A",{href:!0});var kp=s($o);ti=i(kp,"chat()"),kp.forEach(t),oi=i(An,":"),An.forEach(t),Ts=p(e),d(Ct.$$.fragment,e),ks=p(e),ne=r(e,"H3",{class:!0});var Tn=s(ne);Oe=r(Tn,"A",{id:!0,class:!0,href:!0});var Pp=s(Oe);Ha=r(Pp,"SPAN",{});var Ip=s(Ha);d(Dt.$$.fragment,Ip),Ip.forEach(t),Pp.forEach(t),ai=p(Tn),Ca=r(Tn,"SPAN",{});var qp=s(Ca);ri=i(qp,"What's happening here? What are tools, and what are agents?"),qp.forEach(t),Tn.forEach(t),Ps=p(e),bo=r(e,"IMG",{src:!0}),Is=p(e),le=r(e,"H4",{class:!0});var kn=s(le);Se=r(kn,"A",{id:!0,class:!0,href:!0});var Op=s(Se);Da=r(Op,"SPAN",{});var Sp=s(Da);d(Gt.$$.fragment,Sp),Sp.forEach(t),Op.forEach(t),si=p(kn),Ga=r(kn,"SPAN",{});var Lp=s(Ga);ni=i(Lp,"Agents"),Lp.forEach(t),kn.forEach(t),qs=p(e),Eo=r(e,"P",{});var Rp=s(Eo);li=i(Rp,"The \u201Cagent\u201D here is a large language model, and we\u2019re prompting it so that it has access to a specific set of tools."),Rp.forEach(t),Os=p(e),xo=r(e,"P",{});var Np=s(xo);ii=i(Np,`LLMs are pretty good at generating small samples of code, so this API takes advantage of that by prompting the
LLM gives a small sample of code performing a task with a set of tools. This prompt is then completed by the
task you give your agent and the description of the tools you give it. This way it gets access to the doc of the
tools you are using, especially their expected inputs and outputs, and can generate the relevant code.`),Np.forEach(t),Ss=p(e),ie=r(e,"H4",{class:!0});var Pn=s(ie);Le=r(Pn,"A",{id:!0,class:!0,href:!0});var jp=s(Le);Ba=r(jp,"SPAN",{});var Hp=s(Ba);d(Bt.$$.fragment,Hp),Hp.forEach(t),jp.forEach(t),fi=p(Pn),Ma=r(Pn,"SPAN",{});var Cp=s(Ma);hi=i(Cp,"Tools"),Cp.forEach(t),Pn.forEach(t),Ls=p(e),Ao=r(e,"P",{});var Dp=s(Ao);pi=i(Dp,`Tools are very simple: they\u2019re a single function, with a name, and a description. We then use these tools\u2019 descriptions
to prompt the agent. Through the prompt, we show the agent how it would leverage tools to perform what was
requested in the query.`),Dp.forEach(t),Rs=p(e),To=r(e,"P",{});var Gp=s(To);ui=i(Gp,`This is using brand-new tools and not pipelines, because the agent writes better code with very atomic tools.
Pipelines are more refactored and often combine several tasks in one. Tools are meant to be focused on
one very simple task only.`),Gp.forEach(t),Ns=p(e),fe=r(e,"H4",{class:!0});var In=s(fe);Re=r(In,"A",{id:!0,class:!0,href:!0});var Bp=s(Re);Wa=r(Bp,"SPAN",{});var Mp=s(Wa);d(Mt.$$.fragment,Mp),Mp.forEach(t),Bp.forEach(t),ci=p(In),Fa=r(In,"SPAN",{});var Wp=s(Fa);mi=i(Wp,"Code-execution?!"),Wp.forEach(t),In.forEach(t),js=p(e),ko=r(e,"P",{});var Fp=s(ko);di=i(Fp,`This code is then executed with our small Python interpreter on the set of inputs passed along with your tools.
We hear you screaming \u201CArbitrary code execution!\u201D in the back, but let us explain why that is not the case.`),Fp.forEach(t),Hs=p(e),Po=r(e,"P",{});var Up=s(Po);gi=i(Up,`The only functions that can be called are the tools you provided and the print function, so you\u2019re already
limited in what can be executed. You should be safe if it\u2019s limited to Hugging Face tools.`),Up.forEach(t),Cs=p(e),Io=r(e,"P",{});var Yp=s(Io);vi=i(Yp,`Then, we don\u2019t allow any attribute lookup or imports (which shouldn\u2019t be needed anyway for passing along
inputs/outputs to a small set of functions) so all the most obvious attacks (and you\u2019d need to prompt the LLM
to output them anyway) shouldn\u2019t be an issue. If you want to be on the super safe side, you can execute the
run() method with the additional argument return_code=True, in which case the agent will just return the code
to execute and you can decide whether to do it or not.`),Yp.forEach(t),Ds=p(e),qo=r(e,"P",{});var zp=s(qo);wi=i(zp,`The execution will stop at any line trying to perform an illegal operation or if there is a regular Python error
with the code generated by the agent.`),zp.forEach(t),Gs=p(e),he=r(e,"H3",{class:!0});var qn=s(he);Ne=r(qn,"A",{id:!0,class:!0,href:!0});var Qp=s(Ne);Ua=r(Qp,"SPAN",{});var Kp=s(Ua);d(Wt.$$.fragment,Kp),Kp.forEach(t),Qp.forEach(t),yi=p(qn),Ya=r(qn,"SPAN",{});var Vp=s(Ya);_i=i(Vp,"A curated set of tools"),Vp.forEach(t),qn.forEach(t),Bs=p(e),je=r(e,"P",{});var On=s(je);$i=i(On,`We identify a set of tools that can empower such agents. Here is an updated list of the tools we have integrated
in `),za=r(On,"CODE",{});var Zp=s(za);bi=i(Zp,"transformers"),Zp.forEach(t),Ei=i(On,":"),On.forEach(t),Ms=p(e),E=r(e,"UL",{});var A=s(E);He=r(A,"LI",{});var wr=s(He);Qa=r(wr,"STRONG",{});var Jp=s(Qa);xi=i(Jp,"Document question answering"),Jp.forEach(t),Ai=i(wr,": given a document (such as a PDF) in image format, answer a question on this document ("),Oo=r(wr,"A",{href:!0});var Xp=s(Oo);Ti=i(Xp,"Donut"),Xp.forEach(t),ki=i(wr,")"),wr.forEach(t),Pi=p(A),Ce=r(A,"LI",{});var yr=s(Ce);Ka=r(yr,"STRONG",{});var eu=s(Ka);Ii=i(eu,"Text question answering"),eu.forEach(t),qi=i(yr,": given a long text and a question, answer the question in the text ("),So=r(yr,"A",{href:!0});var tu=s(So);Oi=i(tu,"Flan-T5"),tu.forEach(t),Si=i(yr,")"),yr.forEach(t),Li=p(A),De=r(A,"LI",{});var _r=s(De);Va=r(_r,"STRONG",{});var ou=s(Va);Ri=i(ou,"Unconditional image captioning"),ou.forEach(t),Ni=i(_r,": Caption the image! ("),Lo=r(_r,"A",{href:!0});var au=s(Lo);ji=i(au,"BLIP"),au.forEach(t),Hi=i(_r,")"),_r.forEach(t),Ci=p(A),Ge=r(A,"LI",{});var $r=s(Ge);Za=r($r,"STRONG",{});var ru=s(Za);Di=i(ru,"Image question answering"),ru.forEach(t),Gi=i($r,": given an image, answer a question on this image ("),Ro=r($r,"A",{href:!0});var su=s(Ro);Bi=i(su,"VILT"),su.forEach(t),Mi=i($r,")"),$r.forEach(t),Wi=p(A),Be=r(A,"LI",{});var br=s(Be);Ja=r(br,"STRONG",{});var nu=s(Ja);Fi=i(nu,"Image segmentation"),nu.forEach(t),Ui=i(br,": given an image and a prompt, output the segmentation mask of that prompt ("),No=r(br,"A",{href:!0});var lu=s(No);Yi=i(lu,"CLIPSeg"),lu.forEach(t),zi=i(br,")"),br.forEach(t),Qi=p(A),Me=r(A,"LI",{});var Er=s(Me);Xa=r(Er,"STRONG",{});var iu=s(Xa);Ki=i(iu,"Speech to text"),iu.forEach(t),Vi=i(Er,": given an audio recording of a person talking, transcribe the speech into text ("),jo=r(Er,"A",{href:!0});var fu=s(jo);Zi=i(fu,"Whisper"),fu.forEach(t),Ji=i(Er,")"),Er.forEach(t),Xi=p(A),We=r(A,"LI",{});var xr=s(We);er=r(xr,"STRONG",{});var hu=s(er);ef=i(hu,"Text to speech"),hu.forEach(t),tf=i(xr,": convert text to speech ("),Ho=r(xr,"A",{href:!0});var pu=s(Ho);of=i(pu,"SpeechT5"),pu.forEach(t),af=i(xr,")"),xr.forEach(t),rf=p(A),Fe=r(A,"LI",{});var Ar=s(Fe);tr=r(Ar,"STRONG",{});var uu=s(tr);sf=i(uu,"Zero-shot text classification"),uu.forEach(t),nf=i(Ar,": given a text and a list of labels, identify to which label the text corresponds the most ("),Co=r(Ar,"A",{href:!0});var cu=s(Co);lf=i(cu,"BART"),cu.forEach(t),ff=i(Ar,")"),Ar.forEach(t),hf=p(A),Ue=r(A,"LI",{});var Tr=s(Ue);or=r(Tr,"STRONG",{});var mu=s(or);pf=i(mu,"Text summarization"),mu.forEach(t),uf=i(Tr,": summarize a long text in one or a few sentences ("),Do=r(Tr,"A",{href:!0});var du=s(Do);cf=i(du,"BART"),du.forEach(t),mf=i(Tr,")"),Tr.forEach(t),df=p(A),Ye=r(A,"LI",{});var kr=s(Ye);ar=r(kr,"STRONG",{});var gu=s(ar);gf=i(gu,"Translation"),gu.forEach(t),vf=i(kr,": translate the text into a given language ("),Go=r(kr,"A",{href:!0});var vu=s(Go);wf=i(vu,"NLLB"),vu.forEach(t),yf=i(kr,")"),kr.forEach(t),A.forEach(t),Ws=p(e),Bo=r(e,"P",{});var wu=s(Bo);_f=i(wu,"These tools have an integration in transformers, and can be used manually as well, for example:"),wu.forEach(t),Fs=p(e),d(Ft.$$.fragment,e),Us=p(e),pe=r(e,"H3",{class:!0});var Sn=s(pe);ze=r(Sn,"A",{id:!0,class:!0,href:!0});var yu=s(ze);rr=r(yu,"SPAN",{});var _u=s(rr);d(Ut.$$.fragment,_u),_u.forEach(t),yu.forEach(t),$f=p(Sn),sr=r(Sn,"SPAN",{});var $u=s(sr);bf=i($u,"Custom tools"),$u.forEach(t),Sn.forEach(t),Ys=p(e),Mo=r(e,"P",{});var bu=s(Mo);Ef=i(bu,`While we identify a curated set of tools, we strongly believe that the main value provided by this implementation is
the ability to quickly create and share custom tools.`),bu.forEach(t),zs=p(e),Z=r(e,"P",{});var ta=s(Z);xf=i(ta,`By pushing the code of a tool to a Hugging Face Space or a model repository, you\u2019re then able to leverage the tool
directly with the agent. We\u2019ve added a few
`),nr=r(ta,"STRONG",{});var Eu=s(nr);Af=i(Eu,"transformers-agnostic"),Eu.forEach(t),Tf=i(ta," tools to the "),Qe=r(ta,"A",{href:!0,rel:!0});var oh=s(Qe);lr=r(oh,"CODE",{});var xu=s(lr);kf=i(xu,"huggingface-tools"),xu.forEach(t),Pf=i(oh," organization"),oh.forEach(t),If=i(ta,":"),ta.forEach(t),Qs=p(e),G=r(e,"UL",{});var Xe=s(G);Wo=r(Xe,"LI",{});var ah=s(Wo);ir=r(ah,"STRONG",{});var Au=s(ir);qf=i(Au,"Text downloader"),Au.forEach(t),Of=i(ah,": to download a text from a web URL"),ah.forEach(t),Sf=p(Xe),Fo=r(Xe,"LI",{});var rh=s(Fo);fr=r(rh,"STRONG",{});var Tu=s(fr);Lf=i(Tu,"Text to image"),Tu.forEach(t),Rf=i(rh,": generate an image according to a prompt, leveraging stable diffusion"),rh.forEach(t),Nf=p(Xe),Uo=r(Xe,"LI",{});var sh=s(Uo);hr=r(sh,"STRONG",{});var ku=s(hr);jf=i(ku,"Image transformation"),ku.forEach(t),Hf=i(sh,": modify an image given an initial image and a prompt, leveraging instruct pix2pix stable diffusion"),sh.forEach(t),Cf=p(Xe),Yo=r(Xe,"LI",{});var nh=s(Yo);pr=r(nh,"STRONG",{});var Pu=s(pr);Df=i(Pu,"Text to video"),Pu.forEach(t),Gf=i(nh,": generate a small video according to a prompt, leveraging damo-vilab"),nh.forEach(t),Xe.forEach(t),Ks=p(e),Ke=r(e,"P",{});var Ln=s(Ke);Bf=i(Ln,`The text-to-image tool we have been using since the beginning is a remote tool that lives in
`),Yt=r(Ln,"A",{href:!0,rel:!0});var Iu=s(Yt);ur=r(Iu,"EM",{});var qu=s(ur);Mf=i(qu,"huggingface-tools/text-to-image"),qu.forEach(t),Iu.forEach(t),Wf=i(Ln,`! We will
continue releasing such tools on this and other organizations, to further supercharge this implementation.`),Ln.forEach(t),Vs=p(e),J=r(e,"P",{});var oa=s(J);Ff=i(oa,"The agents have by default access to tools that reside on "),zt=r(oa,"A",{href:!0,rel:!0});var Ou=s(zt);cr=r(Ou,"CODE",{});var Su=s(cr);Uf=i(Su,"huggingface-tools"),Su.forEach(t),Ou.forEach(t),Yf=i(oa,`.
We explain how to you can write and share your tools as well as leverage any custom tool that resides on the Hub in `),zo=r(oa,"A",{href:!0});var Lu=s(zo);zf=i(Lu,"following guide"),Lu.forEach(t),Qf=i(oa,"."),oa.forEach(t),Zs=p(e),ue=r(e,"H3",{class:!0});var Rn=s(ue);Ve=r(Rn,"A",{id:!0,class:!0,href:!0});var Ru=s(Ve);mr=r(Ru,"SPAN",{});var Nu=s(mr);d(Qt.$$.fragment,Nu),Nu.forEach(t),Ru.forEach(t),Kf=p(Rn),dr=r(Rn,"SPAN",{});var ju=s(dr);Vf=i(ju,"Code generation"),ju.forEach(t),Rn.forEach(t),Js=p(e),Qo=r(e,"P",{});var Hu=s(Qo);Zf=i(Hu,`So far we have shown how to use the agents to perform actions for you. However, the agent is only generating code
that we then execute using a very restricted Python interpreter. In case you would like to use the code generated in
a different setting, the agent can be prompted to return the code, along with tool definition and accurate imports.`),Hu.forEach(t),Xs=p(e),Ko=r(e,"P",{});var Cu=s(Ko);Jf=i(Cu,"For example, the following instruction"),Cu.forEach(t),en=p(e),d(Kt.$$.fragment,e),tn=p(e),Vo=r(e,"P",{});var Du=s(Vo);Xf=i(Du,"returns the following code"),Du.forEach(t),on=p(e),d(Vt.$$.fragment,e),an=p(e),Zo=r(e,"P",{});var Gu=s(Zo);eh=i(Gu,"that you can then modify and execute yourself."),Gu.forEach(t),this.h()},h(){u(_,"name","hf:doc:metadata"),u(_,"content",JSON.stringify(Zu)),u(b,"id","transformers-agent"),u(b,"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"),u(b,"href","#transformers-agent"),u($,"class","relative group"),u(S,"href","https://colab.research.google.com/drive/1c7MHD-T1forUPGcC_jlwsIptOzpG3hSj"),u(S,"rel","nofollow"),et(eo.src,ih="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/beaver.png")||u(eo,"src",ih),u(eo,"width","200"),et(to.src,fh="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tts_example.wav")||u(to,"src",fh),u(to,"type","audio/wav"),mt.controls=!0,et(oo.src,hh="https://datasets-server.huggingface.co/assets/hf-internal-testing/example-documents/--/hf-internal-testing--example-documents/test/0/image/image.jpg")||u(oo,"src",hh),u(oo,"width","200"),u(we,"id","quickstart"),u(we,"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"),u(we,"href","#quickstart"),u(oe,"class","relative group"),u(ao,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.OpenAiAgent"),u(be,"id","single-execution-run"),u(be,"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"),u(be,"href","#single-execution-run"),u(ae,"class","relative group"),u(io,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.run"),et(Tt.src,ph="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes.png")||u(Tt,"src",ph),u(Tt,"width","200"),et(Pt.src,uh="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/sea_and_island.png")||u(Pt,"src",uh),u(Pt,"width","200"),u(ho,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.run"),u(po,"href","custom_tools#writing-good-user-inputs"),u(Te,"id","chatbased-execution-chat"),u(Te,"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"),u(Te,"href","#chatbased-execution-chat"),u(re,"class","relative group"),u(co,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.chat"),et(St.src,ch="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes.png")||u(St,"src",ch),u(St,"width","200"),et(Rt.src,mh="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes_and_beaver.png")||u(Rt,"src",mh),u(Rt,"width","200"),u(mo,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.run"),u(Ie,"id","remote-execution"),u(Ie,"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"),u(Ie,"href","#remote-execution"),u(se,"class","relative group"),u(jt,"href","https://huggingface.co/inference-endpoints"),u(jt,"rel","nofollow"),u(vo,"href","./custom_tools"),u(wo,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.run"),u(yo,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.chat"),u($o,"href","/docs/transformers/v4.29.0/en/main_classes/agent#transformers.Agent.chat"),u(Oe,"id","whats-happening-here-what-are-tools-and-what-are-agents"),u(Oe,"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"),u(Oe,"href","#whats-happening-here-what-are-tools-and-what-are-agents"),u(ne,"class","relative group"),et(bo.src,dh="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/diagram.png")||u(bo,"src",dh),u(Se,"id","agents"),u(Se,"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"),u(Se,"href","#agents"),u(le,"class","relative group"),u(Le,"id","tools"),u(Le,"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"),u(Le,"href","#tools"),u(ie,"class","relative group"),u(Re,"id","codeexecution"),u(Re,"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"),u(Re,"href","#codeexecution"),u(fe,"class","relative group"),u(Ne,"id","a-curated-set-of-tools"),u(Ne,"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"),u(Ne,"href","#a-curated-set-of-tools"),u(he,"class","relative group"),u(Oo,"href","./model_doc/donut"),u(So,"href","./model_doc/flan-t5"),u(Lo,"href","./model_doc/blip"),u(Ro,"href","./model_doc/vilt"),u(No,"href","./model_doc/clipseg"),u(jo,"href","./model_doc/whisper"),u(Ho,"href","./model_doc/speecht5"),u(Co,"href","./model_doc/bart"),u(Do,"href","./model_doc/bart"),u(Go,"href","./model_doc/nllb"),u(ze,"id","custom-tools"),u(ze,"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"),u(ze,"href","#custom-tools"),u(pe,"class","relative group"),u(Qe,"href","https://huggingface.co/huggingface-tools"),u(Qe,"rel","nofollow"),u(Yt,"href","https://huggingface.co/spaces/huggingface-tools/text-to-image"),u(Yt,"rel","nofollow"),u(zt,"href","https://huggingface.co/huggingface-tools"),u(zt,"rel","nofollow"),u(zo,"href","custom_tools"),u(Ve,"id","code-generation"),u(Ve,"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"),u(Ve,"href","#code-generation"),u(ue,"class","relative group")},m(e,n){o(document.head,_),f(e,k,n),f(e,$,n),o($,b),o(b,W),g(I,W,null),o($,tt),o($,F),o(F,N),f(e,j,n),g(H,e,n),f(e,U,n),f(e,P,n),o(P,ot),o(P,X),o(X,O),o(P,at),o(P,M),o(M,rt),o(P,st),o(P,S),o(S,nt),o(P,lt),f(e,ee,n),f(e,L,n),o(L,it),f(e,te,n),f(e,q,n),o(q,me),f(e,c,n),g(x,e,n),f(e,ft,n),f(e,R,n),o(R,Y),o(Y,z),o(z,C),o(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,dl),o(ae,qa),o(qa,gl),f(e,Zr,n),f(e,Ee,n),o(Ee,vl),o(Ee,io),o(io,wl),o(Ee,yl),f(e,Jr,n),g(At,e,n),f(e,Xr,n),f(e,Tt,n),f(e,es,n),f(e,fo,n),o(fo,_l),f(e,ts,n),g(kt,e,n),f(e,os,n),f(e,Pt,n),f(e,as,n),f(e,rs,n),f(e,ss,n),f(e,xe,n),o(xe,$l),o(xe,ho),o(ho,bl),o(xe,El),f(e,ns,n),f(e,K,n),o(K,xl),o(K,Oa),o(Oa,Al),o(K,Tl),o(K,po),o(po,kl),o(K,Pl),f(e,ls,n),f(e,uo,n),o(uo,Il),f(e,is,n),g(It,e,n),f(e,fs,n),g(Ae,e,n),f(e,hs,n),f(e,re,n),o(re,Te),o(Te,Sa),g(qt,Sa,null),o(re,ql),o(re,La),o(La,Ol),f(e,ps,n),f(e,ke,n),o(ke,Sl),o(ke,co),o(co,Ll),o(ke,Rl),f(e,us,n),g(Ot,e,n),f(e,cs,n),f(e,St,n),f(e,ms,n),g(Lt,e,n),f(e,ds,n),f(e,Rt,n),f(e,gs,n),f(e,vs,n),f(e,ws,n),f(e,Pe,n),o(Pe,Nl),o(Pe,mo),o(mo,jl),o(Pe,Hl),f(e,ys,n),f(e,go,n),o(go,Cl),f(e,_s,n),f(e,se,n),o(se,Ie),o(Ie,Ra),g(Nt,Ra,null),o(se,Dl),o(se,Na),o(Na,Gl),f(e,$s,n),f(e,V,n),o(V,Bl),o(V,jt),o(jt,Ml),o(V,Wl),o(V,vo),o(vo,Fl),o(V,Ul),f(e,bs,n),f(e,D,n),o(D,Yl),o(D,ja),o(ja,zl),o(D,Ql),o(D,wo),o(wo,Kl),o(D,Vl),o(D,yo),o(yo,Zl),o(D,Jl),f(e,Es,n),f(e,_o,n),o(_o,Xl),f(e,xs,n),g(Ht,e,n),f(e,As,n),f(e,qe,n),o(qe,ei),o(qe,$o),o($o,ti),o(qe,oi),f(e,Ts,n),g(Ct,e,n),f(e,ks,n),f(e,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e,on,n),g(Vt,e,n),f(e,an,n),f(e,Zo,n),o(Zo,eh),rn=!0},p(e,[n]){const Zt={};n&2&&(Zt.$$scope={dirty:n,ctx:e}),H.$set(Zt);const gr={};n&2&&(gr.$$scope={dirty:n,ctx:e}),$e.$set(gr);const vr={};n&2&&(vr.$$scope={dirty:n,ctx:e}),Ae.$set(vr)},i(e){rn||(v(I.$$.fragment,e),v(H.$$.fragment,e),v(x.$$.fragment,e),v(pt.$$.fragment,e),v(dt.$$.fragment,e),v(wt.$$.fragment,e),v(yt.$$.fragment,e),v(_t.$$.fragment,e),v($t.$$.fragment,e),v(bt.$$.fragment,e),v(Et.$$.fragment,e),v($e.$$.fragment,e),v(xt.$$.fragment,e),v(At.$$.fragment,e),v(kt.$$.fragment,e),v(It.$$.fragment,e),v(Ae.$$.fragment,e),v(qt.$$.fragment,e),v(Ot.$$.fragment,e),v(Lt.$$.fragment,e),v(Nt.$$.fragment,e),v(Ht.$$.fragment,e),v(Ct.$$.fragment,e),v(Dt.$$.fragment,e),v(Gt.$$.fragment,e),v(Bt.$$.fragment,e),v(Mt.$$.fragment,e),v(Wt.$$.fragment,e),v(Ft.$$.fragment,e),v(Ut.$$.fragment,e),v(Qt.$$.fragment,e),v(Kt.$$.fragment,e),v(Vt.$$.fragment,e),rn=!0)},o(e){w(I.$$.fragment,e),w(H.$$.fragment,e),w(x.$$.fragment,e),w(pt.$$.fragment,e),w(dt.$$.fragment,e),w(wt.$$.fragment,e),w(yt.$$.fragment,e),w(_t.$$.fragment,e),w($t.$$.fragment,e),w(bt.$$.fragment,e),w(Et.$$.fragment,e),w($e.$$.fragment,e),w(xt.$$.fragment,e),w(At.$$.fragment,e),w(kt.$$.fragment,e),w(It.$$.fragment,e),w(Ae.$$.fragment,e),w(qt.$$.fragment,e),w(Ot.$$.fragment,e),w(Lt.$$.fragment,e),w(Nt.$$.fragment,e),w(Ht.$$.fragment,e),w(Ct.$$.fragment,e),w(Dt.$$.fragment,e),w(Gt.$$.fragment,e),w(Bt.$$.fragment,e),w(Mt.$$.fragment,e),w(Wt.$$.fragment,e),w(Ft.$$.fragment,e),w(Ut.$$.fragment,e),w(Qt.$$.fragment,e),w(Kt.$$.fragment,e),w(Vt.$$.fragment,e),rn=!1},d(e){t(_),e&&t(k),e&&t($),y(I),e&&t(j),y(H,e),e&&t(U),e&&t(P),e&&t(ee),e&&t(L),e&&t(te),e&&t(q),e&&t(c),y(x,e),e&&t(ft),e&&t(R),e&&t(Pr),e&&t(Ir),e&&t(qr),y(pt,e),e&&t(Or),e&&t(ge),e&&t(Sr),e&&t(Lr),e&&t(Rr),y(dt,e),e&&t(Nr),e&&t(ve),e&&t(jr),e&&t(oe),y(wt),e&&t(Hr),e&&t(ye),e&&t(Cr),e&&t(_e),e&&t(Dr),y(yt,e),e&&t(Gr),e&&t(Q),e&&t(Br),y(_t,e),e&&t(Mr),y($t,e),e&&t(Wr),e&&t(ro),e&&t(Fr),y(bt,e),e&&t(Ur),e&&t(so),e&&t(Yr),y(Et,e),e&&t(zr),e&&t(no),e&&t(Qr),y($e,e),e&&t(Kr),e&&t(lo),e&&t(Vr),e&&t(ae),y(xt),e&&t(Zr),e&&t(Ee),e&&t(Jr),y(At,e),e&&t(Xr),e&&t(Tt),e&&t(es),e&&t(fo),e&&t(ts),y(kt,e),e&&t(os),e&&t(Pt),e&&t(as),e&&t(rs),e&&t(ss),e&&t(xe),e&&t(ns),e&&t(K),e&&t(ls),e&&t(uo),e&&t(is),y(It,e),e&&t(fs),y(Ae,e),e&&t(hs),e&&t(re),y(qt),e&&t(ps),e&&t(ke),e&&t(us),y(Ot,e),e&&t(cs),e&&t(St),e&&t(ms),y(Lt,e),e&&t(ds),e&&t(Rt),e&&t(gs),e&&t(vs),e&&t(ws),e&&t(Pe),e&&t(ys),e&&t(go),e&&t(_s),e&&t(se),y(Nt),e&&t($s),e&&t(V),e&&t(bs),e&&t(D),e&&t(Es),e&&t(_o),e&&t(xs),y(Ht,e),e&&t(As),e&&t(qe),e&&t(Ts),y(Ct,e),e&&t(ks),e&&t(ne),y(Dt),e&&t(Ps),e&&t(bo),e&&t(Is),e&&t(le),y(Gt),e&&t(qs),e&&t(Eo),e&&t(Os),e&&t(xo),e&&t(Ss),e&&t(ie),y(Bt),e&&t(Ls),e&&t(Ao),e&&t(Rs),e&&t(To),e&&t(Ns),e&&t(fe),y(Mt),e&&t(js),e&&t(ko),e&&t(Hs),e&&t(Po),e&&t(Cs),e&&t(Io),e&&t(Ds),e&&t(qo),e&&t(Gs),e&&t(he),y(Wt),e&&t(Bs),e&&t(je),e&&t(Ms),e&&t(E),e&&t(Ws),e&&t(Bo),e&&t(Fs),y(Ft,e),e&&t(Us),e&&t(pe),y(Ut),e&&t(Ys),e&&t(Mo),e&&t(zs),e&&t(Z),e&&t(Qs),e&&t(G),e&&t(Ks),e&&t(Ke),e&&t(Vs),e&&t(J),e&&t(Zs),e&&t(ue),y(Qt),e&&t(Js),e&&t(Qo),e&&t(Xs),e&&t(Ko),e&&t(en),y(Kt,e),e&&t(tn),e&&t(Vo),e&&t(on),y(Vt,e),e&&t(an),e&&t(Zo)}}}const Zu={local:"transformers-agent",sections:[{local:"quickstart",sections:[{local:"single-execution-run",title:"Single execution (run)"},{local:"chatbased-execution-chat",title:"Chat-based execution (chat)"},{local:"remote-execution",title:"\u26A0\uFE0F Remote execution"},{local:"whats-happening-here-what-are-tools-and-what-are-agents",sections:[{local:"agents",title:"Agents"},{local:"tools",title:"Tools"},{local:"codeexecution",title:"Code-execution?!"}],title:"What's happening here? What are tools, and what are agents?"},{local:"a-curated-set-of-tools",title:"A curated set of tools"},{local:"custom-tools",title:"Custom tools"},{local:"code-generation",title:"Code generation"}],title:"Quickstart"}],title:"Transformers Agent"};function Ju(ce){return Uu(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ac extends Bu{constructor(_){super();Mu(this,_,Ju,Vu,Wu,{})}}export{ac as default,Zu as metadata};
