import{S as vb,i as Jb,s as Ub,e as n,k as p,w as u,t as a,M as Tb,c as i,d as t,m,a as h,x as c,h as s,b as f,N as $n,G as o,g as r,y as w,q as y,o as M,B as b,v as Eb}from"../chunks/vendor-hf-doc-builder.js";import{T as re}from"../chunks/Tip-hf-doc-builder.js";import{I as S}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as J}from"../chunks/CodeBlock-hf-doc-builder.js";function $b(Z){let d,U,g,v,$;return{c(){d=n("p"),U=a(`If you are not aware of what tools and agents are in the context of transformers, we recommend you read the
`),g=n("a"),v=a("Transformers Agents"),$=a(" page first."),this.h()},l(T){d=i(T,"P",{});var E=h(d);U=s(E,`If you are not aware of what tools and agents are in the context of transformers, we recommend you read the
`),g=i(E,"A",{href:!0});var j=h(g);v=s(j,"Transformers Agents"),j.forEach(t),$=s(E," page first."),E.forEach(t),this.h()},h(){f(g,"href","transformers_agents")},m(T,E){r(T,d,E),o(d,U),o(d,g),o(g,v),o(d,$)},d(T){T&&t(d)}}}function Zb(Z){let d,U;return{c(){d=n("p"),U=a(`Transformers Agent is an experimental API that 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(g){d=i(g,"P",{});var v=h(d);U=s(v,`Transformers Agent is an experimental API that is subject to change at any time. Results returned by the agents
can vary as the APIs or underlying models are prone to change.`),v.forEach(t)},m(g,v){r(g,d,v),o(d,U)},d(g){g&&t(d)}}}function jb(Z){let d,U,g,v,$;return{c(){d=n("p"),U=a(`Check the naming and description of the curated Transformers tools to better understand what name and
description a tool is expected to have. You can see all tools with the `),g=n("code"),v=a("Agent.toolbox"),$=a(" property.")},l(T){d=i(T,"P",{});var E=h(d);U=s(E,`Check the naming and description of the curated Transformers tools to better understand what name and
description a tool is expected to have. You can see all tools with the `),g=i(E,"CODE",{});var j=h(g);v=s(j,"Agent.toolbox"),j.forEach(t),$=s(E," property."),E.forEach(t)},m(T,E){r(T,d,E),o(d,U),o(d,g),o(g,v),o(d,$)},d(T){T&&t(d)}}}function Gb(Z){let d,U;return{c(){d=n("p"),U=a(`Agents are still brittle for many use cases, especially when it comes to
slightly more complex use cases like generating an image of multiple objects.
Both the agent itself and the underlying prompt will be further improved in the coming
months making sure that agents become more robust to a variety of user inputs.`)},l(g){d=i(g,"P",{});var v=h(d);U=s(v,`Agents are still brittle for many use cases, especially when it comes to
slightly more complex use cases like generating an image of multiple objects.
Both the agent itself and the underlying prompt will be further improved in the coming
months making sure that agents become more robust to a variety of user inputs.`),v.forEach(t)},m(g,v){r(g,d,v),o(d,U)},d(g){g&&t(d)}}}function Ib(Z){let d,U,g,v,$,T,E,j,k,B,R;return{c(){d=n("p"),U=a("Please make sure to have the "),g=n("code"),v=a("<<all_tools>>"),$=a(" string and the "),T=n("code"),E=a("<<prompt>>"),j=a(" defined somewhere in the "),k=n("code"),B=a("template"),R=a(` so that the agent can be aware
of the tools, it has available to it as well as correctly insert the user\u2019s prompt.`)},l(X){d=i(X,"P",{});var I=h(d);U=s(I,"Please make sure to have the "),g=i(I,"CODE",{});var Mt=h(g);v=s(Mt,"<<all_tools>>"),Mt.forEach(t),$=s(I," string and the "),T=i(I,"CODE",{});var he=h(T);E=s(he,"<<prompt>>"),he.forEach(t),j=s(I," defined somewhere in the "),k=i(I,"CODE",{});var zo=h(k);B=s(zo,"template"),zo.forEach(t),R=s(I,` so that the agent can be aware
of the tools, it has available to it as well as correctly insert the user\u2019s prompt.`),I.forEach(t)},m(X,I){r(X,d,I),o(d,U),o(d,g),o(g,v),o(d,$),o(d,T),o(T,E),o(d,j),o(d,k),o(k,B),o(d,R)},d(X){X&&t(d)}}}function _b(Z){let d,U,g,v,$,T,E,j;return{c(){d=n("p"),U=a("Please make sure to have the "),g=n("code"),v=a("<<all_tools>>"),$=a(" string defined somewhere in the "),T=n("code"),E=a("template"),j=a(` so that the agent can be aware
of the tools, it has available to it.`)},l(k){d=i(k,"P",{});var B=h(d);U=s(B,"Please make sure to have the "),g=i(B,"CODE",{});var R=h(g);v=s(R,"<<all_tools>>"),R.forEach(t),$=s(B," string defined somewhere in the "),T=i(B,"CODE",{});var X=h(T);E=s(X,"template"),X.forEach(t),j=s(B,` so that the agent can be aware
of the tools, it has available to it.`),B.forEach(t)},m(k,B){r(k,d,B),o(d,U),o(d,g),o(g,v),o(d,$),o(d,T),o(T,E),o(d,j)},d(k){k&&t(d)}}}function Wb(Z){let d,U;return{c(){d=n("p"),U=a(`Overwriting existing tools can be beneficial if we want to use a custom tool exactly for the same task as an existing tool
because the agent is well-versed in using the specific task. Beware that the custom tool should follow the exact same API
as the overwritten tool in this case, or you should adapt the prompt template to make sure all examples using that
tool are updated.`)},l(g){d=i(g,"P",{});var v=h(d);U=s(v,`Overwriting existing tools can be beneficial if we want to use a custom tool exactly for the same task as an existing tool
because the agent is well-versed in using the specific task. Beware that the custom tool should follow the exact same API
as the overwritten tool in this case, or you should adapt the prompt template to make sure all examples using that
tool are updated.`),v.forEach(t)},m(g,v){r(g,d,v),o(d,U)},d(g){g&&t(d)}}}function Bb(Z){let d,U;return{c(){d=n("p"),U=a(`Depending on the LLM, some are quite brittle and require very exact prompts in order to work well. Having a well-defined
name and description of the tool is paramount to having it be leveraged by the agent.`)},l(g){d=i(g,"P",{});var v=h(d);U=s(v,`Depending on the LLM, some are quite brittle and require very exact prompts in order to work well. Having a well-defined
name and description of the tool is paramount to having it be leveraged by the agent.`),v.forEach(t)},m(g,v){r(g,d,v),o(d,U)},d(g){g&&t(d)}}}function kb(Z){let d,U;return{c(){d=n("p"),U=a(`Beware when replacing tools with others! This will also adjust the agent\u2019s prompt. This can be good if you have a better
prompt suited for the task, but it can also result in your tool being selected way more than others or for other
tools to be selected instead of the one you have defined.`)},l(g){d=i(g,"P",{});var v=h(d);U=s(v,`Beware when replacing tools with others! This will also adjust the agent\u2019s prompt. This can be good if you have a better
prompt suited for the task, but it can also result in your tool being selected way more than others or for other
tools to be selected instead of the one you have defined.`),v.forEach(t)},m(g,v){r(g,d,v),o(d,U)},d(g){g&&t(d)}}}function Rb(Z){let d,U,g,v,$;return{c(){d=n("p"),U=a("gradio-tools requires "),g=n("em"),v=a("textual"),$=a(` inputs and outputs, even when working with different modalities. This implementation
works with image and audio objects. The two are currently incompatible, but will rapidly become compatible as we
work to improve the support.`)},l(T){d=i(T,"P",{});var E=h(d);U=s(E,"gradio-tools requires "),g=i(E,"EM",{});var j=h(g);v=s(j,"textual"),j.forEach(t),$=s(E,` inputs and outputs, even when working with different modalities. This implementation
works with image and audio objects. The two are currently incompatible, but will rapidly become compatible as we
work to improve the support.`),E.forEach(t)},m(T,E){r(T,d,E),o(d,U),o(d,g),o(g,v),o(d,$)},d(T){T&&t(d)}}}function Cb(Z){let d,U,g,v,$,T,E,j,k,B,R,X,I,Mt,he,zo,Zn,A,ia,rp,hp,ra,pp,mp,ha,dp,jn,pe,Ee,pa,bt,fp,ma,up,Gn,_,cp,qo,wp,yp,Ao,Mp,bp,Po,gp,vp,da,Jp,Up,fa,Tp,Ep,ua,$p,Zp,In,me,$e,ca,gt,jp,wa,Gp,_n,Lo,Ip,Wn,Q,ya,Ma,ba,_p,Wp,ga,Do,vt,Bp,va,kp,Rp,Cp,Ja,Oo,Ua,Yp,Np,Ta,Ko,Ea,xp,Bn,Ze,Hp,$a,Xp,Sp,kn,Jt,Rn,je,Qp,Za,Vp,Fp,Cn,C,zp,ja,qp,Ap,Ga,Pp,Lp,Ia,Dp,Op,_a,Kp,em,Yn,Ut,Nn,el,tm,xn,Tt,Hn,tl,om,Xn,Et,Sn,ol,lm,Qn,ll,am,Vn,Ge,Fn,al,sm,zn,sl,nm,qn,$t,An,nl,im,Pn,Ie,rm,Zt,hm,pm,Ln,il,mm,Dn,jt,On,rl,dm,Kn,Gt,ei,P,fm,Wa,um,cm,Ba,wm,ym,ti,_e,Mm,ka,bm,gm,oi,It,li,G,vm,Ra,Jm,Um,Ca,Tm,Em,Ya,$m,Zm,Na,jm,Gm,xa,Im,_m,Ha,Wm,Bm,Xa,km,Rm,Sa,Cm,Ym,ai,L,Nm,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4lMjIpJTBBaW1hZ2UlMjAlM0QlMjBpbWFnZV9nZW5lcmF0b3IoJTIyQSUyMGJhbm5lciUyMHNob3dpbmclMjAlMjIlMjAlMkIlMjBhbnN3ZXIpJTBBJTYwJTYwJTYwJTBBJTBBJTVCLi4uJTVEJTBBJTBBVGFzayUzQSUyMCUyMkRyYXclMjBtZSUyMGElMjBwaWN0dXJlJTIwb2YlMjByaXZlcnMlMjBhbmQlMjBsYWtlcyUyMiUwQSUwQUklMjB3aWxsJTIwdXNlJTIwdGhlJTIwZm9sbG93aW5n",highlighted:`I will ask you to perform a task, your job is to come up with a series of simple commands in Python that will perform the task.
[...]
You can print intermediate results if it makes sense to do so.

Tools:
- document_qa: This is a tool that answers a question about a document (pdf). It takes an input named \`document\` which should be the document containing the information, as well as a \`question\` that is the question about the document. It returns a text that contains the answer to the question.
- image_captioner: This is a tool that generates a description of an image. It takes an input named \`image\` which should be the image to the caption and returns a text that contains the description in English.
[...]

Task: &quot;Answer the question in the variable \`question\` about the image stored in the variable \`image\`. The question is in French.&quot;

I will use the following tools: \`translator\` to translate the question into English and then \`image_qa\` to answer the question on the input image.

Answer:
\`\`\`py
translated_question = translator(question=question, src_lang=&quot;French&quot;, tgt_lang=&quot;English&quot;)
print(f&quot;The translated question is {translated_question}.&quot;)
answer = image_qa(image=image, question=translated_question)
print(f&quot;The answer is {answer}&quot;)
\`\`\`

Task: &quot;Identify the oldest person in the \`document\` and create an image showcasing the result as a banner.&quot;

I will use the following tools: \`document_qa\` to find the oldest person in the document, then \`image_generator\` to generate an image according to the answer.

Answer:
\`\`\`py
answer = document_qa(document, question=&quot;What is the oldest person?&quot;)
print(f&quot;The answer is {answer}.&quot;)
image = image_generator(&quot;A banner showing &quot; + answer)
\`\`\`

[...]

Task: &quot;Draw me a picture of rivers and lakes&quot;

I will use the following`}}),Ut=new J({props:{code:"LSUyMCUzQ3Rvb2wubmFtZSUzRSUzQSUyMCUzQ3Rvb2wuZGVzY3JpcHRpb24lM0U=",highlighted:"- &lt;tool.name&gt;: &lt;tool.description&gt;"}}),Tt=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGxvYWRfdG9vbCUwQSUwQWRvY3VtZW50X3FhJTIwJTNEJTIwbG9hZF90b29sKCUyMmRvY3VtZW50LXF1ZXN0aW9uLWFuc3dlcmluZyUyMiklMEFwcmludChmJTIyLSUyMCU3QmRvY3VtZW50X3FhLm5hbWUlN0QlM0ElMjAlN0Jkb2N1bWVudF9xYS5kZXNjcmlwdGlvbiU3RCUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> load_tool

document_qa = load_tool(<span class="hljs-string">&quot;document-question-answering&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;- <span class="hljs-subst">{document_qa.name}</span>: <span class="hljs-subst">{document_qa.description}</span>&quot;</span>)`}}),Et=new J({props:{code:"LSUyMGRvY3VtZW50X3FhJTNBJTIwVGhpcyUyMGlzJTIwYSUyMHRvb2wlMjB0aGF0JTIwYW5zd2VycyUyMGElMjBxdWVzdGlvbiUyMGFib3V0JTIwYSUyMGRvY3VtZW50JTIwKHBkZikuJTIwSXQlMjB0YWtlcyUyMGFuJTIwaW5wdXQlMjBuYW1lZCUyMCU2MGRvY3VtZW50JTYwJTIwd2hpY2glMjBzaG91bGQlMjBiZSUyMHRoZSUyMGRvY3VtZW50JTIwY29udGFpbmluZyUyMHRoZSUyMGluZm9ybWF0aW9uJTJDJTIwYXMlMjB3ZWxsJTIwYXMlMjBhJTIwJTYwcXVlc3Rpb24lNjAlMjB0aGF0JTIwaXMlMjB0aGUlMjBxdWVzdGlvbiUyMGFib3V0JTIwdGhlJTIwZG9jdW1lbnQuJTIwSXQlMjByZXR1cm5zJTIwYSUyMHRleHQlMjB0aGF0JTIwY29udGFpbnMlMjB0aGUlMjBhbnN3ZXIlMjB0byUyMHRoZSUyMHF1ZXN0aW9uLg==",highlighted:"- document_qa: This is a tool that answers a question about a document (pdf). It takes an input named `document` which should be the document containing the information, as well as a `question` that is the question about the document. It returns a text that contains the answer to the question."}}),Ge=new re({props:{$$slots:{default:[jb]},$$scope:{ctx:Z}}}),$t=new J({props:{code:"VGFzayUzQSUyMCUyMklkZW50aWZ5JTIwdGhlJTIwb2xkZXN0JTIwcGVyc29uJTIwaW4lMjB0aGUlMjAlNjBkb2N1bWVudCU2MCUyMGFuZCUyMGNyZWF0ZSUyMGFuJTIwaW1hZ2UlMjBzaG93Y2FzaW5nJTIwdGhlJTIwcmVzdWx0JTIwYXMlMjBhJTIwYmFubmVyLiUyMiUwQSUwQUklMjB3aWxsJTIwdXNlJTIwdGhlJTIwZm9sbG93aW5nJTIwdG9vbHMlM0ElMjAlNjBkb2N1bWVudF9xYSU2MCUyMHRvJTIwZmluZCUyMHRoZSUyMG9sZGVzdCUyMHBlcnNvbiUyMGluJTIwdGhlJTIwZG9jdW1lbnQlMkMlMjB0aGVuJTIwJTYwaW1hZ2VfZ2VuZXJhdG9yJTYwJTIwdG8lMjBnZW5lcmF0ZSUyMGFuJTIwaW1hZ2UlMjBhY2NvcmRpbmclMjB0byUyMHRoZSUyMGFuc3dlci4lMEElMEFBbnN3ZXIlM0ElMEElNjAlNjAlNjBweSUwQWFuc3dlciUyMCUzRCUyMGRvY3VtZW50X3FhKGRvY3VtZW50JTJDJTIwcXVlc3Rpb24lM0QlMjJXaGF0JTIwaXMlMjB0aGUlMjBvbGRlc3QlMjBwZXJzb24lM0YlMjIpJTBBcHJpbnQoZiUyMlRoZSUyMGFuc3dlciUyMGlzJTIwJTdCYW5zd2VyJTdELiUyMiklMEFpbWFnZSUyMCUzRCUyMGltYWdlX2dlbmVyYXRvciglMjJBJTIwYmFubmVyJTIwc2hvd2luZyUyMCUyMiUyMCUyQiUyMGFuc3dlciklMEElNjAlNjAlNjAlMEE=",highlighted:"Task: &quot;Identify the oldest person in the `document` and create an image showcasing the result as a banner.&quot;\n\nI will use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer.\n\nAnswer:\n```py\nanswer = document_qa(document, question=&quot;What is the oldest person?&quot;)\nprint(f&quot;The answer is {answer}.&quot;)\nimage = image_generator(&quot;A banner showing &quot; + answer)\n```\n"}}),jt=new J({props:{code:"VGFzayUzQSUyMCUyMkRyYXclMjBtZSUyMGElMjBwaWN0dXJlJTIwb2YlMjByaXZlcnMlMjBhbmQlMjBsYWtlcyUyMiUwQSUwQUklMjB3aWxsJTIwdXNlJTIwdGhlJTIwZm9sbG93aW5n",highlighted:`Task: &quot;Draw me a picture of rivers and lakes&quot;

I will use the following`}}),Gt=new J({props:{code:"YWdlbnQucnVuKCUyMkRyYXclMjBtZSUyMGElMjBwaWN0dXJlJTIwb2YlMjByaXZlcnMlMjBhbmQlMjBsYWtlcyUyMik=",highlighted:'agent.run(<span class="hljs-string">&quot;Draw me a picture of rivers and lakes&quot;</span>)'}}),It=new J({props:{code:"JTVCLi4uJTVEJTBBJTBBJTNEJTNEJTNEJTNEJTNEJTBBJTBBSHVtYW4lM0ElMjBBbnN3ZXIlMjB0aGUlMjBxdWVzdGlvbiUyMGluJTIwdGhlJTIwdmFyaWFibGUlMjAlNjBxdWVzdGlvbiU2MCUyMGFib3V0JTIwdGhlJTIwaW1hZ2UlMjBzdG9yZWQlMjBpbiUyMHRoZSUyMHZhcmlhYmxlJTIwJTYwaW1hZ2UlNjAuJTBBJTBBQXNzaXN0YW50JTNBJTIwSSUyMHdpbGwlMjB1c2UlMjB0aGUlMjB0b29sJTIwJTYwaW1hZ2VfcWElNjAlMjB0byUyMGFuc3dlciUyMHRoZSUyMHF1ZXN0aW9uJTIwb24lMjB0aGUlMjBpbnB1dCUyMGltYWdlLiUwQSUwQSU2MCU2MCU2MHB5JTBBYW5zd2VyJTIwJTNEJTIwaW1hZ2VfcWEodGV4dCUzRHF1ZXN0aW9uJTJDJTIwaW1hZ2UlM0RpbWFnZSklMEFwcmludChmJTIyVGhlJTIwYW5zd2VyJTIwaXMlMjAlN0JhbnN3ZXIlN0QlMjIpJTBBJTYwJTYwJTYwJTBBJTBBSHVtYW4lM0ElMjBJJTIwdHJpZWQlMjB0aGlzJTIwY29kZSUyQyUyMGl0JTIwd29ya2VkJTIwYnV0JTIwZGlkbid0JTIwZ2l2ZSUyMG1lJTIwYSUyMGdvb2QlMjByZXN1bHQuJTIwVGhlJTIwcXVlc3Rpb24lMjBpcyUyMGluJTIwRnJlbmNoJTBBJTBBQXNzaXN0YW50JTNBJTIwSW4lMjB0aGlzJTIwY2FzZSUyQyUyMHRoZSUyMHF1ZXN0aW9uJTIwbmVlZHMlMjB0byUyMGJlJTIwdHJhbnNsYXRlZCUyMGZpcnN0LiUyMEklMjB3aWxsJTIwdXNlJTIwdGhlJTIwdG9vbCUyMCU2MHRyYW5zbGF0b3IlNjAlMjB0byUyMGRvJTIwdGhpcy4lMEElMEElNjAlNjAlNjBweSUwQXRyYW5zbGF0ZWRfcXVlc3Rpb24lMjAlM0QlMjB0cmFuc2xhdG9yKHF1ZXN0aW9uJTNEcXVlc3Rpb24lMkMlMjBzcmNfbGFuZyUzRCUyMkZyZW5jaCUyMiUyQyUyMHRndF9sYW5nJTNEJTIyRW5nbGlzaCUyMiklMEFwcmludChmJTIyVGhlJTIwdHJhbnNsYXRlZCUyMHF1ZXN0aW9uJTIwaXMlMjAlN0J0cmFuc2xhdGVkX3F1ZXN0aW9uJTdELiUyMiklMEFhbnN3ZXIlMjAlM0QlMjBpbWFnZV9xYSh0ZXh0JTNEdHJhbnNsYXRlZF9xdWVzdGlvbiUyQyUyMGltYWdlJTNEaW1hZ2UpJTBBcHJpbnQoZiUyMlRoZSUyMGFuc3dlciUyMGlzJTIwJTdCYW5zd2VyJTdEJTIyKSUwQSU2MCU2MCU2MCUwQSUwQSUzRCUzRCUzRCUzRCUzRCUwQSUwQSU1Qi4uLiU1RA==",highlighted:`[...]

=====

Human: Answer the question in the variable \`question\` about the image stored in the variable \`image\`.

Assistant: I will use the tool \`image_qa\` to answer the question on the input image.

\`\`\`py
answer = image_qa(text=question, image=image)
print(f&quot;The answer is {answer}&quot;)
\`\`\`

Human: I tried this code, it worked but didn&#x27;t give me a good result. The question is in French

Assistant: In this case, the question needs to be translated first. I will use the tool \`translator\` to do this.

\`\`\`py
translated_question = translator(question=question, src_lang=&quot;French&quot;, tgt_lang=&quot;English&quot;)
print(f&quot;The translated question is {translated_question}.&quot;)
answer = image_qa(text=translated_question, image=image)
print(f&quot;The answer is {answer}&quot;)
\`\`\`

=====

[...]`}}),_t=new J({props:{code:"SHVtYW4lM0ElMjAlM0N1c2VyLWlucHV0JTNFJTVDbiU1Q25Bc3Npc3RhbnQlM0E=",highlighted:"Human: &lt;user-input&gt;\\n\\nAssistant:"}}),Wt=new S({}),Bt=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEhmQWdlbnQlMEElMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQoJTIyaHR0cHMlM0ElMkYlMkZhcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvJTJGbW9kZWxzJTJGYmlnY29kZSUyRnN0YXJjb2RlciUyMiklMEElMEFhZ2VudC5ydW4oJTIyU2hvdyUyMG1lJTIwYSUyMHRyZWUlMjIlMkMlMjByZXR1cm5fY29kZSUzRFRydWUp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> HfAgent

