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