agent = HfAgent(<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigcode/starcoder&quot;</span>)

agent.run(<span class="hljs-string">&quot;Show me a tree&quot;</span>, return_code=<span class="hljs-literal">True</span>)`}}),kt=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2wlM0ElMjAlNjBpbWFnZV9zZWdtZW50ZXIlNjAlMjB0byUyMGNyZWF0ZSUyMGElMjBzZWdtZW50YXRpb24lMjBtYXNrJTIwZm9yJTIwdGhlJTIwaW1hZ2UuJTBBJTBBJTBBJTNEJTNEQ29kZSUyMGdlbmVyYXRlZCUyMGJ5JTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFtYXNrJTIwJTNEJTIwaW1hZ2Vfc2VnbWVudGVyKGltYWdlJTJDJTIwcHJvbXB0JTNEJTIydHJlZSUyMik=",highlighted:`==Explanation from the agent==
I will use the following tool: \`image_segmenter\` to create a segmentation mask for the image.


==Code generated by the agent==
mask = image_segmenter(image, prompt=&quot;tree&quot;)`}}),Rt=new J({props:{code:"YWdlbnQudG9vbGJveCU1QiUyMmltYWdlX2dlbmVyYXRvciUyMiU1RC5kZXNjcmlwdGlvbg==",highlighted:'agent.toolbox[<span class="hljs-string">&quot;image_generator&quot;</span>].description'}}),Ct=new J({props:{code:"J1RoaXMlMjBpcyUyMGElMjB0b29sJTIwdGhhdCUyMGNyZWF0ZXMlMjBhbiUyMGltYWdlJTIwYWNjb3JkaW5nJTIwdG8lMjBhJTIwcHJvbXB0JTJDJTIwd2hpY2glMjBpcyUyMGElMjB0ZXh0JTIwZGVzY3JpcHRpb24uJTIwSXQlMjB0YWtlcyUyMGFuJTIwaW5wdXQlMjBuYW1lZCUyMCU2MHByb21wdCU2MCUyMHdoaWNoJTIwY29udGFpbnMlMjB0aGUlMjBpbWFnZSUyMGRlc2NyaXB0aW9uJTIwYW5kJTIwb3V0cHV0cyUyMGFuJTIwaW1hZ2Uu",highlighted:"&#x27;This is a tool that creates an image according to a prompt, which is a text description. It takes an input named `prompt` which contains the image description and outputs an image."}}),Yt=new J({props:{code:"YWdlbnQucnVuKCUyMkNyZWF0ZSUyMGFuJTIwaW1hZ2UlMjBvZiUyMGElMjB0cmVlJTIyJTJDJTIwcmV0dXJuX2NvZGUlM0RUcnVlKQ==",highlighted:'agent.run(<span class="hljs-string">&quot;Create an image of a tree&quot;</span>, return_code=<span class="hljs-literal">True</span>)'}}),Nt=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2wlMjAlNjBpbWFnZV9nZW5lcmF0b3IlNjAlMjB0byUyMGdlbmVyYXRlJTIwYW4lMjBpbWFnZSUyMG9mJTIwYSUyMHRyZWUuJTBBJTBBJTBBJTNEJTNEQ29kZSUyMGdlbmVyYXRlZCUyMGJ5JTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFpbWFnZSUyMCUzRCUyMGltYWdlX2dlbmVyYXRvcihwcm9tcHQlM0QlMjJ0cmVlJTIyKQ==",highlighted:`==Explanation from the agent==
I will use the following tool \`image_generator\` to generate an image of a tree.


==Code generated by the agent==
image = image_generator(prompt=&quot;tree&quot;)`}}),xt=new S({}),Xt=new J({props:{code:"YWdlbnQucnVuKCUyMk1ha2UlMjBhbiUyMGltYWdlJTIwb2YlMjBhJTIwaG91c2UlMjBhbmQlMjBhJTIwY2FyJTIyJTJDJTIwcmV0dXJuX2NvZGUlM0RUcnVlKQ==",highlighted:'agent.run(<span class="hljs-string">&quot;Make an image of a house and a car&quot;</span>, return_code=<span class="hljs-literal">True</span>)'}}),St=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMjAlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2xzJTIwJTYwaW1hZ2VfZ2VuZXJhdG9yJTYwJTIwdG8lMjBnZW5lcmF0ZSUyMGFuJTIwaW1hZ2UlMjBvZiUyMGElMjBob3VzZSUyMGFuZCUyMCU2MGltYWdlX3RyYW5zZm9ybWVyJTYwJTIwdG8lMjB0cmFuc2Zvcm0lMjB0aGUlMjBpbWFnZSUyMG9mJTIwYSUyMGNhciUyMGludG8lMjB0aGUlMjBpbWFnZSUyMG9mJTIwYSUyMGhvdXNlLiUwQSUwQSUzRCUzRENvZGUlMjBnZW5lcmF0ZWQlMjBieSUyMHRoZSUyMGFnZW50JTNEJTNEJTBBaG91c2VfaW1hZ2UlMjAlM0QlMjBpbWFnZV9nZW5lcmF0b3IocHJvbXB0JTNEJTIyQSUyMGhvdXNlJTIyKSUwQWNhcl9pbWFnZSUyMCUzRCUyMGltYWdlX2dlbmVyYXRvcihwcm9tcHQlM0QlMjJBJTIwY2FyJTIyKSUwQWhvdXNlX2Nhcl9pbWFnZSUyMCUzRCUyMGltYWdlX3RyYW5zZm9ybWVyKGltYWdlJTNEY2FyX2ltYWdlJTJDJTIwcHJvbXB0JTNEJTIyQSUyMGhvdXNlJTIyKQ==",highlighted:`==Explanation from the agent== 
I will use the following tools \`image_generator\` to generate an image of a house and \`image_transformer\` to transform the image of a car into the image of a house.

==Code generated by the agent==
house_image = image_generator(prompt=&quot;A house&quot;)
car_image = image_generator(prompt=&quot;A car&quot;)
house_car_image = image_transformer(image=car_image, prompt=&quot;A house&quot;)`}}),Qt=new J({props:{code:"YWdlbnQudG9vbGJveCU1QiUyMm1vZGlmaWVyJTIyJTVEJTIwJTNEJTIwYWdlbnQudG9vbGJveC5wb3AoJTIyaW1hZ2VfdHJhbnNmb3JtZXIlMjIpJTBBYWdlbnQudG9vbGJveCU1QiUyMm1vZGlmaWVyJTIyJTVELmRlc2NyaXB0aW9uJTIwJTNEJTIwYWdlbnQudG9vbGJveCU1QiUyMm1vZGlmaWVyJTIyJTVELmRlc2NyaXB0aW9uLnJlcGxhY2UoJTBBJTIwJTIwJTIwJTIwJTIydHJhbnNmb3JtcyUyMGFuJTIwaW1hZ2UlMjBhY2NvcmRpbmclMjB0byUyMGElMjBwcm9tcHQlMjIlMkMlMjAlMjJtb2RpZmllcyUyMGFuJTIwaW1hZ2UlMjIlMEEp",highlighted:`agent.toolbox[<span class="hljs-string">&quot;modifier&quot;</span>] = agent.toolbox.pop(<span class="hljs-string">&quot;image_transformer&quot;</span>)
agent.toolbox[<span class="hljs-string">&quot;modifier&quot;</span>].description = agent.toolbox[<span class="hljs-string">&quot;modifier&quot;</span>].description.replace(
    <span class="hljs-string">&quot;transforms an image according to a prompt&quot;</span>, <span class="hljs-string">&quot;modifies an image&quot;</span>
)`}}),Vt=new J({props:{code:"YWdlbnQucnVuKCUyMk1ha2UlMjBhbiUyMGltYWdlJTIwb2YlMjBhJTIwaG91c2UlMjBhbmQlMjBhJTIwY2FyJTIyJTJDJTIwcmV0dXJuX2NvZGUlM0RUcnVlKQ==",highlighted:'agent.run(<span class="hljs-string">&quot;Make an image of a house and a car&quot;</span>, return_code=<span class="hljs-literal">True</span>)'}}),Ft=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2xzJTNBJTIwJTYwaW1hZ2VfZ2VuZXJhdG9yJTYwJTIwdG8lMjBnZW5lcmF0ZSUyMGFuJTIwaW1hZ2UlMjBvZiUyMGElMjBob3VzZSUyQyUyMHRoZW4lMjAlNjBpbWFnZV9nZW5lcmF0b3IlNjAlMjB0byUyMGdlbmVyYXRlJTIwYW4lMjBpbWFnZSUyMG9mJTIwYSUyMGNhci4lMEElMEElMEElM0QlM0RDb2RlJTIwZ2VuZXJhdGVkJTIwYnklMjB0aGUlMjBhZ2VudCUzRCUzRCUwQWhvdXNlX2ltYWdlJTIwJTNEJTIwaW1hZ2VfZ2VuZXJhdG9yKHByb21wdCUzRCUyMkElMjBob3VzZSUyMiklMEFjYXJfaW1hZ2UlMjAlM0QlMjBpbWFnZV9nZW5lcmF0b3IocHJvbXB0JTNEJTIyQSUyMGNhciUyMik=",highlighted:`==Explanation from the agent==
I will use the following tools: \`image_generator\` to generate an image of a house, then \`image_generator\` to generate an image of a car.


==Code generated by the agent==
house_image = image_generator(prompt=&quot;A house&quot;)
car_image = image_generator(prompt=&quot;A car&quot;)`}}),zt=new J({props:{code:"YWdlbnQucnVuKCUyMkNyZWF0ZSUyMGltYWdlJTNBJTIwJ0ElMjBob3VzZSUyMGFuZCUyMGNhciclMjIlMkMlMjByZXR1cm5fY29kZSUzRFRydWUp",highlighted:'agent.run(<span class="hljs-string">&quot;Create image: &#x27;A house and car&#x27;&quot;</span>, return_code=<span class="hljs-literal">True</span>)'}}),qt=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2wlM0ElMjAlNjBpbWFnZV9nZW5lcmF0b3IlNjAlMjB0byUyMGdlbmVyYXRlJTIwYW4lMjBpbWFnZS4lMEElMEElMEElM0QlM0RDb2RlJTIwZ2VuZXJhdGVkJTIwYnklMjB0aGUlMjBhZ2VudCUzRCUzRCUwQWltYWdlJTIwJTNEJTIwaW1hZ2VfZ2VuZXJhdG9yKHByb21wdCUzRCUyMkElMjBob3VzZSUyMGFuZCUyMGNhciUyMik=",highlighted:`==Explanation from the agent==
I will use the following tool: \`image_generator\` to generate an image.


==Code generated by the agent==
image = image_generator(prompt=&quot;A house and car&quot;)`}}),Re=new re({props:{warning:!0,$$slots:{default:[Gb]},$$scope:{ctx:Z}}}),At=new S({}),Pt=new J({props:{code:"dGVtcGxhdGUlMjAlM0QlMjAlMjIlMjIlMjIlMjAlNUIuLi4lNUQlMjAlMjIlMjIlMjIlMEElMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQoeW91cl9lbmRwb2ludCUyQyUyMHJ1bl9wcm9tcHRfdGVtcGxhdGUlM0R0ZW1wbGF0ZSk=",highlighted:`template = <span class="hljs-string">&quot;&quot;&quot; [...] &quot;&quot;&quot;</span>

agent = HfAgent(your_endpoint, run_prompt_template=template)`}}),Ye=new re({props:{warning:!0,$$slots:{default:[Ib]},$$scope:{ctx:Z}}}),Lt=new J({props:{code:"SHVtYW4lM0ElMjAlM0MlM0N0YXNrJTNFJTNFJTBBJTBBQXNzaXN0YW50JTNB",highlighted:`Human: &lt;&lt;task&gt;&gt;

Assistant:`}}),Dt=new J({props:{code:"dGVtcGxhdGUlMjAlM0QlMjAlMjIlMjIlMjIlMjAlNUIuLi4lNUQlMjAlMjIlMjIlMjIlMEElMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQodXJsX2VuZHBvaW50JTNEeW91cl9lbmRwb2ludCUyQyUyMGNoYXRfcHJvbXB0X3RlbXBsYXRlJTNEdGVtcGxhdGUp",highlighted:`<span class="hljs-attr">template</span> = <span class="hljs-string">&quot;&quot;&quot; [...] &quot;&quot;&quot;</span>

<span class="hljs-attr">agent</span> = HfAgent(url_endpoint=your_endpoint, chat_prompt_template=template)`}}),Ne=new re({props:{warning:!0,$$slots:{default:[_b]},$$scope:{ctx:Z}}}),Kt=new S({}),ao=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGxvYWRfdG9vbCUwQSUwQWNvbnRyb2xuZXRfdHJhbnNmb3JtZXIlMjAlM0QlMjBsb2FkX3Rvb2woJTIyZGlmZnVzZXJzJTJGY29udHJvbG5ldC1jYW5ueS10b29sJTIyKSUwQXVwc2NhbGVyJTIwJTNEJTIwbG9hZF90b29sKCUyMmRpZmZ1c2VycyUyRmxhdGVudC11cHNjYWxlci10b29sJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> load_tool

controlnet_transformer = load_tool(<span class="hljs-string">&quot;diffusers/controlnet-canny-tool&quot;</span>)
upscaler = load_tool(<span class="hljs-string">&quot;diffusers/latent-upscaler-tool&quot;</span>)`}}),so=new J({props:{code:"cHJpbnQoZiUyMkRlc2NyaXB0aW9uJTNBJTIwJyU3QmNvbnRyb2xuZXRfdHJhbnNmb3JtZXIuZGVzY3JpcHRpb24lN0QnJTIyKSUwQXByaW50KGYlMjJOYW1lJTNBJTIwJyU3QmNvbnRyb2xuZXRfdHJhbnNmb3JtZXIubmFtZSU3RCclMjIp",highlighted:`<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Description: &#x27;<span class="hljs-subst">{controlnet_transformer.description}</span>&#x27;&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Name: &#x27;<span class="hljs-subst">{controlnet_transformer.name}</span>&#x27;&quot;</span>)`}}),no=new J({props:{code:"RGVzY3JpcHRpb24lM0ElMjAnVGhpcyUyMGlzJTIwYSUyMHRvb2wlMjB0aGF0JTIwdHJhbnNmb3JtcyUyMGFuJTIwaW1hZ2UlMjB3aXRoJTIwQ29udHJvbE5ldCUyMGFjY29yZGluZyUyMHRvJTIwYSUyMHByb21wdC4lMjAlMEFJdCUyMHRha2VzJTIwdHdvJTIwaW5wdXRzJTNBJTIwJTYwaW1hZ2UlNjAlMkMlMjB3aGljaCUyMHNob3VsZCUyMGJlJTIwdGhlJTIwaW1hZ2UlMjB0byUyMHRyYW5zZm9ybSUyQyUyMGFuZCUyMCU2MHByb21wdCU2MCUyQyUyMHdoaWNoJTIwc2hvdWxkJTIwYmUlMjB0aGUlMjBwcm9tcHQlMjB0byUyMHVzZSUyMHRvJTIwY2hhbmdlJTIwaXQuJTIwSXQlMjByZXR1cm5zJTIwdGhlJTIwbW9kaWZpZWQlMjBpbWFnZS4nJTBBTmFtZSUzQSUyMCdpbWFnZV90cmFuc2Zvcm1lcic=",highlighted:"Description: &#x27;This is a tool that transforms an image with ControlNet according to a prompt. \nIt takes two inputs: `image`, which should be the image to transform, and `prompt`, which should be the prompt to use to change it. It returns the modified image.&#x27;\nName: &#x27;image_transformer&#x27;"}}),io=new J({props:{code:"dG9vbHMlMjAlM0QlMjAlNUJjb250cm9sbmV0X3RyYW5zZm9ybWVyJTJDJTIwdXBzY2FsZXIlNUQlMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQoJTIyaHR0cHMlM0ElMkYlMkZhcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvJTJGbW9kZWxzJTJGYmlnY29kZSUyRnN0YXJjb2RlciUyMiUyQyUyMGFkZGl0aW9uYWxfdG9vbHMlM0R0b29scyk=",highlighted:`tools = [controlnet_transformer, upscaler]
agent = HfAgent(<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigcode/starcoder&quot;</span>, additional_tools=tools)`}}),ro=new J({props:{code:"aW1hZ2VfdHJhbnNmb3JtZXIlMjBoYXMlMjBiZWVuJTIwcmVwbGFjZWQlMjBieSUyMCUzQ3RyYW5zZm9ybWVyc19tb2R1bGVzLmRpZmZ1c2Vycy5jb250cm9sbmV0LWNhbm55LXRvb2wuYmQ3NjE4MmM3Nzc3ZWJhOTYxMmZjMDNjMCUwQTg3MThhNjBjMGFhNjMxMi5pbWFnZV90cmFuc2Zvcm1hdGlvbi5Db250cm9sTmV0VHJhbnNmb3JtYXRpb25Ub29sJTIwb2JqZWN0JTIwYXQlMjAweDdmMWQzYmZhM2EwMCUzRSUyMGFzJTIwcHJvdmlkZWQlMjBpbiUyMCU2MGFkZGl0aW9uYWxfdG9vbHMlNjA=",highlighted:"image_transformer has been replaced by &lt;transformers_modules.diffusers.controlnet-canny-tool.bd76182c7777eba9612fc03c0\n8718a60c0aa6312.image_transformation.ControlNetTransformationTool object at 0x7f1d3bfa3a00&gt; as provided in `additional_tools`"}}),qe=new re({props:{$$slots:{default:[Wb]},$$scope:{ctx:Z}}}),ho=new J({props:{code:"cHJpbnQoJTIyJTVDbiUyMi5qb2luKCU1QmYlMjItJTIwJTdCYSU3RCUyMiUyMGZvciUyMGElMjBpbiUyMGFnZW50LnRvb2xib3gua2V5cygpJTVEKSk=",highlighted:'<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;\\n&quot;</span>.join([<span class="hljs-string">f&quot;- <span class="hljs-subst">{a}</span>&quot;</span> <span class="hljs-keyword">for</span> a <span class="hljs-keyword">in</span> agent.toolbox.keys()]))'}}),po=new J({props:{code:"LSUyMGRvY3VtZW50X3FhJTBBLSUyMGltYWdlX2NhcHRpb25lciUwQS0lMjBpbWFnZV9xYSUwQS0lMjBpbWFnZV9zZWdtZW50ZXIlMEEtJTIwdHJhbnNjcmliZXIlMEEtJTIwc3VtbWFyaXplciUwQS0lMjB0ZXh0X2NsYXNzaWZpZXIlMEEtJTIwdGV4dF9xYSUwQS0lMjB0ZXh0X3JlYWRlciUwQS0lMjB0cmFuc2xhdG9yJTBBLSUyMGltYWdlX3RyYW5zZm9ybWVyJTBBLSUyMHRleHRfZG93bmxvYWRlciUwQS0lMjBpbWFnZV9nZW5lcmF0b3IlMEEtJTIwdmlkZW9fZ2VuZXJhdG9yJTBBLSUyMGltYWdlX3Vwc2NhbGVy",highlighted:`- document_qa
- image_captioner
- image_qa
- image_segmenter
- transcriber
- summarizer
- text_classifier
- text_qa
- text_reader
- translator
- image_transformer
- text_downloader
- image_generator
- video_generator
- image_upscaler`}}),mo=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGxvYWRfaW1hZ2UlMEElMEFpbWFnZSUyMCUzRCUyMGxvYWRfaW1hZ2UoJTBBJTIwJTIwJTIwJTIwJTIyaHR0cHMlM0ElMkYlMkZodWdnaW5nZmFjZS5jbyUyRmRhdGFzZXRzJTJGaHVnZ2luZ2ZhY2UlMkZkb2N1bWVudGF0aW9uLWltYWdlcyUyRnJlc29sdmUlMkZtYWluJTJGdHJhbnNmb3JtZXJzJTJGcml2ZXJzX2FuZF9sYWtlcy5wbmclMjIlMEEp",highlighted:`<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image

image = load_image(
    <span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes.png&quot;</span>
)`}}),uo=new J({props:{code:"aW1hZ2UlMjAlM0QlMjBhZ2VudC5ydW4oJTIyVHJhbnNmb3JtJTIwdGhlJTIwaW1hZ2UlM0ElMjAnQSUyMGZyb3plbiUyMGxha2UlMjBhbmQlMjBzbm93eSUyMGZvcmVzdCclMjIlMkMlMjBpbWFnZSUzRGltYWdlKQ==",highlighted:'image = agent.run(<span class="hljs-string">&quot;Transform the image: &#x27;A frozen lake and snowy forest&#x27;&quot;</span>, image=image)'}}),co=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2wlM0ElMjAlNjBpbWFnZV90cmFuc2Zvcm1lciU2MCUyMHRvJTIwdHJhbnNmb3JtJTIwdGhlJTIwaW1hZ2UuJTBBJTBBJTBBJTNEJTNEQ29kZSUyMGdlbmVyYXRlZCUyMGJ5JTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFpbWFnZSUyMCUzRCUyMGltYWdlX3RyYW5zZm9ybWVyKGltYWdlJTJDJTIwcHJvbXB0JTNEJTIyQSUyMGZyb3plbiUyMGxha2UlMjBhbmQlMjBzbm93eSUyMGZvcmVzdCUyMik=",highlighted:`==Explanation from the agent==
I will use the following tool: \`image_transformer\` to transform the image.


==Code generated by the agent==
image = image_transformer(image, prompt=&quot;A frozen lake and snowy forest&quot;)`}}),yo=new J({props:{code:"aW1hZ2UlMjAlM0QlMjBhZ2VudC5ydW4oJTIyVXBzY2FsZSUyMHRoZSUyMGltYWdlJTIyJTJDJTIwaW1hZ2Up",highlighted:'image = agent.run(<span class="hljs-string">&quot;Upscale the image&quot;</span>, image)'}}),Mo=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMHRvb2wlM0ElMjAlNjBpbWFnZV91cHNjYWxlciU2MCUyMHRvJTIwdXBzY2FsZSUyMHRoZSUyMGltYWdlLiUwQSUwQSUwQSUzRCUzRENvZGUlMjBnZW5lcmF0ZWQlMjBieSUyMHRoZSUyMGFnZW50JTNEJTNEJTBBdXBzY2FsZWRfaW1hZ2UlMjAlM0QlMjBpbWFnZV91cHNjYWxlcihpbWFnZSk=",highlighted:`==Explanation from the agent==
I will use the following tool: \`image_upscaler\` to upscale the image.


==Code generated by the agent==
upscaled_image = image_upscaler(image)`}}),go=new S({}),vo=new S({}),Jo=new J({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGxpc3RfbW9kZWxzJTBBJTBBdGFzayUyMCUzRCUyMCUyMnRleHQtY2xhc3NpZmljYXRpb24lMjIlMEElMEFtb2RlbCUyMCUzRCUyMG5leHQoaXRlcihsaXN0X21vZGVscyhmaWx0ZXIlM0R0YXNrJTJDJTIwc29ydCUzRCUyMmRvd25sb2FkcyUyMiUyQyUyMGRpcmVjdGlvbiUzRC0xKSkpJTBBcHJpbnQobW9kZWwuaWQp",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> list_models

task = <span class="hljs-string">&quot;text-classification&quot;</span>

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">&quot;downloads&quot;</span>, direction=-<span class="hljs-number">1</span>)))
<span class="hljs-built_in">print</span>(model.<span class="hljs-built_in">id</span>)`}}),Uo=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRvb2wlMEElMEElMEFjbGFzcyUyMEhGTW9kZWxEb3dubG9hZHNUb29sKFRvb2wpJTNBJTBBJTIwJTIwJTIwJTIwcGFzcw==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Tool


<span class="hljs-keyword">class</span> <span class="hljs-title class_">HFModelDownloadsTool</span>(<span class="hljs-title class_ inherited__">Tool</span>):
    <span class="hljs-keyword">pass</span>`}}),$o=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRvb2wlMEFmcm9tJTIwaHVnZ2luZ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oaXRlcihsaXN0X21vZGVscyhmaWx0ZXIlM0R0YXNrJTJDJTIwc29ydCUzRCUyMmRvd25sb2FkcyUyMiUyQyUyMGRpcmVjdGlvbiUzRC0xKSkpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmV0dXJuJTIwbW9kZWwuaWQ=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Tool
<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> list_models


<span class="hljs-keyword">class</span> <span class="hljs-title class_">HFModelDownloadsTool</span>(<span class="hljs-title class_ inherited__">Tool</span>):
    name = <span class="hljs-string">&quot;model_download_counter&quot;</span>
    description = (
        <span class="hljs-string">&quot;This is a tool that returns the most downloaded model of a given task on the Hugging Face Hub. &quot;</span>
        <span class="hljs-string">&quot;It takes the name of the category (such as text-classification, depth-estimation, etc), and &quot;</span>
        <span class="hljs-string">&quot;returns the name of the checkpoint.&quot;</span>
    )

    inputs = [<span class="hljs-string">&quot;text&quot;</span>]
    outputs = [<span class="hljs-string">&quot;text&quot;</span>]

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, task: <span class="hljs-built_in">str</span></span>):
        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">&quot;downloads&quot;</span>, direction=-<span class="hljs-number">1</span>)))
        <span class="hljs-keyword">return</span> model.<span class="hljs-built_in">id</span>`}}),Zo=new J({props:{code:"ZnJvbSUyMG1vZGVsX2Rvd25sb2FkcyUyMGltcG9ydCUyMEhGTW9kZWxEb3dubG9hZHNUb29sJTBBJTBBdG9vbCUyMCUzRCUyMEhGTW9kZWxEb3dubG9hZHNUb29sKCk=",highlighted:`<span class="hljs-keyword">from</span> model_downloads <span class="hljs-keyword">import</span> HFModelDownloadsTool

tool = HFModelDownloadsTool()`}}),jo=new J({props:{code:"dG9vbC5wdXNoX3RvX2h1YiglMjJoZi1tb2RlbC1kb3dubG9hZHMlMjIp",highlighted:'tool.push_to_hub(<span class="hljs-string">&quot;hf-model-downloads&quot;</span>)'}}),Go=new S({}),Io=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGxvYWRfdG9vbCUwQSUwQXRvb2wlMjAlM0QlMjBsb2FkX3Rvb2woJTIybHlzYW5kcmUlMkZoZi1tb2RlbC1kb3dubG9hZHMlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> load_tool

tool = load_tool(<span class="hljs-string">&quot;lysandre/hf-model-downloads&quot;</span>)`}}),_o=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEhmQWdlbnQlMEElMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQoJTIyaHR0cHMlM0ElMkYlMkZhcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvJTJGbW9kZWxzJTJGYmlnY29kZSUyRnN0YXJjb2RlciUyMiUyQyUyMGFkZGl0aW9uYWxfdG9vbHMlM0QlNUJ0b29sJTVEKSUwQSUwQWFnZW50LnJ1biglMEElMjAlMjAlMjAlMjAlMjJDYW4lMjB5b3UlMjByZWFkJTIwb3V0JTIwbG91ZCUyMHRoZSUyMG5hbWUlMjBvZiUyMHRoZSUyMG1vZGVsJTIwdGhhdCUyMGhhcyUyMHRoZSUyMG1vc3QlMjBkb3dubG9hZHMlMjBpbiUyMHRoZSUyMCd0ZXh0LXRvLXZpZGVvJyUyMHRhc2slMjBvbiUyMHRoZSUyMEh1Z2dpbmclMjBGYWNlJTIwSHViJTNGJTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> HfAgent

agent = HfAgent(<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigcode/starcoder&quot;</span>, additional_tools=[tool])

agent.run(
    <span class="hljs-string">&quot;Can you read out loud the name of the model that has the most downloads in the &#x27;text-to-video&#x27; task on the Hugging Face Hub?&quot;</span>
)`}}),Wo=new J({props:{code:"JTNEJTNEQ29kZSUyMGdlbmVyYXRlZCUyMGJ5JTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFtb2RlbCUyMCUzRCUyMG1vZGVsX2Rvd25sb2FkX2NvdW50ZXIodGFzayUzRCUyMnRleHQtdG8tdmlkZW8lMjIpJTBBcHJpbnQoZiUyMlRoZSUyMG1vZGVsJTIwd2l0aCUyMHRoZSUyMG1vc3QlMjBkb3dubG9hZHMlMjBpcyUyMCU3Qm1vZGVsJTdELiUyMiklMEFhdWRpb19tb2RlbCUyMCUzRCUyMHRleHRfcmVhZGVyKG1vZGVsKSUwQSUwQSUwQSUzRCUzRFJlc3VsdCUzRCUzRCUwQVRoZSUyMG1vZGVsJTIwd2l0aCUyMHRoZSUyMG1vc3QlMjBkb3dubG9hZHMlMjBpcyUyMGRhbW8tdmlsYWIlMkZ0ZXh0LXRvLXZpZGVvLW1zLTEuN2Iu",highlighted:`==Code generated by the agent==
model = model_download_counter(task=&quot;text-to-video&quot;)
print(f&quot;The model with the most downloads is {model}.&quot;)
audio_model = text_reader(model)


==Result==
The model with the most downloads is damo-vilab/text-to-video-ms-1.7b.`}}),lt=new re({props:{$$slots:{default:[Bb]},$$scope:{ctx:Z}}}),Bo=new S({}),ko=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEhmQWdlbnQlMkMlMjBsb2FkX3Rvb2wlMEElMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQoJTIyaHR0cHMlM0ElMkYlMkZhcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvJTJGbW9kZWxzJTJGYmlnY29kZSUyRnN0YXJjb2RlciUyMiklMEFhZ2VudC50b29sYm94JTVCJTIyaW1hZ2UtdHJhbnNmb3JtYXRpb24lMjIlNUQlMjAlM0QlMjBsb2FkX3Rvb2woJTIyZGlmZnVzZXJzJTJGY29udHJvbG5ldC1jYW5ueS10b29sJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> HfAgent, load_tool

agent = HfAgent(<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigcode/starcoder&quot;</span>)
agent.toolbox[<span class="hljs-string">&quot;image-transformation&quot;</span>] = load_tool(<span class="hljs-string">&quot;diffusers/controlnet-canny-tool&quot;</span>)`}}),st=new re({props:{$$slots:{default:[kb]},$$scope:{ctx:Z}}}),Ro=new S({}),No=new J({props:{code:"ZnJvbSUyMGdyYWRpb190b29scyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblByb21wdEdlbmVyYXRvclRvb2wlMEElMEFncmFkaW9fdG9vbCUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblByb21wdEdlbmVyYXRvclRvb2woKQ==",highlighted:`<span class="hljs-keyword">from</span> gradio_tools <span class="hljs-keyword">import</span> StableDiffusionPromptGeneratorTool

gradio_tool = StableDiffusionPromptGeneratorTool()`}}),xo=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRvb2wlMEElMEF0b29sJTIwJTNEJTIwVG9vbC5mcm9tX2dyYWRpbyhncmFkaW9fdG9vbCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Tool

tool = Tool.from_gradio(gradio_tool)`}}),Ho=new J({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEhmQWdlbnQlMEElMEFhZ2VudCUyMCUzRCUyMEhmQWdlbnQoJTIyaHR0cHMlM0ElMkYlMkZhcGktaW5mZXJlbmNlLmh1Z2dpbmdmYWNlLmNvJTJGbW9kZWxzJTJGYmlnY29kZSUyRnN0YXJjb2RlciUyMiUyQyUyMGFkZGl0aW9uYWxfdG9vbHMlM0QlNUJ0b29sJTVEKSUwQSUwQWFnZW50LnJ1biglMjJHZW5lcmF0ZSUyMGFuJTIwaW1hZ2UlMjBvZiUyMHRoZSUyMCU2MHByb21wdCU2MCUyMGFmdGVyJTIwaW1wcm92aW5nJTIwaXQuJTIyJTJDJTIwcHJvbXB0JTNEJTIyQSUyMHJhYmJpdCUyMHdlYXJpbmclMjBhJTIwc3BhY2UlMjBzdWl0JTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> HfAgent

agent = HfAgent(<span class="hljs-string">&quot;https://api-inference.huggingface.co/models/bigcode/starcoder&quot;</span>, additional_tools=[tool])

agent.run(<span class="hljs-string">&quot;Generate an image of the \`prompt\` after improving it.&quot;</span>, prompt=<span class="hljs-string">&quot;A rabbit wearing a space suit&quot;</span>)`}}),Xo=new J({props:{code:"JTNEJTNERXhwbGFuYXRpb24lMjBmcm9tJTIwdGhlJTIwYWdlbnQlM0QlM0QlMEFJJTIwd2lsbCUyMHVzZSUyMHRoZSUyMGZvbGxvd2luZyUyMCUyMHRvb2xzJTNBJTIwJTYwU3RhYmxlRGlmZnVzaW9uUHJvbXB0R2VuZXJhdG9yJTYwJTIwdG8lMjBpbXByb3ZlJTIwdGhlJTIwcHJvbXB0JTJDJTIwdGhlbiUyMCU2MGltYWdlX2dlbmVyYXRvciU2MCUyMHRvJTIwZ2VuZXJhdGUlMjBhbiUyMGltYWdlJTIwYWNjb3JkaW5nJTIwdG8lMjB0aGUlMjBpbXByb3ZlZCUyMHByb21wdC4lMEElMEElMEElM0QlM0RDb2RlJTIwZ2VuZXJhdGVkJTIwYnklMjB0aGUlMjBhZ2VudCUzRCUzRCUwQWltcHJvdmVkX3Byb21wdCUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblByb21wdEdlbmVyYXRvcihwcm9tcHQpJTBBcHJpbnQoZiUyMlRoZSUyMGltcHJvdmVkJTIwcHJvbXB0JTIwaXMlMjAlN0JpbXByb3ZlZF9wcm9tcHQlN0QuJTIyKSUwQWltYWdlJTIwJTNEJTIwaW1hZ2VfZ2VuZXJhdG9yKGltcHJvdmVkX3Byb21wdCk=",highlighted:`==Explanation from the agent==
I will use the following  tools: \`StableDiffusionPromptGenerator\` to improve the prompt, then \`image_generator\` to generate an image according to the improved prompt.


==Code generated by the agent==
improved_prompt = StableDiffusionPromptGenerator(prompt)
print(f&quot;The improved prompt is {improved_prompt}.&quot;)
image = image_generator(improved_prompt)`}}),pt=new re({props:{warning:!0,$$slots:{default:[Rb]},$$scope:{ctx:Z}}}),So=new S({}),{c(){d=n("meta"),U=p(),g=n("h1"),v=n("a"),$=n("span"),u(T.$$.fragment),E=p(),j=n("span"),k=a("Custom Tools and Prompts"),B=p(),u(R.$$.fragment),X=p(),u(I.$$.fragment),Mt=p(),he=n("p"),zo=a(`Creating and using custom tools and prompts is paramount to empowering the agent and having it perform new tasks.
In this guide we\u2019ll take a look at:`),Zn=p(),A=n("ul"),ia=n("li"),rp=a("How to customize the prompt"),hp=p(),ra=n("li"),pp=a("How to use custom tools"),mp=p(),ha=n("li"),dp=a("How to create custom tools"),jn=p(),pe=n("h2"),Ee=n("a"),pa=n("span"),u(bt.$$.fragment),fp=p(),ma=n("span"),up=a("Customizing the prompt"),Gn=p(),_=n("p"),cp=a("As explained in "),qo=n("a"),wp=a("Transformers Agents"),yp=a(" agents can run in "),Ao=n("a"),Mp=a("run()"),bp=a(" and "),Po=n("a"),gp=a("chat()"),vp=a(` mode.
Both the `),da=n("code"),Jp=a("run"),Up=a(" and "),fa=n("code"),Tp=a("chat"),Ep=a(` modes underlie the same logic. The language model powering the agent is conditioned on a long
prompt and completes the prompt by generating the next tokens until the stop token is reached.
The only difference between the two modes is that during the `),ua=n("code"),$p=a("chat"),Zp=a(` mode the prompt is extended with
previous user inputs and model generations. This allows the agent to have access to past interactions,
seemingly giving the agent some kind of memory.`),In=p(),me=n("h3"),$e=n("a"),ca=n("span"),u(gt.$$.fragment),jp=p(),wa=n("span"),Gp=a("Structure of the prompt"),_n=p(),Lo=n("p"),Ip=a(`Let\u2019s take a closer look at how the prompt is structured to understand how it can be best customized.
The prompt is structured broadly into four parts.`),Wn=p(),Q=n("ul"),ya=n("li"),Ma=n("ol"),ba=n("li"),_p=a("Introduction: how the agent should behave, explanation of the concept of tools."),Wp=p(),ga=n("li"),Do=n("ol"),vt=n("li"),Bp=a("Description of all the tools. This is defined by a "),va=n("code"),kp=a("<<all_tools>>"),Rp=a(" token that is dynamically replaced at runtime with the tools defined/chosen by the user."),Cp=p(),Ja=n("li"),Oo=n("ol"),Ua=n("li"),Yp=a("A set of examples of tasks and their solution"),Np=p(),Ta=n("li"),Ko=n("ol"),Ea=n("li"),xp=a("Current example, and request for solution."),Bn=p(),Ze=n("p"),Hp=a("To better understand each part, let\u2019s look at a shortened version of how the "),$a=n("code"),Xp=a("run"),Sp=a(" prompt can look like:"),kn=p(),u(Jt.$$.fragment),Rn=p(),je=n("p"),Qp=a("The introduction (the text before "),Za=n("em"),Vp=a("\u201CTools:\u201D"),Fp=a(`) explains precisely how the model shall behave and what it should do.
This part most likely does not need to be customized as the agent shall always behave the same way.`),Cn=p(),C=n("p"),zp=a("The second part (the bullet points below "),ja=n("em"),qp=a("\u201CTools\u201D"),Ap=a(") is dynamically added upon calling "),Ga=n("code"),Pp=a("run"),Lp=a(" or "),Ia=n("code"),Dp=a("chat"),Op=a(`. There are
exactly as many bullet points as there are tools in `),_a=n("code"),Kp=a("agent.toolbox"),em=a(` and each bullet point consists of the name
and description of the tool:`),Yn=p(),u(Ut.$$.fragment),Nn=p(),el=n("p"),tm=a("Let\u2019s verify this quickly by loading the document_qa tool and printing out the name and description."),xn=p(),u(Tt.$$.fragment),Hn=p(),tl=n("p"),om=a("which gives:"),Xn=p(),u(Et.$$.fragment),Sn=p(),ol=n("p"),lm=a(`We can see that the tool name is short and precise. The description includes two parts, the first explaining
what the tool does and the second states what input arguments and return values are expected.`),Qn=p(),ll=n("p"),am=a(`A good tool name and tool description are very important for the agent to correctly use it. Note that the only
information the agent has about the tool is its name and description, so one should make sure that both
are precisely written and match the style of the existing tools in the toolbox. In particular make sure the description
mentions all the arguments expected by name in code-style, along with the expected type and a description of what they
are.`),Vn=p(),u(Ge.$$.fragment),Fn=p(),al=n("p"),sm=a(`The third part includes a set of curated examples that show the agent exactly what code it should produce
for what kind of user request. The large language models empowering the agent are extremely good at
recognizing patterns in a prompt and repeating the pattern with new data. Therefore, it is very important
that the examples are written in a way that maximizes the likelihood of the agent to generating correct,
executable code in practice.`),zn=p(),sl=n("p"),nm=a("Let\u2019s have a look at one example:"),qn=p(),u($t.$$.fragment),An=p(),nl=n("p"),im=a(`The pattern the model is prompted to repeat has three parts: The task statement, the agent\u2019s explanation of
what it intends to do, and finally the generated code. Every example that is part of the prompt has this exact
pattern, thus making sure that the agent will reproduce exactly the same pattern when generating new tokens.`),Pn=p(),Ie=n("p"),rm=a(`The prompt examples are curated by the Transformers team and rigorously evaluated on a set of
`),Zt=n("a"),hm=a("problem statements"),pm=a(`
to ensure that the agent\u2019s prompt is as good as possible to solve real use cases of the agent.`),Ln=p(),il=n("p"),mm=a("The final part of the prompt corresponds to:"),Dn=p(),u(jt.$$.fragment),On=p(),rl=n("p"),dm=a(`is a final and unfinished example that the agent is tasked to complete. The unfinished example
is dynamically created based on the actual user input. For the above example, the user ran:`),Kn=p(),u(Gt.$$.fragment),ei=p(),P=n("p"),fm=a("The user input - "),Wa=n("em"),um=a("a.k.a"),cm=a(" the task: "),Ba=n("em"),wm=a("\u201CDraw me a picture of rivers and lakes\u201D"),ym=a(` is cast into the
prompt template: \u201CTask: <task> \\n\\n I will use the following\u201D. This sentence makes up the final lines of the
prompt the agent is conditioned on, therefore strongly influencing the agent to finish the example
exactly in the same way it was previously done in the examples.`),ti=p(),_e=n("p"),Mm=a(`Without going into too much detail, the chat template has the same prompt structure with the
examples having a slightly different style, `),ka=n("em"),bm=a("e.g."),gm=a(":"),oi=p(),u(It.$$.fragment),li=p(),G=n("p"),vm=a("Contrary, to the examples of the "),Ra=n("code"),Jm=a("run"),Um=a(" prompt, each "),Ca=n("code"),Tm=a("chat"),Em=a(` prompt example has one or more exchanges between the
`),Ya=n("em"),$m=a("Human"),Zm=a(" and the "),Na=n("em"),jm=a("Assistant"),Gm=a(". Every exchange is structured similarly to the example of the "),xa=n("code"),Im=a("run"),_m=a(` prompt.
The user\u2019s input is appended to behind `),Ha=n("em"),Wm=a("Human:"),Bm=a(` and the agent is prompted to first generate what needs to be done
before generating code. An exchange can be based on previous exchanges, therefore allowing the user to refer
to past exchanges as is done `),Xa=n("em"),km=a("e.g."),Rm=a(" above by the user\u2019s input of \u201CI tried "),Sa=n("strong"),Cm=a("this"),Ym=a(` code\u201D refers to the
previously generated code of the agent.`),ai=p(),L=n("p"),Nm=a("Upon running "),Qa=n("code"),xm=a(".chat"),Hm=a(", the user\u2019s input or "),Va=n("em"),Xm=a("task"),Sm=a(" is cast into an unfinished example of the form:"),si=p(),u(_t.$$.fragment),ni=p(),V=n("p"),Qm=a("which the agent completes. Contrary to the "),Fa=n("code"),Vm=a("run"),Fm=a(" command, the "),za=n("code"),zm=a("chat"),qm=a(` command then appends the completed example
to the prompt, thus giving the agent more context for the next `),qa=n("code"),Am=a("chat"),Pm=a(" turn."),ii=p(),hl=n("p"),Lm=a("Great now that we know how the prompt is structured, let\u2019s see how we can customize it!"),ri=p(),de=n("h3"),We=n("a"),Aa=n("span"),u(Wt.$$.fragment),Dm=p(),Pa=n("span"),Om=a("Writing good user inputs"),hi=p(),pl=n("p"),Km=a(`While large language models are getting better and better at understanding users\u2019 intentions, it helps
enormously to be as precise as possible to help the agent pick the correct task. What does it mean to be
as precise as possible?`),pi=p(),ml=n("p"),ed=a(`The agent sees a list of tool names and their description in its prompt. The more tools are added the
more difficult it becomes for the agent to choose the correct tool and it\u2019s even more difficult to choose
the correct sequences of tools to run. Let\u2019s look at a common failure case, here we will only return
the code to analyze it.`),mi=p(),u(Bt.$$.fragment),di=p(),dl=n("p"),td=a("gives:"),fi=p(),u(kt.$$.fragment),ui=p(),fl=n("p"),od=a(`which is probably not what we wanted. Instead, it is more likely that we want an image of a tree to be generated.
To steer the agent more towards using a specific tool it can therefore be very helpful to use important keywords that
are present in the tool\u2019s name and description. Let\u2019s have a look.`),ci=p(),u(Rt.$$.fragment),wi=p(),u(Ct.$$.fragment),yi=p(),ul=n("p"),ld=a("The name and description make use of the keywords \u201Cimage\u201D, \u201Cprompt\u201D, \u201Ccreate\u201D and \u201Cgenerate\u201D. Using these words will most likely work better here. Let\u2019s refine our prompt a bit."),Mi=p(),u(Yt.$$.fragment),bi=p(),cl=n("p"),ad=a("gives:"),gi=p(),u(Nt.$$.fragment),vi=p(),wl=n("p"),sd=a(`Much better! That looks more like what we want. In short, when you notice that the agent struggles to
correctly map your task to the correct tools, try looking up the most pertinent keywords of the tool\u2019s name
and description and try refining your task request with it.`),Ji=p(),fe=n("h3"),Be=n("a"),La=n("span"),u(xt.$$.fragment),nd=p(),Da=n("span"),id=a("Customizing the tool descriptions"),Ui=p(),ke=n("p"),rd=a(`As we\u2019ve seen before the agent has access to each of the tools\u2019 names and descriptions. The base tools
should have very precise names and descriptions, however, you might find that it could help to change the
the description or name of a tool for your specific use case. This might become especially important
when you\u2019ve added multiple tools that are very similar or if you want to use your agent only for a certain
domain, `),Oa=n("em"),hd=a("e.g."),pd=a(" image generation and transformations."),Ti=p(),Ht=n("p"),md=a(`A common problem is that the agent confuses image generation with image transformation/modification when
used a lot for image generation tasks, `),Ka=n("em"),dd=a("e.g."),Ei=p(),u(Xt.$$.fragment),$i=p(),yl=n("p"),fd=a("returns"),Zi=p(),u(St.$$.fragment),ji=p(),D=n("p"),ud=a(`which is probably not exactly what we want here. It seems like the agent has a difficult time
to understand the difference between `),es=n("code"),cd=a("image_generator"),wd=a(" and "),ts=n("code"),yd=a("image_transformer"),Md=a(" and often uses the two together."),Gi=p(),O=n("p"),bd=a("We can help the agent here by changing the tool name and description of "),os=n("code"),gd=a("image_transformer"),vd=a(". Let\u2019s instead call it "),ls=n("code"),Jd=a("modifier"),Ud=a(`
to disassociate it a bit from \u201Cimage\u201D and \u201Cprompt\u201D:`),Ii=p(),u(Qt.$$.fragment),_i=p(),Ml=n("p"),Td=a("Now \u201Cmodify\u201D is a strong cue to use the new image processor which should help with the above prompt. Let\u2019s run it again."),Wi=p(),u(Vt.$$.fragment),Bi=p(),bl=n("p"),Ed=a("Now we\u2019re getting:"),ki=p(),u(Ft.$$.fragment),Ri=p(),gl=n("p"),$d=a("which is definitely closer to what we had in mind! However, we want to have both the house and car in the same image. Steering the task more toward single image generation should help:"),Ci=p(),u(zt.$$.fragment),Yi=p(),u(qt.$$.fragment),Ni=p(),u(Re.$$.fragment),xi=p(),ue=n("h3"),Ce=n("a"),as=n("span"),u(At.$$.fragment),Zd=p(),ss=n("span"),jd=a("Customizing the whole prompt"),Hi=p(),K=n("p"),Gd=a("To give the user maximum flexibility, the whole prompt template as explained in "),vl=n("a"),Id=a("above"),_d=a(`
can be overwritten by the user. In this case make sure that your custom prompt includes an introduction section,
a tool section, an example section, and an unfinished example section. If you want to overwrite the `),ns=n("code"),Wd=a("run"),Bd=a(` prompt template,
you can do as follows:`),Xi=p(),u(Pt.$$.fragment),Si=p(),u(Ye.$$.fragment),Qi=p(),ee=n("p"),kd=a("Similarly, one can overwrite the "),is=n("code"),Rd=a("chat"),Cd=a(" prompt template. Note that the "),rs=n("code"),Yd=a("chat"),Nd=a(" mode always uses the following format for the exchanges:"),Vi=p(),u(Lt.$$.fragment),Fi=p(),te=n("p"),xd=a("Therefore it is important that the examples of the custom "),hs=n("code"),Hd=a("chat"),Xd=a(` prompt template also make use of this format.
You can overwrite the `),ps=n("code"),Sd=a("chat"),Qd=a(" template at instantiation as follows."),zi=p(),u(Dt.$$.fragment),qi=p(),u(Ne.$$.fragment),Ai=p(),xe=n("p"),Vd=a("In both cases, you can pass a repo ID instead of the prompt template if you would like to use a template hosted by someone in the community. The default prompts live in "),Ot=n("a"),Fd=a("this repo"),zd=a(" as an example."),Pi=p(),Jl=n("p"),qd=a("To upload your custom prompt on a repo on the Hub and share it with the community just make sure:"),Li=p(),oe=n("ul"),ms=n("li"),Ad=a("to use a dataset repository"),Pd=p(),He=n("li"),Ld=a("to put the prompt template for the "),ds=n("code"),Dd=a("run"),Od=a(" command in a file named "),fs=n("code"),Kd=a("run_prompt_template.txt"),ef=p(),Xe=n("li"),tf=a("to put the prompt template for the "),us=n("code"),of=a("chat"),lf=a(" command in a file named "),cs=n("code"),af=a("chat_prompt_template.txt"),Di=p(),ce=n("h2"),Se=n("a"),ws=n("span"),u(Kt.$$.fragment),sf=p(),ys=n("span"),nf=a("Using custom tools"),Oi=p(),Ul=n("p"),rf=a("In this section, we\u2019ll be leveraging two existing custom tools that are specific to image generation:"),Ki=p(),Qe=n("ul"),we=n("li"),hf=a("We replace "),eo=n("a"),pf=a("huggingface-tools/image-transformation"),mf=a(`,
with `),to=n("a"),df=a("diffusers/controlnet-canny-tool"),ff=a(`
to allow for more image modifications.`),uf=p(),oo=n("li"),cf=a(`We add a new tool for image upscaling to the default toolbox:
`),lo=n("a"),wf=a("diffusers/latent-upscaler-tool"),yf=a(" replace the existing image-transformation tool."),er=p(),Ve=n("p"),Mf=a("We\u2019ll start by loading the custom tools with the convenient "),Tl=n("a"),bf=a("load_tool()"),gf=a(" function:"),tr=p(),u(ao.$$.fragment),or=p(),Fe=n("p"),vf=a(`Upon adding custom tools to an agent, the tools\u2019 descriptions and names are automatically
included in the agents\u2019 prompts. Thus, it is imperative that custom tools have
a well-written description and name in order for the agent to understand how to use them.
Let\u2019s take a look at the description and name of `),Ms=n("code"),Jf=a("controlnet_transformer"),Uf=a(":"),lr=p(),u(so.$$.fragment),ar=p(),El=n("p"),Tf=a("gives"),sr=p(),u(no.$$.fragment),nr=p(),F=n("p"),Ef=a("The name and description are accurate and fit the style of the "),$l=n("a"),$f=a("curated set of tools"),Zf=a(`.
Next, let\u2019s instantiate an agent with `),bs=n("code"),jf=a("controlnet_transformer"),Gf=a(" and "),gs=n("code"),If=a("upscaler"),_f=a(":"),ir=p(),u(io.$$.fragment),rr=p(),Zl=n("p"),Wf=a("This command should give you the following info:"),hr=p(),u(ro.$$.fragment),pr=p(),ze=n("p"),Bf=a("The set of curated tools already has an "),vs=n("code"),kf=a("image_transformer"),Rf=a(" tool which is hereby replaced with our custom tool."),mr=p(),u(qe.$$.fragment),dr=p(),le=n("p"),Cf=a("The upscaler tool was given the name "),Js=n("code"),Yf=a("image_upscaler"),Nf=a(` which is not yet present in the default toolbox and is therefore simply added to the list of tools.
You can always have a look at the toolbox that is currently available to the agent via the `),Us=n("code"),xf=a("agent.toolbox"),Hf=a(" attribute:"),fr=p(),u(ho.$$.fragment),ur=p(),u(po.$$.fragment),cr=p(),Ae=n("p"),Xf=a("Note how "),Ts=n("code"),Sf=a("image_upscaler"),Qf=a(" is now part of the agents\u2019 toolbox."),wr=p(),Pe=n("p"),Vf=a("Let\u2019s now try out the new tools! We will re-use the image we generated in "),jl=n("a"),Ff=a("Transformers Agents Quickstart"),zf=a("."),yr=p(),u(mo.$$.fragment),Mr=p(),fo=n("img"),br=p(),Gl=n("p"),qf=a("Let\u2019s transform the image into a beautiful winter landscape:"),gr=p(),u(uo.$$.fragment),vr=p(),u(co.$$.fragment),Jr=p(),wo=n("img"),Ur=p(),Il=n("p"),Af=a(`The new image processing tool is based on ControlNet which can make very strong modifications to the image.
By default the image processing tool returns an image of size 512x512 pixels. Let\u2019s see if we can upscale it.`),Tr=p(),u(yo.$$.fragment),Er=p(),u(Mo.$$.fragment),$r=p(),bo=n("img"),Zr=p(),_l=n("p"),Pf=a(`The agent automatically mapped our prompt \u201CUpscale the image\u201D to the just added upscaler tool purely based on the description and name of the upscaler tool
and was able to correctly run it.`),jr=p(),Wl=n("p"),Lf=a("Next, let\u2019s have a look at how you can create a new custom tool."),Gr=p(),ye=n("h3"),Le=n("a"),Es=n("span"),u(go.$$.fragment),Df=p(),$s=n("span"),Of=a("Adding new tools"),Ir=p(),Bl=n("p"),Kf=a("In this section, we show how to create a new tool that can be added to the agent."),_r=p(),Me=n("h4"),De=n("a"),Zs=n("span"),u(vo.$$.fragment),eu=p(),js=n("span"),tu=a("Creating a new tool"),Wr=p(),kl=n("p"),ou=a(`We\u2019ll first start by creating a tool. We\u2019ll add the not-so-useful yet fun task of fetching the model on the Hugging Face
Hub with the most downloads for a given task.`),Br=p(),Rl=n("p"),lu=a("We can do that with the following code:"),kr=p(),u(Jo.$$.fragment),Rr=p(),Y=n("p"),au=a("For the task "),Gs=n("code"),su=a("text-classification"),nu=a(", this returns "),Is=n("code"),iu=a("'facebook/bart-large-mnli'"),ru=a(", for "),_s=n("code"),hu=a("translation"),pu=a(" it returns "),Ws=n("code"),mu=a("'t5-base"),du=a("."),Cr=p(),Oe=n("p"),fu=a("How do we convert this to a tool that the agent can leverage? All tools depend on the superclass "),Bs=n("code"),uu=a("Tool"),cu=a(` that holds the
main attributes necessary. We\u2019ll create a class that inherits from it:`),Yr=p(),u(Uo.$$.fragment),Nr=p(),Cl=n("p"),wu=a("This class has a few needs:"),xr=p(),z=n("ul"),be=n("li"),yu=a("An attribute "),ks=n("code"),Mu=a("name"),bu=a(`, which corresponds to the name of the tool itself. To be in tune with other tools which have a
performative name, we\u2019ll name it `),Rs=n("code"),gu=a("model_download_counter"),vu=a("."),Ju=p(),To=n("li"),Uu=a("An attribute "),Cs=n("code"),Tu=a("description"),Eu=a(", which will be used to populate the prompt of the agent."),$u=p(),N=n("li"),Ys=n("code"),Zu=a("inputs"),ju=a(" and "),Ns=n("code"),Gu=a("outputs"),Iu=a(` attributes. Defining this will help the python interpreter make educated choices about types,
and will allow for a gradio-demo to be spawned when we push our tool to the Hub. They\u2019re both a list of expected
values, which can be `),xs=n("code"),_u=a("text"),Wu=a(", "),Hs=n("code"),Bu=a("image"),ku=a(", or "),Xs=n("code"),Ru=a("audio"),Cu=a("."),Yu=p(),Eo=n("li"),Nu=a("A "),Ss=n("code"),xu=a("__call__"),Hu=a(" method which contains the inference code. This is the code we\u2019ve played with above!"),Hr=p(),Yl=n("p"),Xu=a("Here\u2019s what our class looks like now:"),Xr=p(),u($o.$$.fragment),Sr=p(),Ke=n("p"),Su=a(`We now have our tool handy. Save it in a file and import it from your main script. Let\u2019s name this file
`),Qs=n("code"),Qu=a("model_downloads.py"),Vu=a(", so the resulting import code looks like this:"),Qr=p(),u(Zo.$$.fragment),Vr=p(),ae=n("p"),Fu=a(`In order to let others benefit from it and for simpler initialization, we recommend pushing it to the Hub under your
namespace. To do so, just call `),Vs=n("code"),zu=a("push_to_hub"),qu=a(" on the "),Fs=n("code"),Au=a("tool"),Pu=a(" variable:"),Fr=p(),u(jo.$$.fragment),zr=p(),Nl=n("p"),Lu=a("You now have your code on the Hub! Let\u2019s take a look at the final step, which is to have the agent use it."),qr=p(),ge=n("h4"),et=n("a"),zs=n("span"),u(Go.$$.fragment),Du=p(),qs=n("span"),Ou=a("Having the agent use the tool"),Ar=p(),xl=n("p"),Ku=a("We now have our tool that lives on the Hub which can be instantiated as such (change the user name for your tool):"),Pr=p(),u(Io.$$.fragment),Lr=p(),tt=n("p"),ec=a("In order to use it in the agent, simply pass it in the "),As=n("code"),tc=a("additional_tools"),oc=a(" parameter of the agent initialization method:"),Dr=p(),u(_o.$$.fragment),Or=p(),Hl=n("p"),lc=a("which outputs the following:"),Kr=p(),u(Wo.$$.fragment),eh=p(),Xl=n("p"),ac=a("and generates the following audio."),th=p(),ot=n("table"),Ps=n("thead"),Ls=n("tr"),Ds=n("th"),Os=n("strong"),sc=a("Audio"),nc=p(),Ks=n("tbody"),en=n("tr"),tn=n("td"),Sl=n("audio"),Ql=n("source"),oh=p(),u(lt.$$.fragment),lh=p(),ve=n("h3"),at=n("a"),on=n("span"),u(Bo.$$.fragment),ic=p(),ln=n("span"),rc=a("Replacing existing tools"),ah=p(),Vl=n("p"),hc=a("Replacing existing tools can be done simply by assigning a new item to the agent\u2019s toolbox. Here\u2019s how one would do so:"),sh=p(),u(ko.$$.fragment),nh=p(),u(st.$$.fragment),ih=p(),Je=n("h2"),nt=n("a"),an=n("span"),u(Ro.$$.fragment),pc=p(),sn=n("span"),mc=a("Leveraging gradio-tools"),rh=p(),Co=n("p"),Yo=n("a"),dc=a("gradio-tools"),fc=a(` is a powerful library that allows using Hugging
Face Spaces as tools. It supports many existing Spaces as well as custom Spaces to be designed with it.`),hh=p(),x=n("p"),uc=a("We offer support for "),nn=n("code"),cc=a("gradio_tools"),wc=a(" by using the "),rn=n("code"),yc=a("Tool.from_gradio"),Mc=a(` method. For example, we want to take
advantage of the `),hn=n("code"),bc=a("StableDiffusionPromptGeneratorTool"),gc=a(" tool offered in the "),pn=n("code"),vc=a("gradio-tools"),Jc=a(` toolkit so as to
improve our prompts and generate better images.`),ph=p(),it=n("p"),Uc=a("We first import the tool from "),mn=n("code"),Tc=a("gradio_tools"),Ec=a(" and instantiate it:"),mh=p(),u(No.$$.fragment),dh=p(),rt=n("p"),$c=a("We pass that instance to the "),dn=n("code"),Zc=a("Tool.from_gradio"),jc=a(" method:"),fh=p(),u(xo.$$.fragment),uh=p(),ht=n("p"),Gc=a(`Now we can manage it exactly as we would a usual custom tool. We leverage it to improve our prompt
`),fn=n("code"),Ic=a("a rabbit wearing a space suit"),_c=a(":"),ch=p(),u(Ho.$$.fragment),wh=p(),Fl=n("p"),Wc=a("The model adequately leverages the tool:"),yh=p(),u(Xo.$$.fragment),Mh=p(),zl=n("p"),Bc=a("Before finally generating the image:"),bh=p(),ql=n("img"),gh=p(),u(pt.$$.fragment),vh=p(),Ue=n("h2"),mt=n("a"),un=n("span"),u(So.$$.fragment),kc=p(),cn=n("span"),Rc=a("Future compatibility with Langchain"),Jh=p(),dt=n("p"),Cc=a(`We love Langchain and think it has a very compelling suite of tools. In order to handle these tools,
Langchain requires `),wn=n("em"),Yc=a("textual"),Nc=a(` inputs and outputs, even when working with different modalities.
This is often the serialized version (i.e., saved to disk) of the objects.`),Uh=p(),Al=n("p"),xc=a(`This difference means that multi-modality isn\u2019t handled between transformers-agents and langchain.
We aim for this limitation to be resolved in future versions, and welcome any help from avid langchain
users to help us achieve this compatibility.`),Th=p(),ft=n("p"),Hc=a(`We would love to have better support. If you would like to help, please
`),Qo=n("a"),Xc=a("open an issue"),Sc=a(" and share what you have in mind."),this.h()},l(e){const l=Tb('[data-svelte="svelte-1phssyn"]',document.head);d=i(l,"META",{name:!0,content:!0}),l.forEach(t),U=m(e),g=i(e,"H1",{class:!0});var Vo=h(g);v=i(Vo,"A",{id:!0,class:!0,href:!0});var yn=h(v);$=i(yn,"SPAN",{});var Mn=h($);c(T.$$.fragment,Mn),Mn.forEach(t),yn.forEach(t),E=m(Vo),j=i(Vo,"SPAN",{});var bn=h(j);k=s(bn,"Custom Tools and Prompts"),bn.forEach(t),Vo.forEach(t),B=m(e),c(R.$$.fragment,e),X=m(e),c(I.$$.fragment,e),Mt=m(e),he=i(e,"P",{});var gn=h(he);zo=s(gn,`Creating and using custom tools and prompts is paramount to empowering the agent and having it perform new tasks.
In this guide we\u2019ll take a look at:`),gn.forEach(t),Zn=m(e),A=i(e,"UL",{});var Te=h(A);ia=i(Te,"LI",{});var vn=h(ia);rp=s(vn,"How to customize the prompt"),vn.forEach(t),hp=m(Te),ra=i(Te,"LI",{});var Jn=h(ra);pp=s(Jn,"How to use custom tools"),Jn.forEach(t),mp=m(Te),ha=i(Te,"LI",{});var Un=h(ha);dp=s(Un,"How to create custom tools"),Un.forEach(t),Te.forEach(t),jn=m(e),pe=i(e,"H2",{class:!0});var Fo=h(pe);Ee=i(Fo,"A",{id:!0,class:!0,href:!0});var Lc=h(Ee);pa=i(Lc,"SPAN",{});var Dc=h(pa);c(bt.$$.fragment,Dc),Dc.forEach(t),Lc.forEach(t),fp=m(Fo),ma=i(Fo,"SPAN",{});var Oc=h(ma);up=s(Oc,"Customizing the prompt"),Oc.forEach(t),Fo.forEach(t),Gn=m(e),_=i(e,"P",{});var H=h(_);cp=s(H,"As explained in "),qo=i(H,"A",{href:!0});var Kc=h(qo);wp=s(Kc,"Transformers Agents"),Kc.forEach(t),yp=s(H," agents can run in "),Ao=i(H,"A",{href:!0});var ew=h(Ao);Mp=s(ew,"run()"),ew.forEach(t),bp=s(H," and "),Po=i(H,"A",{href:!0});var tw=h(Po);gp=s(tw,"chat()"),tw.forEach(t),vp=s(H,` mode.
Both the `),da=i(H,"CODE",{});var ow=h(da);Jp=s(ow,"run"),ow.forEach(t),Up=s(H," and "),fa=i(H,"CODE",{});var lw=h(fa);Tp=s(lw,"chat"),lw.forEach(t),Ep=s(H,` modes underlie the same logic. The language model powering the agent is conditioned on a long
prompt and completes the prompt by generating the next tokens until the stop token is reached.
The only difference between the two modes is that during the `),ua=i(H,"CODE",{});var aw=h(ua);$p=s(aw,"chat"),aw.forEach(t),Zp=s(H,` mode the prompt is extended with
previous user inputs and model generations. This allows the agent to have access to past interactions,
seemingly giving the agent some kind of memory.`),H.forEach(t),In=m(e),me=i(e,"H3",{class:!0});var $h=h(me);$e=i($h,"A",{id:!0,class:!0,href:!0});var sw=h($e);ca=i(sw,"SPAN",{});var nw=h(ca);c(gt.$$.fragment,nw),nw.forEach(t),sw.forEach(t),jp=m($h),wa=i($h,"SPAN",{});var iw=h(wa);Gp=s(iw,"Structure of the prompt"),iw.forEach(t),$h.forEach(t),_n=m(e),Lo=i(e,"P",{});var rw=h(Lo);Ip=s(rw,`Let\u2019s take a closer look at how the prompt is structured to understand how it can be best customized.
The prompt is structured broadly into four parts.`),rw.forEach(t),Wn=m(e),Q=i(e,"UL",{});var ut=h(Q);ya=i(ut,"LI",{});var hw=h(ya);Ma=i(hw,"OL",{});var pw=h(Ma);ba=i(pw,"LI",{});var mw=h(ba);_p=s(mw,"Introduction: how the agent should behave, explanation of the concept of tools."),mw.forEach(t),pw.forEach(t),hw.forEach(t),Wp=m(ut),ga=i(ut,"LI",{});var dw=h(ga);Do=i(dw,"OL",{start:!0});var fw=h(Do);vt=i(fw,"LI",{});var Zh=h(vt);Bp=s(Zh,"Description of all the tools. This is defined by a "),va=i(Zh,"CODE",{});var uw=h(va);kp=s(uw,"<<all_tools>>"),uw.forEach(t),Rp=s(Zh," token that is dynamically replaced at runtime with the tools defined/chosen by the user."),Zh.forEach(t),fw.forEach(t),dw.forEach(t),Cp=m(ut),Ja=i(ut,"LI",{});var cw=h(Ja);Oo=i(cw,"OL",{start:!0});var ww=h(Oo);Ua=i(ww,"LI",{});var yw=h(Ua);Yp=s(yw,"A set of examples of tasks and their solution"),yw.forEach(t),ww.forEach(t),cw.forEach(t),Np=m(ut),Ta=i(ut,"LI",{});var Mw=h(Ta);Ko=i(Mw,"OL",{start:!0});var bw=h(Ko);Ea=i(bw,"LI",{});var gw=h(Ea);xp=s(gw,"Current example, and request for solution."),gw.forEach(t),bw.forEach(t),Mw.forEach(t),ut.forEach(t),Bn=m(e),Ze=i(e,"P",{});var jh=h(Ze);Hp=s(jh,"To better understand each part, let\u2019s look at a shortened version of how the "),$a=i(jh,"CODE",{});var vw=h($a);Xp=s(vw,"run"),vw.forEach(t),Sp=s(jh," prompt can look like:"),jh.forEach(t),kn=m(e),c(Jt.$$.fragment,e),Rn=m(e),je=i(e,"P",{});var Gh=h(je);Qp=s(Gh,"The introduction (the text before "),Za=i(Gh,"EM",{});var Jw=h(Za);Vp=s(Jw,"\u201CTools:\u201D"),Jw.forEach(t),Fp=s(Gh,`) explains precisely how the model shall behave and what it should do.
This part most likely does not need to be customized as the agent shall always behave the same way.`),Gh.forEach(t),Cn=m(e),C=i(e,"P",{});var se=h(C);zp=s(se,"The second part (the bullet points below "),ja=i(se,"EM",{});var Uw=h(ja);qp=s(Uw,"\u201CTools\u201D"),Uw.forEach(t),Ap=s(se,") is dynamically added upon calling "),Ga=i(se,"CODE",{});var Tw=h(Ga);Pp=s(Tw,"run"),Tw.forEach(t),Lp=s(se," or "),Ia=i(se,"CODE",{});var Ew=h(Ia);Dp=s(Ew,"chat"),Ew.forEach(t),Op=s(se,`. There are
exactly as many bullet points as there are tools in `),_a=i(se,"CODE",{});var $w=h(_a);Kp=s($w,"agent.toolbox"),$w.forEach(t),em=s(se,` and each bullet point consists of the name
and description of the tool:`),se.forEach(t),Yn=m(e),c(Ut.$$.fragment,e),Nn=m(e),el=i(e,"P",{});var Zw=h(el);tm=s(Zw,"Let\u2019s verify this quickly by loading the document_qa tool and printing out the name and description."),Zw.forEach(t),xn=m(e),c(Tt.$$.fragment,e),Hn=m(e),tl=i(e,"P",{});var jw=h(tl);om=s(jw,"which gives:"),jw.forEach(t),Xn=m(e),c(Et.$$.fragment,e),Sn=m(e),ol=i(e,"P",{});var Gw=h(ol);lm=s(Gw,`We can see that the tool name is short and precise. The description includes two parts, the first explaining
what the tool does and the second states what input arguments and return values are expected.`),Gw.forEach(t),Qn=m(e),ll=i(e,"P",{});var Iw=h(ll);am=s(Iw,`A good tool name and tool description are very important for the agent to correctly use it. Note that the only
information the agent has about the tool is its name and description, so one should make sure that both
are precisely written and match the style of the existing tools in the toolbox. In particular make sure the description
mentions all the arguments expected by name in code-style, along with the expected type and a description of what they
are.`),Iw.forEach(t),Vn=m(e),c(Ge.$$.fragment,e),Fn=m(e),al=i(e,"P",{});var _w=h(al);sm=s(_w,`The third part includes a set of curated examples that show the agent exactly what code it should produce
for what kind of user request. The large language models empowering the agent are extremely good at
recognizing patterns in a prompt and repeating the pattern with new data. Therefore, it is very important
that the examples are written in a way that maximizes the likelihood of the agent to generating correct,
executable code in practice.`),_w.forEach(t),zn=m(e),sl=i(e,"P",{});var Ww=h(sl);nm=s(Ww,"Let\u2019s have a look at one example:"),Ww.forEach(t),qn=m(e),c($t.$$.fragment,e),An=m(e),nl=i(e,"P",{});var Bw=h(nl);im=s(Bw,`The pattern the model is prompted to repeat has three parts: The task statement, the agent\u2019s explanation of
what it intends to do, and finally the generated code. Every example that is part of the prompt has this exact
pattern, thus making sure that the agent will reproduce exactly the same pattern when generating new tokens.`),Bw.forEach(t),Pn=m(e),Ie=i(e,"P",{});var Ih=h(Ie);rm=s(Ih,`The prompt examples are curated by the Transformers team and rigorously evaluated on a set of
`),Zt=i(Ih,"A",{href:!0,rel:!0});var kw=h(Zt);hm=s(kw,"problem statements"),kw.forEach(t),pm=s(Ih,`
to ensure that the agent\u2019s prompt is as good as possible to solve real use cases of the agent.`),Ih.forEach(t),Ln=m(e),il=i(e,"P",{});var Rw=h(il);mm=s(Rw,"The final part of the prompt corresponds to:"),Rw.forEach(t),Dn=m(e),c(jt.$$.fragment,e),On=m(e),rl=i(e,"P",{});var Cw=h(rl);dm=s(Cw,`is a final and unfinished example that the agent is tasked to complete. The unfinished example
is dynamically created based on the actual user input. For the above example, the user ran:`),Cw.forEach(t),Kn=m(e),c(Gt.$$.fragment,e),ei=m(e),P=i(e,"P",{});var Pl=h(P);fm=s(Pl,"The user input - "),Wa=i(Pl,"EM",{});var Yw=h(Wa);um=s(Yw,"a.k.a"),Yw.forEach(t),cm=s(Pl," the task: "),Ba=i(Pl,"EM",{});var Nw=h(Ba);wm=s(Nw,"\u201CDraw me a picture of rivers and lakes\u201D"),Nw.forEach(t),ym=s(Pl,` is cast into the
prompt template: \u201CTask: <task> \\n\\n I will use the following\u201D. This sentence makes up the final lines of the
prompt the agent is conditioned on, therefore strongly influencing the agent to finish the example
exactly in the same way it was previously done in the examples.`),Pl.forEach(t),ti=m(e),_e=i(e,"P",{});var _h=h(_e);Mm=s(_h,`Without going into too much detail, the chat template has the same prompt structure with the
examples having a slightly different style, `),ka=i(_h,"EM",{});var xw=h(ka);bm=s(xw,"e.g."),xw.forEach(t),gm=s(_h,":"),_h.forEach(t),oi=m(e),c(It.$$.fragment,e),li=m(e),G=i(e,"P",{});var W=h(G);vm=s(W,"Contrary, to the examples of the "),Ra=i(W,"CODE",{});var Hw=h(Ra);Jm=s(Hw,"run"),Hw.forEach(t),Um=s(W," prompt, each "),Ca=i(W,"CODE",{});var Xw=h(Ca);Tm=s(Xw,"chat"),Xw.forEach(t),Em=s(W,` prompt example has one or more exchanges between the
`),Ya=i(W,"EM",{});var Sw=h(Ya);$m=s(Sw,"Human"),Sw.forEach(t),Zm=s(W," and the "),Na=i(W,"EM",{});var Qw=h(Na);jm=s(Qw,"Assistant"),Qw.forEach(t),Gm=s(W,". Every exchange is structured similarly to the example of the "),xa=i(W,"CODE",{});var Vw=h(xa);Im=s(Vw,"run"),Vw.forEach(t),_m=s(W,` prompt.
The user\u2019s input is appended to behind `),Ha=i(W,"EM",{});var Fw=h(Ha);Wm=s(Fw,"Human:"),Fw.forEach(t),Bm=s(W,` and the agent is prompted to first generate what needs to be done
before generating code. An exchange can be based on previous exchanges, therefore allowing the user to refer
to past exchanges as is done `),Xa=i(W,"EM",{});var zw=h(Xa);km=s(zw,"e.g."),zw.forEach(t),Rm=s(W," above by the user\u2019s input of \u201CI tried "),Sa=i(W,"STRONG",{});var qw=h(Sa);Cm=s(qw,"this"),qw.forEach(t),Ym=s(W,` code\u201D refers to the
previously generated code of the agent.`),W.forEach(t),ai=m(e),L=i(e,"P",{});var Ll=h(L);Nm=s(Ll,"Upon running "),Qa=i(Ll,"CODE",{});var Aw=h(Qa);xm=s(Aw,".chat"),Aw.forEach(t),Hm=s(Ll,", the user\u2019s input or "),Va=i(Ll,"EM",{});var Pw=h(Va);Xm=s(Pw,"task"),Pw.forEach(t),Sm=s(Ll," is cast into an unfinished example of the form:"),Ll.forEach(t),si=m(e),c(_t.$$.fragment,e),ni=m(e),V=i(e,"P",{});var ct=h(V);Qm=s(ct,"which the agent completes. Contrary to the "),Fa=i(ct,"CODE",{});var Lw=h(Fa);Vm=s(Lw,"run"),Lw.forEach(t),Fm=s(ct," command, the "),za=i(ct,"CODE",{});var Dw=h(za);zm=s(Dw,"chat"),Dw.forEach(t),qm=s(ct,` command then appends the completed example
to the prompt, thus giving the agent more context for the next `),qa=i(ct,"CODE",{});var Ow=h(qa);Am=s(Ow,"chat"),Ow.forEach(t),Pm=s(ct," turn."),ct.forEach(t),ii=m(e),hl=i(e,"P",{});var Kw=h(hl);Lm=s(Kw,"Great now that we know how the prompt is structured, let\u2019s see how we can customize it!"),Kw.forEach(t),ri=m(e),de=i(e,"H3",{class:!0});var Wh=h(de);We=i(Wh,"A",{id:!0,class:!0,href:!0});var ey=h(We);Aa=i(ey,"SPAN",{});var ty=h(Aa);c(Wt.$$.fragment,ty),ty.forEach(t),ey.forEach(t),Dm=m(Wh),Pa=i(Wh,"SPAN",{});var oy=h(Pa);Om=s(oy,"Writing good user inputs"),oy.forEach(t),Wh.forEach(t),hi=m(e),pl=i(e,"P",{});var ly=h(pl);Km=s(ly,`While large language models are getting better and better at understanding users\u2019 intentions, it helps
enormously to be as precise as possible to help the agent pick the correct task. What does it mean to be
as precise as possible?`),ly.forEach(t),pi=m(e),ml=i(e,"P",{});var ay=h(ml);ed=s(ay,`The agent sees a list of tool names and their description in its prompt. The more tools are added the
more difficult it becomes for the agent to choose the correct tool and it\u2019s even more difficult to choose
the correct sequences of tools to run. Let\u2019s look at a common failure case, here we will only return
the code to analyze it.`),ay.forEach(t),mi=m(e),c(Bt.$$.fragment,e),di=m(e),dl=i(e,"P",{});var sy=h(dl);td=s(sy,"gives:"),sy.forEach(t),fi=m(e),c(kt.$$.fragment,e),ui=m(e),fl=i(e,"P",{});var ny=h(fl);od=s(ny,`which is probably not what we wanted. Instead, it is more likely that we want an image of a tree to be generated.
To steer the agent more towards using a specific tool it can therefore be very helpful to use important keywords that
are present in the tool\u2019s name and description. Let\u2019s have a look.`),ny.forEach(t),ci=m(e),c(Rt.$$.fragment,e),wi=m(e),c(Ct.$$.fragment,e),yi=m(e),ul=i(e,"P",{});var iy=h(ul);ld=s(iy,"The name and description make use of the keywords \u201Cimage\u201D, \u201Cprompt\u201D, \u201Ccreate\u201D and \u201Cgenerate\u201D. Using these words will most likely work better here. Let\u2019s refine our prompt a bit."),iy.forEach(t),Mi=m(e),c(Yt.$$.fragment,e),bi=m(e),cl=i(e,"P",{});var ry=h(cl);ad=s(ry,"gives:"),ry.forEach(t),gi=m(e),c(Nt.$$.fragment,e),vi=m(e),wl=i(e,"P",{});var hy=h(wl);sd=s(hy,`Much better! That looks more like what we want. In short, when you notice that the agent struggles to
correctly map your task to the correct tools, try looking up the most pertinent keywords of the tool\u2019s name
and description and try refining your task request with it.`),hy.forEach(t),Ji=m(e),fe=i(e,"H3",{class:!0});var Bh=h(fe);Be=i(Bh,"A",{id:!0,class:!0,href:!0});var py=h(Be);La=i(py,"SPAN",{});var my=h(La);c(xt.$$.fragment,my),my.forEach(t),py.forEach(t),nd=m(Bh),Da=i(Bh,"SPAN",{});var dy=h(Da);id=s(dy,"Customizing the tool descriptions"),dy.forEach(t),Bh.forEach(t),Ui=m(e),ke=i(e,"P",{});var kh=h(ke);rd=s(kh,`As we\u2019ve seen before the agent has access to each of the tools\u2019 names and descriptions. The base tools
should have very precise names and descriptions, however, you might find that it could help to change the
the description or name of a tool for your specific use case. This might become especially important
when you\u2019ve added multiple tools that are very similar or if you want to use your agent only for a certain
domain, `),Oa=i(kh,"EM",{});var fy=h(Oa);hd=s(fy,"e.g."),fy.forEach(t),pd=s(kh," image generation and transformations."),kh.forEach(t),Ti=m(e),Ht=i(e,"P",{});var Qc=h(Ht);md=s(Qc,`A common problem is that the agent confuses image generation with image transformation/modification when
used a lot for image generation tasks, `),Ka=i(Qc,"EM",{});var uy=h(Ka);dd=s(uy,"e.g."),uy.forEach(t),Qc.forEach(t),Ei=m(e),c(Xt.$$.fragment,e),$i=m(e),yl=i(e,"P",{});var cy=h(yl);fd=s(cy,"returns"),cy.forEach(t),Zi=m(e),c(St.$$.fragment,e),ji=m(e),D=i(e,"P",{});var Dl=h(D);ud=s(Dl,`which is probably not exactly what we want here. It seems like the agent has a difficult time
to understand the difference between `),es=i(Dl,"CODE",{});var wy=h(es);cd=s(wy,"image_generator"),wy.forEach(t),wd=s(Dl," and "),ts=i(Dl,"CODE",{});var yy=h(ts);yd=s(yy,"image_transformer"),yy.forEach(t),Md=s(Dl," and often uses the two together."),Dl.forEach(t),Gi=m(e),O=i(e,"P",{});var Ol=h(O);bd=s(Ol,"We can help the agent here by changing the tool name and description of "),os=i(Ol,"CODE",{});var My=h(os);gd=s(My,"image_transformer"),My.forEach(t),vd=s(Ol,". Let\u2019s instead call it "),ls=i(Ol,"CODE",{});var by=h(ls);Jd=s(by,"modifier"),by.forEach(t),Ud=s(Ol,`
to disassociate it a bit from \u201Cimage\u201D and \u201Cprompt\u201D:`),Ol.forEach(t),Ii=m(e),c(Qt.$$.fragment,e),_i=m(e),Ml=i(e,"P",{});var gy=h(Ml);Td=s(gy,"Now \u201Cmodify\u201D is a strong cue to use the new image processor which should help with the above prompt. Let\u2019s run it again."),gy.forEach(t),Wi=m(e),c(Vt.$$.fragment,e),Bi=m(e),bl=i(e,"P",{});var vy=h(bl);Ed=s(vy,"Now we\u2019re getting:"),vy.forEach(t),ki=m(e),c(Ft.$$.fragment,e),Ri=m(e),gl=i(e,"P",{});var Jy=h(gl);$d=s(Jy,"which is definitely closer to what we had in mind! However, we want to have both the house and car in the same image. Steering the task more toward single image generation should help:"),Jy.forEach(t),Ci=m(e),c(zt.$$.fragment,e),Yi=m(e),c(qt.$$.fragment,e),Ni=m(e),c(Re.$$.fragment,e),xi=m(e),ue=i(e,"H3",{class:!0});var Rh=h(ue);Ce=i(Rh,"A",{id:!0,class:!0,href:!0});var Uy=h(Ce);as=i(Uy,"SPAN",{});var Ty=h(as);c(At.$$.fragment,Ty),Ty.forEach(t),Uy.forEach(t),Zd=m(Rh),ss=i(Rh,"SPAN",{});var Ey=h(ss);jd=s(Ey,"Customizing the whole prompt"),Ey.forEach(t),Rh.forEach(t),Hi=m(e),K=i(e,"P",{});var Kl=h(K);Gd=s(Kl,"To give the user maximum flexibility, the whole prompt template as explained in "),vl=i(Kl,"A",{href:!0});var $y=h(vl);Id=s($y,"above"),$y.forEach(t),_d=s(Kl,`
can be overwritten by the user. In this case make sure that your custom prompt includes an introduction section,
a tool section, an example section, and an unfinished example section. If you want to overwrite the `),ns=i(Kl,"CODE",{});var Zy=h(ns);Wd=s(Zy,"run"),Zy.forEach(t),Bd=s(Kl,` prompt template,
you can do as follows:`),Kl.forEach(t),Xi=m(e),c(Pt.$$.fragment,e),Si=m(e),c(Ye.$$.fragment,e),Qi=m(e),ee=i(e,"P",{});var ea=h(ee);kd=s(ea,"Similarly, one can overwrite the "),is=i(ea,"CODE",{});var jy=h(is);Rd=s(jy,"chat"),jy.forEach(t),Cd=s(ea," prompt template. Note that the "),rs=i(ea,"CODE",{});var Gy=h(rs);Yd=s(Gy,"chat"),Gy.forEach(t),Nd=s(ea," mode always uses the following format for the exchanges:"),ea.forEach(t),Vi=m(e),c(Lt.$$.fragment,e),Fi=m(e),te=i(e,"P",{});var ta=h(te);xd=s(ta,"Therefore it is important that the examples of the custom "),hs=i(ta,"CODE",{});var Iy=h(hs);Hd=s(Iy,"chat"),Iy.forEach(t),Xd=s(ta,` prompt template also make use of this format.
You can overwrite the `),ps=i(ta,"CODE",{});var _y=h(ps);Sd=s(_y,"chat"),_y.forEach(t),Qd=s(ta," template at instantiation as follows."),ta.forEach(t),zi=m(e),c(Dt.$$.fragment,e),qi=m(e),c(Ne.$$.fragment,e),Ai=m(e),xe=i(e,"P",{});var Ch=h(xe);Vd=s(Ch,"In both cases, you can pass a repo ID instead of the prompt template if you would like to use a template hosted by someone in the community. The default prompts live in "),Ot=i(Ch,"A",{href:!0,rel:!0});var Wy=h(Ot);Fd=s(Wy,"this repo"),Wy.forEach(t),zd=s(Ch," as an example."),Ch.forEach(t),Pi=m(e),Jl=i(e,"P",{});var By=h(Jl);qd=s(By,"To upload your custom prompt on a repo on the Hub and share it with the community just make sure:"),By.forEach(t),Li=m(e),oe=i(e,"UL",{});var oa=h(oe);ms=i(oa,"LI",{});var ky=h(ms);Ad=s(ky,"to use a dataset repository"),ky.forEach(t),Pd=m(oa),He=i(oa,"LI",{});var Tn=h(He);Ld=s(Tn,"to put the prompt template for the "),ds=i(Tn,"CODE",{});var Ry=h(ds);Dd=s(Ry,"run"),Ry.forEach(t),Od=s(Tn," command in a file named "),fs=i(Tn,"CODE",{});var Cy=h(fs);Kd=s(Cy,"run_prompt_template.txt"),Cy.forEach(t),Tn.forEach(t),ef=m(oa),Xe=i(oa,"LI",{});var En=h(Xe);tf=s(En,"to put the prompt template for the "),us=i(En,"CODE",{});var Yy=h(us);of=s(Yy,"chat"),Yy.forEach(t),lf=s(En," command in a file named "),cs=i(En,"CODE",{});var Ny=h(cs);af=s(Ny,"chat_prompt_template.txt"),Ny.forEach(t),En.forEach(t),oa.forEach(t),Di=m(e),ce=i(e,"H2",{class:!0});var Yh=h(ce);Se=i(Yh,"A",{id:!0,class:!0,href:!0});var xy=h(Se);ws=i(xy,"SPAN",{});var Hy=h(ws);c(Kt.$$.fragment,Hy),Hy.forEach(t),xy.forEach(t),sf=m(Yh),ys=i(Yh,"SPAN",{});var Xy=h(ys);nf=s(Xy,"Using custom tools"),Xy.forEach(t),Yh.forEach(t),Oi=m(e),Ul=i(e,"P",{});var Sy=h(Ul);rf=s(Sy,"In this section, we\u2019ll be leveraging two existing custom tools that are specific to image generation:"),Sy.forEach(t),Ki=m(e),Qe=i(e,"UL",{});var Nh=h(Qe);we=i(Nh,"LI",{});var la=h(we);hf=s(la,"We replace "),eo=i(la,"A",{href:!0,rel:!0});var Qy=h(eo);pf=s(Qy,"huggingface-tools/image-transformation"),Qy.forEach(t),mf=s(la,`,
with `),to=i(la,"A",{href:!0,rel:!0});var Vy=h(to);df=s(Vy,"diffusers/controlnet-canny-tool"),Vy.forEach(t),ff=s(la,`
to allow for more image modifications.`),la.forEach(t),uf=m(Nh),oo=i(Nh,"LI",{});var xh=h(oo);cf=s(xh,`We add a new tool for image upscaling to the default toolbox:
`),lo=i(xh,"A",{href:!0,rel:!0});var Fy=h(lo);wf=s(Fy,"diffusers/latent-upscaler-tool"),Fy.forEach(t),yf=s(xh," replace the existing image-transformation tool."),xh.forEach(t),Nh.forEach(t),er=m(e),Ve=i(e,"P",{});var Hh=h(Ve);Mf=s(Hh,"We\u2019ll start by loading the custom tools with the convenient "),Tl=i(Hh,"A",{href:!0});var zy=h(Tl);bf=s(zy,"load_tool()"),zy.forEach(t),gf=s(Hh," function:"),Hh.forEach(t),tr=m(e),c(ao.$$.fragment,e),or=m(e),Fe=i(e,"P",{});var Xh=h(Fe);vf=s(Xh,`Upon adding custom tools to an agent, the tools\u2019 descriptions and names are automatically
included in the agents\u2019 prompts. Thus, it is imperative that custom tools have
a well-written description and name in order for the agent to understand how to use them.
Let\u2019s take a look at the description and name of `),Ms=i(Xh,"CODE",{});var qy=h(Ms);Jf=s(qy,"controlnet_transformer"),qy.forEach(t),Uf=s(Xh,":"),Xh.forEach(t),lr=m(e),c(so.$$.fragment,e),ar=m(e),El=i(e,"P",{});var Ay=h(El);Tf=s(Ay,"gives"),Ay.forEach(t),sr=m(e),c(no.$$.fragment,e),nr=m(e),F=i(e,"P",{});var wt=h(F);Ef=s(wt,"The name and description are accurate and fit the style of the "),$l=i(wt,"A",{href:!0});var Py=h($l);$f=s(Py,"curated set of tools"),Py.forEach(t),Zf=s(wt,`.
Next, let\u2019s instantiate an agent with `),bs=i(wt,"CODE",{});var Ly=h(bs);jf=s(Ly,"controlnet_transformer"),Ly.forEach(t),Gf=s(wt," and "),gs=i(wt,"CODE",{});var Dy=h(gs);If=s(Dy,"upscaler"),Dy.forEach(t),_f=s(wt,":"),wt.forEach(t),ir=m(e),c(io.$$.fragment,e),rr=m(e),Zl=i(e,"P",{});var Oy=h(Zl);Wf=s(Oy,"This command should give you the following info:"),Oy.forEach(t),hr=m(e),c(ro.$$.fragment,e),pr=m(e),ze=i(e,"P",{});var Sh=h(ze);Bf=s(Sh,"The set of curated tools already has an "),vs=i(Sh,"CODE",{});var Ky=h(vs);kf=s(Ky,"image_transformer"),Ky.forEach(t),Rf=s(Sh," tool which is hereby replaced with our custom tool."),Sh.forEach(t),mr=m(e),c(qe.$$.fragment,e),dr=m(e),le=i(e,"P",{});var aa=h(le);Cf=s(aa,"The upscaler tool was given the name "),Js=i(aa,"CODE",{});var eM=h(Js);Yf=s(eM,"image_upscaler"),eM.forEach(t),Nf=s(aa,` which is not yet present in the default toolbox and is therefore simply added to the list of tools.
You can always have a look at the toolbox that is currently available to the agent via the `),Us=i(aa,"CODE",{});var tM=h(Us);xf=s(tM,"agent.toolbox"),tM.forEach(t),Hf=s(aa," attribute:"),aa.forEach(t),fr=m(e),c(ho.$$.fragment,e),ur=m(e),c(po.$$.fragment,e),cr=m(e),Ae=i(e,"P",{});var Qh=h(Ae);Xf=s(Qh,"Note how "),Ts=i(Qh,"CODE",{});var oM=h(Ts);Sf=s(oM,"image_upscaler"),oM.forEach(t),Qf=s(Qh," is now part of the agents\u2019 toolbox."),Qh.forEach(t),wr=m(e),Pe=i(e,"P",{});var Vh=h(Pe);Vf=s(Vh,"Let\u2019s now try out the new tools! We will re-use the image we generated in "),jl=i(Vh,"A",{href:!0});var lM=h(jl);Ff=s(lM,"Transformers Agents Quickstart"),lM.forEach(t),zf=s(Vh,"."),Vh.forEach(t),yr=m(e),c(mo.$$.fragment,e),Mr=m(e),fo=i(e,"IMG",{src:!0,width:!0}),br=m(e),Gl=i(e,"P",{});var aM=h(Gl);qf=s(aM,"Let\u2019s transform the image into a beautiful winter landscape:"),aM.forEach(t),gr=m(e),c(uo.$$.fragment,e),vr=m(e),c(co.$$.fragment,e),Jr=m(e),wo=i(e,"IMG",{src:!0,width:!0}),Ur=m(e),Il=i(e,"P",{});var sM=h(Il);Af=s(sM,`The new image processing tool is based on ControlNet which can make very strong modifications to the image.
By default the image processing tool returns an image of size 512x512 pixels. Let\u2019s see if we can upscale it.`),sM.forEach(t),Tr=m(e),c(yo.$$.fragment,e),Er=m(e),c(Mo.$$.fragment,e),$r=m(e),bo=i(e,"IMG",{src:!0,width:!0}),Zr=m(e),_l=i(e,"P",{});var nM=h(_l);Pf=s(nM,`The agent automatically mapped our prompt \u201CUpscale the image\u201D to the just added upscaler tool purely based on the description and name of the upscaler tool
and was able to correctly run it.`),nM.forEach(t),jr=m(e),Wl=i(e,"P",{});var iM=h(Wl);Lf=s(iM,"Next, let\u2019s have a look at how you can create a new custom tool."),iM.forEach(t),Gr=m(e),ye=i(e,"H3",{class:!0});var Fh=h(ye);Le=i(Fh,"A",{id:!0,class:!0,href:!0});var rM=h(Le);Es=i(rM,"SPAN",{});var hM=h(Es);c(go.$$.fragment,hM),hM.forEach(t),rM.forEach(t),Df=m(Fh),$s=i(Fh,"SPAN",{});var pM=h($s);Of=s(pM,"Adding new tools"),pM.forEach(t),Fh.forEach(t),Ir=m(e),Bl=i(e,"P",{});var mM=h(Bl);Kf=s(mM,"In this section, we show how to create a new tool that can be added to the agent."),mM.forEach(t),_r=m(e),Me=i(e,"H4",{class:!0});var zh=h(Me);De=i(zh,"A",{id:!0,class:!0,href:!0});var dM=h(De);Zs=i(dM,"SPAN",{});var fM=h(Zs);c(vo.$$.fragment,fM),fM.forEach(t),dM.forEach(t),eu=m(zh),js=i(zh,"SPAN",{});var uM=h(js);tu=s(uM,"Creating a new tool"),uM.forEach(t),zh.forEach(t),Wr=m(e),kl=i(e,"P",{});var cM=h(kl);ou=s(cM,`We\u2019ll first start by creating a tool. We\u2019ll add the not-so-useful yet fun task of fetching the model on the Hugging Face
Hub with the most downloads for a given task.`),cM.forEach(t),Br=m(e),Rl=i(e,"P",{});var wM=h(Rl);lu=s(wM,"We can do that with the following code:"),wM.forEach(t),kr=m(e),c(Jo.$$.fragment,e),Rr=m(e),Y=i(e,"P",{});var ne=h(Y);au=s(ne,"For the task "),Gs=i(ne,"CODE",{});var yM=h(Gs);su=s(yM,"text-classification"),yM.forEach(t),nu=s(ne,", this returns "),Is=i(ne,"CODE",{});var MM=h(Is);iu=s(MM,"'facebook/bart-large-mnli'"),MM.forEach(t),ru=s(ne,", for "),_s=i(ne,"CODE",{});var bM=h(_s);hu=s(bM,"translation"),bM.forEach(t),pu=s(ne," it returns "),Ws=i(ne,"CODE",{});var gM=h(Ws);mu=s(gM,"'t5-base"),gM.forEach(t),du=s(ne,"."),ne.forEach(t),Cr=m(e),Oe=i(e,"P",{});var qh=h(Oe);fu=s(qh,"How do we convert this to a tool that the agent can leverage? All tools depend on the superclass "),Bs=i(qh,"CODE",{});var vM=h(Bs);uu=s(vM,"Tool"),vM.forEach(t),cu=s(qh,` that holds the
main attributes necessary. We\u2019ll create a class that inherits from it:`),qh.forEach(t),Yr=m(e),c(Uo.$$.fragment,e),Nr=m(e),Cl=i(e,"P",{});var JM=h(Cl);wu=s(JM,"This class has a few needs:"),JM.forEach(t),xr=m(e),z=i(e,"UL",{});var yt=h(z);be=i(yt,"LI",{});var sa=h(be);yu=s(sa,"An attribute "),ks=i(sa,"CODE",{});var UM=h(ks);Mu=s(UM,"name"),UM.forEach(t),bu=s(sa,`, which corresponds to the name of the tool itself. To be in tune with other tools which have a
performative name, we\u2019ll name it `),Rs=i(sa,"CODE",{});var TM=h(Rs);gu=s(TM,"model_download_counter"),TM.forEach(t),vu=s(sa,"."),sa.forEach(t),Ju=m(yt),To=i(yt,"LI",{});var Ah=h(To);Uu=s(Ah,"An attribute "),Cs=i(Ah,"CODE",{});var EM=h(Cs);Tu=s(EM,"description"),EM.forEach(t),Eu=s(Ah,", which will be used to populate the prompt of the agent."),Ah.forEach(t),$u=m(yt),N=i(yt,"LI",{});var q=h(N);Ys=i(q,"CODE",{});var $M=h(Ys);Zu=s($M,"inputs"),$M.forEach(t),ju=s(q," and "),Ns=i(q,"CODE",{});var ZM=h(Ns);Gu=s(ZM,"outputs"),ZM.forEach(t),Iu=s(q,` attributes. Defining this will help the python interpreter make educated choices about types,
and will allow for a gradio-demo to be spawned when we push our tool to the Hub. They\u2019re both a list of expected
values, which can be `),xs=i(q,"CODE",{});var jM=h(xs);_u=s(jM,"text"),jM.forEach(t),Wu=s(q,", "),Hs=i(q,"CODE",{});var GM=h(Hs);Bu=s(GM,"image"),GM.forEach(t),ku=s(q,", or "),Xs=i(q,"CODE",{});var IM=h(Xs);Ru=s(IM,"audio"),IM.forEach(t),Cu=s(q,"."),q.forEach(t),Yu=m(yt),Eo=i(yt,"LI",{});var Ph=h(Eo);Nu=s(Ph,"A "),Ss=i(Ph,"CODE",{});var _M=h(Ss);xu=s(_M,"__call__"),_M.forEach(t),Hu=s(Ph," method which contains the inference code. This is the code we\u2019ve played with above!"),Ph.forEach(t),yt.forEach(t),Hr=m(e),Yl=i(e,"P",{});var WM=h(Yl);Xu=s(WM,"Here\u2019s what our class looks like now:"),WM.forEach(t),Xr=m(e),c($o.$$.fragment,e),Sr=m(e),Ke=i(e,"P",{});var Lh=h(Ke);Su=s(Lh,`We now have our tool handy. Save it in a file and import it from your main script. Let\u2019s name this file
`),Qs=i(Lh,"CODE",{});var BM=h(Qs);Qu=s(BM,"model_downloads.py"),BM.forEach(t),Vu=s(Lh,", so the resulting import code looks like this:"),Lh.forEach(t),Qr=m(e),c(Zo.$$.fragment,e),Vr=m(e),ae=i(e,"P",{});var na=h(ae);Fu=s(na,`In order to let others benefit from it and for simpler initialization, we recommend pushing it to the Hub under your
namespace. To do so, just call `),Vs=i(na,"CODE",{});var kM=h(Vs);zu=s(kM,"push_to_hub"),kM.forEach(t),qu=s(na," on the "),Fs=i(na,"CODE",{});var RM=h(Fs);Au=s(RM,"tool"),RM.forEach(t),Pu=s(na," variable:"),na.forEach(t),Fr=m(e),c(jo.$$.fragment,e),zr=m(e),Nl=i(e,"P",{});var CM=h(Nl);Lu=s(CM,"You now have your code on the Hub! Let\u2019s take a look at the final step, which is to have the agent use it."),CM.forEach(t),qr=m(e),ge=i(e,"H4",{class:!0});var Dh=h(ge);et=i(Dh,"A",{id:!0,class:!0,href:!0});var YM=h(et);zs=i(YM,"SPAN",{});var NM=h(zs);c(Go.$$.fragment,NM),NM.forEach(t),YM.forEach(t),Du=m(Dh),qs=i(Dh,"SPAN",{});var xM=h(qs);Ou=s(xM,"Having the agent use the tool"),xM.forEach(t),Dh.forEach(t),Ar=m(e),xl=i(e,"P",{});var HM=h(xl);Ku=s(HM,"We now have our tool that lives on the Hub which can be instantiated as such (change the user name for your tool):"),HM.forEach(t),Pr=m(e),c(Io.$$.fragment,e),Lr=m(e),tt=i(e,"P",{});var Oh=h(tt);ec=s(Oh,"In order to use it in the agent, simply pass it in the "),As=i(Oh,"CODE",{});var XM=h(As);tc=s(XM,"additional_tools"),XM.forEach(t),oc=s(Oh," parameter of the agent initialization method:"),Oh.forEach(t),Dr=m(e),c(_o.$$.fragment,e),Or=m(e),Hl=i(e,"P",{});var SM=h(Hl);lc=s(SM,"which outputs the following:"),SM.forEach(t),Kr=m(e),c(Wo.$$.fragment,e),eh=m(e),Xl=i(e,"P",{});var QM=h(Xl);ac=s(QM,"and generates the following audio."),QM.forEach(t),th=m(e),ot=i(e,"TABLE",{});var Kh=h(ot);Ps=i(Kh,"THEAD",{});var VM=h(Ps);Ls=i(VM,"TR",{});var FM=h(Ls);Ds=i(FM,"TH",{});var zM=h(Ds);Os=i(zM,"STRONG",{});var qM=h(Os);sc=s(qM,"Audio"),qM.forEach(t),zM.forEach(t),FM.forEach(t),VM.forEach(t),nc=m(Kh),Ks=i(Kh,"TBODY",{});var AM=h(Ks);en=i(AM,"TR",{});var PM=h(en);tn=i(PM,"TD",{});var LM=h(tn);Sl=i(LM,"AUDIO",{});var DM=h(Sl);Ql=i(DM,"SOURCE",{src:!0,type:!0}),DM.forEach(t),LM.forEach(t),PM.forEach(t),AM.forEach(t),Kh.forEach(t),oh=m(e),c(lt.$$.fragment,e),lh=m(e),ve=i(e,"H3",{class:!0});var ep=h(ve);at=i(ep,"A",{id:!0,class:!0,href:!0});var OM=h(at);on=i(OM,"SPAN",{});var KM=h(on);c(Bo.$$.fragment,KM),KM.forEach(t),OM.forEach(t),ic=m(ep),ln=i(ep,"SPAN",{});var eb=h(ln);rc=s(eb,"Replacing existing tools"),eb.forEach(t),ep.forEach(t),ah=m(e),Vl=i(e,"P",{});var tb=h(Vl);hc=s(tb,"Replacing existing tools can be done simply by assigning a new item to the agent\u2019s toolbox. Here\u2019s how one would do so:"),tb.forEach(t),sh=m(e),c(ko.$$.fragment,e),nh=m(e),c(st.$$.fragment,e),ih=m(e),Je=i(e,"H2",{class:!0});var tp=h(Je);nt=i(tp,"A",{id:!0,class:!0,href:!0});var ob=h(nt);an=i(ob,"SPAN",{});var lb=h(an);c(Ro.$$.fragment,lb),lb.forEach(t),ob.forEach(t),pc=m(tp),sn=i(tp,"SPAN",{});var ab=h(sn);mc=s(ab,"Leveraging gradio-tools"),ab.forEach(t),tp.forEach(t),rh=m(e),Co=i(e,"P",{});var Vc=h(Co);Yo=i(Vc,"A",{href:!0,rel:!0});var sb=h(Yo);dc=s(sb,"gradio-tools"),sb.forEach(t),fc=s(Vc,` is a powerful library that allows using Hugging
Face Spaces as tools. It supports many existing Spaces as well as custom Spaces to be designed with it.`),Vc.forEach(t),hh=m(e),x=i(e,"P",{});var ie=h(x);uc=s(ie,"We offer support for "),nn=i(ie,"CODE",{});var nb=h(nn);cc=s(nb,"gradio_tools"),nb.forEach(t),wc=s(ie," by using the "),rn=i(ie,"CODE",{});var ib=h(rn);yc=s(ib,"Tool.from_gradio"),ib.forEach(t),Mc=s(ie,` method. For example, we want to take
advantage of the `),hn=i(ie,"CODE",{});var rb=h(hn);bc=s(rb,"StableDiffusionPromptGeneratorTool"),rb.forEach(t),gc=s(ie," tool offered in the "),pn=i(ie,"CODE",{});var hb=h(pn);vc=s(hb,"gradio-tools"),hb.forEach(t),Jc=s(ie,` toolkit so as to
improve our prompts and generate better images.`),ie.forEach(t),ph=m(e),it=i(e,"P",{});var op=h(it);Uc=s(op,"We first import the tool from "),mn=i(op,"CODE",{});var pb=h(mn);Tc=s(pb,"gradio_tools"),pb.forEach(t),Ec=s(op," and instantiate it:"),op.forEach(t),mh=m(e),c(No.$$.fragment,e),dh=m(e),rt=i(e,"P",{});var lp=h(rt);$c=s(lp,"We pass that instance to the "),dn=i(lp,"CODE",{});var mb=h(dn);Zc=s(mb,"Tool.from_gradio"),mb.forEach(t),jc=s(lp," method:"),lp.forEach(t),fh=m(e),c(xo.$$.fragment,e),uh=m(e),ht=i(e,"P",{});var ap=h(ht);Gc=s(ap,`Now we can manage it exactly as we would a usual custom tool. We leverage it to improve our prompt
`),fn=i(ap,"CODE",{});var db=h(fn);Ic=s(db,"a rabbit wearing a space suit"),db.forEach(t),_c=s(ap,":"),ap.forEach(t),ch=m(e),c(Ho.$$.fragment,e),wh=m(e),Fl=i(e,"P",{});var fb=h(Fl);Wc=s(fb,"The model adequately leverages the tool:"),fb.forEach(t),yh=m(e),c(Xo.$$.fragment,e),Mh=m(e),zl=i(e,"P",{});var ub=h(zl);Bc=s(ub,"Before finally generating the image:"),ub.forEach(t),bh=m(e),ql=i(e,"IMG",{src:!0}),gh=m(e),c(pt.$$.fragment,e),vh=m(e),Ue=i(e,"H2",{class:!0});var sp=h(Ue);mt=i(sp,"A",{id:!0,class:!0,href:!0});var cb=h(mt);un=i(cb,"SPAN",{});var wb=h(un);c(So.$$.fragment,wb),wb.forEach(t),cb.forEach(t),kc=m(sp),cn=i(sp,"SPAN",{});var yb=h(cn);Rc=s(yb,"Future compatibility with Langchain"),yb.forEach(t),sp.forEach(t),Jh=m(e),dt=i(e,"P",{});var np=h(dt);Cc=s(np,`We love Langchain and think it has a very compelling suite of tools. In order to handle these tools,
Langchain requires `),wn=i(np,"EM",{});var Mb=h(wn);Yc=s(Mb,"textual"),Mb.forEach(t),Nc=s(np,` inputs and outputs, even when working with different modalities.
This is often the serialized version (i.e., saved to disk) of the objects.`),np.forEach(t),Uh=m(e),Al=i(e,"P",{});var bb=h(Al);xc=s(bb,`This difference means that multi-modality isn\u2019t handled between transformers-agents and langchain.
We aim for this limitation to be resolved in future versions, and welcome any help from avid langchain
users to help us achieve this compatibility.`),bb.forEach(t),Th=m(e),ft=i(e,"P",{});var ip=h(ft);Hc=s(ip,`We would love to have better support. If you would like to help, please
`),Qo=i(ip,"A",{href:!0,rel:!0});var gb=h(Qo);Xc=s(gb,"open an issue"),gb.forEach(t),Sc=s(ip," and share what you have in mind."),ip.forEach(t),this.h()},h(){f(d,"name","hf:doc:metadata"),f(d,"content",JSON.stringify(Yb)),f(v,"id","custom-tools-and-prompts"),f(v,"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"),f(v,"href","#custom-tools-and-prompts"),f(g,"class","relative group"),f(Ee,"id","customizing-the-prompt"),f(Ee,"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"),f(Ee,"href","#customizing-the-prompt"),f(pe,"class","relative group"),f(qo,"href","transformers_agents"),f(Ao,"href","/docs/transformers/v4.31.0/en/main_classes/agent#transformers.Agent.run"),f(Po,"href","/docs/transformers/v4.31.0/en/main_classes/agent#transformers.Agent.chat"),f($e,"id","structure-of-the-prompt"),f($e,"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"),f($e,"href","#structure-of-the-prompt"),f(me,"class","relative group"),f(Do,"start","2"),f(Oo,"start","3"),f(Ko,"start","4"),f(Zt,"href","https://github.com/huggingface/transformers/blob/main/src/transformers/tools/evaluate_agent.py"),f(Zt,"rel","nofollow"),f(We,"id","writing-good-user-inputs"),f(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"),f(We,"href","#writing-good-user-inputs"),f(de,"class","relative group"),f(Be,"id","customizing-the-tool-descriptions"),f(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"),f(Be,"href","#customizing-the-tool-descriptions"),f(fe,"class","relative group"),f(Ce,"id","customizing-the-whole-prompt"),f(Ce,"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"),f(Ce,"href","#customizing-the-whole-prompt"),f(ue,"class","relative group"),f(vl,"href","#structure-of-the-prompt"),f(Ot,"href","https://huggingface.co/datasets/huggingface-tools/default-prompts"),f(Ot,"rel","nofollow"),f(Se,"id","using-custom-tools"),f(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"),f(Se,"href","#using-custom-tools"),f(ce,"class","relative group"),f(eo,"href","https://huggingface.co/spaces/huggingface-tools/image-transformation"),f(eo,"rel","nofollow"),f(to,"href","https://huggingface.co/spaces/diffusers/controlnet-canny-tool"),f(to,"rel","nofollow"),f(lo,"href","https://huggingface.co/spaces/diffusers/latent-upscaler-tool"),f(lo,"rel","nofollow"),f(Tl,"href","/docs/transformers/v4.31.0/en/main_classes/agent#transformers.load_tool"),f($l,"href","./transformers_agents#a-curated-set-of-tools"),f(jl,"href","./transformers_agents#single-execution-run"),$n(fo.src,Fc="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes.png")||f(fo,"src",Fc),f(fo,"width","200"),$n(wo.src,zc="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes_winter.png")||f(wo,"src",zc),f(wo,"width","200"),$n(bo.src,qc="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rivers_and_lakes_winter_upscale.png")||f(bo,"src",qc),f(bo,"width","400"),f(Le,"id","adding-new-tools"),f(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"),f(Le,"href","#adding-new-tools"),f(ye,"class","relative group"),f(De,"id","creating-a-new-tool"),f(De,"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"),f(De,"href","#creating-a-new-tool"),f(Me,"class","relative group"),f(et,"id","having-the-agent-use-the-tool"),f(et,"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"),f(et,"href","#having-the-agent-use-the-tool"),f(ge,"class","relative group"),$n(Ql.src,Ac="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/damo.wav")||f(Ql,"src",Ac),f(Ql,"type","audio/wav"),Sl.controls=!0,f(at,"id","replacing-existing-tools"),f(at,"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"),f(at,"href","#replacing-existing-tools"),f(ve,"class","relative group"),f(nt,"id","leveraging-gradiotools"),f(nt,"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"),f(nt,"href","#leveraging-gradiotools"),f(Je,"class","relative group"),f(Yo,"href","https://github.com/freddyaboulton/gradio-tools"),f(Yo,"rel","nofollow"),$n(ql.src,Pc="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png")||f(ql,"src",Pc),f(mt,"id","future-compatibility-with-langchain"),f(mt,"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"),f(mt,"href","#future-compatibility-with-langchain"),f(Ue,"class","relative group"),f(Qo,"href","https://github.com/huggingface/transformers/issues/new"),f(Qo,"rel","nofollow")},m(e,l){o(document.head,d),r(e,U,l),r(e,g,l),o(g,v),o(v,$),w(T,$,null),o(g,E),o(g,j),o(j,k),r(e,B,l),w(R,e,l),r(e,X,l),w(I,e,l),r(e,Mt,l),r(e,he,l),o(he,zo),r(e,Zn,l),r(e,A,l),o(A,ia),o(ia,rp),o(A,hp),o(A,ra),o(ra,pp),o(A,mp),o(A,ha),o(ha,dp),r(e,jn,l),r(e,pe,l),o(pe,Ee),o(Ee,pa),w(bt,pa,null),o(pe,fp),o(pe,ma),o(ma,up),r(e,G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(pn,vc),o(x,Jc),r(e,ph,l),r(e,it,l),o(it,Uc),o(it,mn),o(mn,Tc),o(it,Ec),r(e,mh,l),w(No,e,l),r(e,dh,l),r(e,rt,l),o(rt,$c),o(rt,dn),o(dn,Zc),o(rt,jc),r(e,fh,l),w(xo,e,l),r(e,uh,l),r(e,ht,l),o(ht,Gc),o(ht,fn),o(fn,Ic),o(ht,_c),r(e,ch,l),w(Ho,e,l),r(e,wh,l),r(e,Fl,l),o(Fl,Wc),r(e,yh,l),w(Xo,e,l),r(e,Mh,l),r(e,zl,l),o(zl,Bc),r(e,bh,l),r(e,ql,l),r(e,gh,l),w(pt,e,l),r(e,vh,l),r(e,Ue,l),o(Ue,mt),o(mt,un),w(So,un,null),o(Ue,kc),o(Ue,cn),o(cn,Rc),r(e,Jh,l),r(e,dt,l),o(dt,Cc),o(dt,wn),o(wn,Yc),o(dt,Nc),r(e,Uh,l),r(e,Al,l),o(Al,xc),r(e,Th,l),r(e,ft,l),o(ft,Hc),o(ft,Qo),o(Qo,Xc),o(ft,Sc),Eh=!0},p(e,[l]){const Vo={};l&2&&(Vo.$$scope={dirty:l,ctx:e}),R.$set(Vo);const yn={};l&2&&(yn.$$scope={dirty:l,ctx:e}),I.$set(yn);const Mn={};l&2&&(Mn.$$scope={dirty:l,ctx:e}),Ge.$set(Mn);const bn={};l&2&&(bn.$$scope={dirty:l,ctx:e}),Re.$set(bn);const gn={};l&2&&(gn.$$scope={dirty:l,ctx:e}),Ye.$set(gn);const Te={};l&2&&(Te.$$scope={dirty:l,ctx:e}),Ne.$set(Te);const vn={};l&2&&(vn.$$scope={dirty:l,ctx:e}),qe.$set(vn);const Jn={};l&2&&(Jn.$$scope={dirty:l,ctx:e}),lt.$set(Jn);const Un={};l&2&&(Un.$$scope={dirty:l,ctx:e}),st.$set(Un);const Fo={};l&2&&(Fo.$$scope={dirty:l,ctx:e}),pt.$set(Fo)},i(e){Eh||(y(T.$$.fragment,e),y(R.$$.fragment,e),y(I.$$.fragment,e),y(bt.$$.fragment,e),y(gt.$$.fragment,e),y(Jt.$$.fragment,e),y(Ut.$$.fragment,e),y(Tt.$$.fragment,e),y(Et.$$.fragment,e),y(Ge.$$.fragment,e),y($t.$$.fragment,e),y(jt.$$.fragment,e),y(Gt.$$.fragment,e),y(It.$$.fragment,e),y(_t.$$.fragment,e),y(Wt.$$.fragment,e),y(Bt.$$.fragment,e),y(kt.$$.fragment,e),y(Rt.$$.fragment,e),y(Ct.$$.fragment,e),y(Yt.$$.fragment,e),y(Nt.$$.fragment,e),y(xt.$$.fragment,e),y(Xt.$$.fragment,e),y(St.$$.fragment,e),y(Qt.$$.fragment,e),y(Vt.$$.fragment,e),y(Ft.$$.fragment,e),y(zt.$$.fragment,e),y(qt.$$.fragment,e),y(Re.$$.fragment,e),y(At.$$.fragment,e),y(Pt.$$.fragment,e),y(Ye.$$.fragment,e),y(Lt.$$.fragment,e),y(Dt.$$.fragment,e),y(Ne.$$.fragment,e),y(Kt.$$.fragment,e),y(ao.$$.fragment,e),y(so.$$.fragment,e),y(no.$$.fragment,e),y(io.$$.fragment,e),y(ro.$$.fragment,e),y(qe.$$.fragment,e),y(ho.$$.fragment,e),y(po.$$.fragment,e),y(mo.$$.fragment,e),y(uo.$$.fragment,e),y(co.$$.fragment,e),y(yo.$$.fragment,e),y(Mo.$$.fragment,e),y(go.$$.fragment,e),y(vo.$$.fragment,e),y(Jo.$$.fragment,e),y(Uo.$$.fragment,e),y($o.$$.fragment,e),y(Zo.$$.fragment,e),y(jo.$$.fragment,e),y(Go.$$.fragment,e),y(Io.$$.fragment,e),y(_o.$$.fragment,e),y(Wo.$$.fragment,e),y(lt.$$.fragment,e),y(Bo.$$.fragment,e),y(ko.$$.fragment,e),y(st.$$.fragment,e),y(Ro.$$.fragment,e),y(No.$$.fragment,e),y(xo.$$.fragment,e),y(Ho.$$.fragment,e),y(Xo.$$.fragment,e),y(pt.$$.fragment,e),y(So.$$.fragment,e),Eh=!0)},o(e){M(T.$$.fragment,e),M(R.$$.fragment,e),M(I.$$.fragment,e),M(bt.$$.fragment,e),M(gt.$$.fragment,e),M(Jt.$$.fragment,e),M(Ut.$$.fragment,e),M(Tt.$$.fragment,e),M(Et.$$.fragment,e),M(Ge.$$.fragment,e),M($t.$$.fragment,e),M(jt.$$.fragment,e),M(Gt.$$.fragment,e),M(It.$$.fragment,e),M(_t.$$.fragment,e),M(Wt.$$.fragment,e),M(Bt.$$.fragment,e),M(kt.$$.fragment,e),M(Rt.$$.fragment,e),M(Ct.$$.fragment,e),M(Yt.$$.fragment,e),M(Nt.$$.fragment,e),M(xt.$$.fragment,e),M(Xt.$$.fragment,e),M(St.$$.fragment,e),M(Qt.$$.fragment,e),M(Vt.$$.fragment,e),M(Ft.$$.fragment,e),M(zt.$$.fragment,e),M(qt.$$.fragment,e),M(Re.$$.fragment,e),M(At.$$.fragment,e),M(Pt.$$.fragment,e),M(Ye.$$.fragment,e),M(Lt.$$.fragment,e),M(Dt.$$.fragment,e),M(Ne.$$.fragment,e),M(Kt.$$.fragment,e),M(ao.$$.fragment,e),M(so.$$.fragment,e),M(no.$$.fragment,e),M(io.$$.fragment,e),M(ro.$$.fragment,e),M(qe.$$.fragment,e),M(ho.$$.fragment,e),M(po.$$.fragment,e),M(mo.$$.fragment,e),M(uo.$$.fragment,e),M(co.$$.fragment,e),M(yo.$$.fragment,e),M(Mo.$$.fragment,e),M(go.$$.fragment,e),M(vo.$$.fragment,e),M(Jo.$$.fragment,e),M(Uo.$$.fragment,e),M($o.$$.fragment,e),M(Zo.$$.fragment,e),M(jo.$$.fragment,e),M(Go.$$.fragment,e),M(Io.$$.fragment,e),M(_o.$$.fragment,e),M(Wo.$$.fragment,e),M(lt.$$.fragment,e),M(Bo.$$.fragment,e),M(ko.$$.fragment,e),M(st.$$.fragment,e),M(Ro.$$.fragment,e),M(No.$$.fragment,e),M(xo.$$.fragment,e),M(Ho.$$.fragment,e),M(Xo.$$.fragment,e),M(pt.$$.fragment,e),M(So.$$.fragment,e),Eh=!1},d(e){t(d),e&&t(U),e&&t(g),b(T),e&&t(B),b(R,e),e&&t(X),b(I,e),e&&t(Mt),e&&t(he),e&&t(Zn),e&&t(A),e&&t(jn),e&&t(pe),b(bt),e&&t(Gn),e&&t(_),e&&t(In),e&&t(me),b(gt),e&&t(_n),e&&t(Lo),e&&t(Wn),e&&t(Q),e&&t(Bn),e&&t(Ze),e&&t(kn),b(Jt,e),e&&t(Rn),e&&t(je),e&&t(Cn),e&&t(C),e&&t(Yn),b(Ut,e),e&&t(Nn),e&&t(el),e&&t(xn),b(Tt,e),e&&t(Hn),e&&t(tl),e&&t(Xn),b(Et,e),e&&t(Sn),e&&t(ol),e&&t(Qn),e&&t(ll),e&&t(Vn),b(Ge,e),e&&t(Fn),e&&t(al),e&&t(zn),e&&t(sl),e&&t(qn),b($t,e),e&&t(An),e&&t(nl),e&&t(Pn),e&&t(Ie),e&&t(Ln),e&&t(il),e&&t(Dn),b(jt,e),e&&t(On),e&&t(rl),e&&t(Kn),b(Gt,e),e&&t(ei),e&&t(P),e&&t(ti),e&&t(_e),e&&t(oi),b(It,e),e&&t(li),e&&t(G),e&&t(ai),e&&t(L),e&&t(si),b(_t,e),e&&t(ni),e&&t(V),e&&t(ii),e&&t(hl),e&&t(ri),e&&t(de),b(Wt),e&&t(hi),e&&t(pl),e&&t(pi),e&&t(ml),e&&t(mi),b(Bt,e),e&&t(di),e&&t(dl),e&&t(fi),b(kt,e),e&&t(ui),e&&t(fl),e&&t(ci),b(Rt,e),e&&t(wi),b(Ct,e),e&&t(yi),e&&t(ul),e&&t(Mi),b(Yt,e),e&&t(bi),e&&t(cl),e&&t(gi),b(Nt,e),e&&t(vi),e&&t(wl),e&&t(Ji),e&&t(fe),b(xt),e&&t(Ui),e&&t(ke),e&&t(Ti),e&&t(Ht),e&&t(Ei),b(Xt,e),e&&t($i),e&&t(yl),e&&t(Zi),b(St,e),e&&t(ji),e&&t(D),e&&t(Gi),e&&t(O),e&&t(Ii),b(Qt,e),e&&t(_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r),e&&t(z),e&&t(Hr),e&&t(Yl),e&&t(Xr),b($o,e),e&&t(Sr),e&&t(Ke),e&&t(Qr),b(Zo,e),e&&t(Vr),e&&t(ae),e&&t(Fr),b(jo,e),e&&t(zr),e&&t(Nl),e&&t(qr),e&&t(ge),b(Go),e&&t(Ar),e&&t(xl),e&&t(Pr),b(Io,e),e&&t(Lr),e&&t(tt),e&&t(Dr),b(_o,e),e&&t(Or),e&&t(Hl),e&&t(Kr),b(Wo,e),e&&t(eh),e&&t(Xl),e&&t(th),e&&t(ot),e&&t(oh),b(lt,e),e&&t(lh),e&&t(ve),b(Bo),e&&t(ah),e&&t(Vl),e&&t(sh),b(ko,e),e&&t(nh),b(st,e),e&&t(ih),e&&t(Je),b(Ro),e&&t(rh),e&&t(Co),e&&t(hh),e&&t(x),e&&t(ph),e&&t(it),e&&t(mh),b(No,e),e&&t(dh),e&&t(rt),e&&t(fh),b(xo,e),e&&t(uh),e&&t(ht),e&&t(ch),b(Ho,e),e&&t(wh),e&&t(Fl),e&&t(yh),b(Xo,e),e&&t(Mh),e&&t(zl),e&&t(bh),e&&t(ql),e&&t(gh),b(pt,e),e&&t(vh),e&&t(Ue),b(So),e&&t(Jh),e&&t(dt),e&&t(Uh),e&&t(Al),e&&t(Th),e&&t(ft)}}}const Yb={local:"custom-tools-and-prompts",sections:[{local:"customizing-the-prompt",sections:[{local:"structure-of-the-prompt",title:"Structure of the prompt"},{local:"writing-good-user-inputs",title:"Writing good user inputs"},{local:"customizing-the-tool-descriptions",title:"Customizing the tool descriptions"},{local:"customizing-the-whole-prompt",title:"Customizing the whole prompt"}],title:"Customizing the prompt"},{local:"using-custom-tools",sections:[{local:"adding-new-tools",sections:[{local:"creating-a-new-tool",title:"Creating a new tool"},{local:"having-the-agent-use-the-tool",title:"Having the agent use the tool"}],title:"Adding new tools"},{local:"replacing-existing-tools",title:"Replacing existing tools"}],title:"Using custom tools"},{local:"leveraging-gradiotools",title:"Leveraging gradio-tools"},{local:"future-compatibility-with-langchain",title:"Future compatibility with Langchain"}],title:"Custom Tools and Prompts"};function Nb(Z){return Eb(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Qb extends vb{constructor(d){super();Jb(this,d,Nb,Cb,Ub,{})}}export{Qb as default,Yb as metadata};
