import{s as vl,n as xl,o as _l}from"../chunks/scheduler.37c15a92.js";import{S as Hl,i as Zl,g as s,s as J,r as U,A as Bl,h as a,f as t,c as n,j as $l,u as i,x as o,k as wl,y as Nl,a as T,v as g,d as A,t as r,w as y}from"../chunks/index.2bf4358c.js";import{C as Ol}from"../chunks/CodeBlock.4e987730.js";import{C as Gl}from"../chunks/CourseFloatingBanner.6add7356.js";import{H as Ml}from"../chunks/Heading.8ada512a.js";import{E as Wl}from"../chunks/getInferenceSnippets.0aa3753f.js";function Ll(pl){let O,W,N,L,w,q,p,E,M,cl='<p>You can follow the code in <a href="https://huggingface.co/agents-course/notebooks/blob/main/unit2/smolagents/tool_calling_agents.ipynb" target="_blank">this notebook</a> that you can run using Google Colab.</p>',F,c,ul="Tool Calling Agents are the second type of agent available in <code>smolagents</code>. Unlike Code Agents that use Python snippets, these agents <strong>use the built-in tool-calling capabilities of LLM providers</strong> to generate tool calls as <strong>JSON structures</strong>. This is the standard approach used by OpenAI, Anthropic, and many other providers.",S,u,jl="Let’s look at an example. When Alfred wants to search for catering services and party ideas, a <code>CodeAgent</code> would generate and run Python code like this:",V,j,Y,k,kl="A <code>ToolCallingAgent</code> would instead create a JSON structure:",X,I,P,m,Il="This JSON blob is then used to execute the tool calls.",z,f,ml='While <code>smolagents</code> primarily focuses on <code>CodeAgents</code> since <a href="https://huggingface.co/papers/2402.01030" rel="nofollow">they perform better overall</a>, <code>ToolCallingAgents</code> can be effective for simple systems that don’t require variable handling or complex tool calls.',K,h,fl='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/code_vs_json_actions.png" alt="Code vs JSON Actions"/>',ll,Q,el,R,hl='Tool Calling Agents follow the same multi-step workflow as Code Agents (see the <a href="./code_agents">previous section</a> for details).',tl,D,Ql="The key difference is in <strong>how they structure their actions</strong>: instead of executable code, they <strong>generate JSON objects that specify tool names and arguments</strong>. The system then <strong>parses these instructions</strong> to execute the appropriate tools.",Tl,d,Jl,b,Rl="Let’s revisit the previous example where Alfred started party preparations, but this time we’ll use a <code>ToolCallingAgent</code> to highlight the difference. We’ll build an agent that can search the web using DuckDuckGo, just like in our Code Agent example. The only difference is the agent type - the framework handles everything else:",nl,C,sl,$,Dl="When you examine the agent’s trace, instead of seeing <code>Executing parsed code:</code>, you’ll see something like:",al,v,ol,x,dl="The agent generates a structured tool call that the system processes to produce the output, rather than directly executing code like a <code>CodeAgent</code>.",Ul,_,bl="Now that we understand both agent types, we can choose the right one for our needs. Let’s continue exploring <code>smolagents</code> to make Alfred’s party a success! 🎉",il,H,gl,Z,Cl='<li><a href="https://huggingface.co/docs/smolagents/v1.8.1/en/reference/agents#smolagents.ToolCallingAgent" rel="nofollow">ToolCallingAgent documentation</a> - Official documentation for ToolCallingAgent</li>',Al,B,rl,G,yl;return w=new Gl({props:{classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/#fileId=https://huggingface.co/agents-course/notebooks/blob/main/unit2/smolagents/tool_calling_agents.ipynb"}],askForHelpUrl:"http://hf.co/join/discord"}}),p=new Ml({props:{title:"Writing actions as code snippets or JSON blobs",local:"writing-actions-as-code-snippets-or-json-blobs",headingTag:"h1"}}),j=new Ol({props:{code:"Zm9yJTIwcXVlcnklMjBpbiUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMkJlc3QlMjBjYXRlcmluZyUyMHNlcnZpY2VzJTIwaW4lMjBHb3RoYW0lMjBDaXR5JTIyJTJDJTIwJTBBJTIwJTIwJTIwJTIwJTIyUGFydHklMjB0aGVtZSUyMGlkZWFzJTIwZm9yJTIwc3VwZXJoZXJvZXMlMjIlMEElNUQlM0ElMEElMjAlMjAlMjAlMjBwcmludCh3ZWJfc2VhcmNoKGYlMjJTZWFyY2glMjBmb3IlM0ElMjAlN0JxdWVyeSU3RCUyMikp",highlighted:`<span class="hljs-keyword">for</span> query <span class="hljs-keyword">in</span> [
    <span class="hljs-string">&quot;Best catering services in Gotham City&quot;</span>, 
    <span class="hljs-string">&quot;Party theme ideas for superheroes&quot;</span>
]:
    <span class="hljs-built_in">print</span>(web_search(<span class="hljs-string">f&quot;Search for: <span class="hljs-subst">{query}</span>&quot;</span>))`,wrap:!1}}),I=new Ol({props:{code:"JTVCJTBBJTIwJTIwJTIwJTIwJTdCJTIybmFtZSUyMiUzQSUyMCUyMndlYl9zZWFyY2glMjIlMkMlMjAlMjJhcmd1bWVudHMlMjIlM0ElMjAlMjJCZXN0JTIwY2F0ZXJpbmclMjBzZXJ2aWNlcyUyMGluJTIwR290aGFtJTIwQ2l0eSUyMiU3RCUyQyUwQSUyMCUyMCUyMCUyMCU3QiUyMm5hbWUlMjIlM0ElMjAlMjJ3ZWJfc2VhcmNoJTIyJTJDJTIwJTIyYXJndW1lbnRzJTIyJTNBJTIwJTIyUGFydHklMjB0aGVtZSUyMGlkZWFzJTIwZm9yJTIwc3VwZXJoZXJvZXMlMjIlN0QlMEElNUQ=",highlighted:`[
    {<span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;web_search&quot;</span>, <span class="hljs-string">&quot;arguments&quot;</span>: <span class="hljs-string">&quot;Best catering services in Gotham City&quot;</span>},
    {<span class="hljs-string">&quot;name&quot;</span>: <span class="hljs-string">&quot;web_search&quot;</span>, <span class="hljs-string">&quot;arguments&quot;</span>: <span class="hljs-string">&quot;Party theme ideas for superheroes&quot;</span>}
]`,wrap:!1}}),Q=new Ml({props:{title:"How Do Tool Calling Agents Work?",local:"how-do-tool-calling-agents-work",headingTag:"h2"}}),d=new Ml({props:{title:"Example: Running a Tool Calling Agent",local:"example-running-a-tool-calling-agent",headingTag:"h2"}}),C=new Ol({props:{code:"ZnJvbSUyMHNtb2xhZ2VudHMlMjBpbXBvcnQlMjBUb29sQ2FsbGluZ0FnZW50JTJDJTIwRHVja0R1Y2tHb1NlYXJjaFRvb2wlMkMlMjBJbmZlcmVuY2VDbGllbnRNb2RlbCUwQSUwQWFnZW50JTIwJTNEJTIwVG9vbENhbGxpbmdBZ2VudCh0b29scyUzRCU1QkR1Y2tEdWNrR29TZWFyY2hUb29sKCklNUQlMkMlMjBtb2RlbCUzREluZmVyZW5jZUNsaWVudE1vZGVsKCkpJTBBJTBBYWdlbnQucnVuKCUyMlNlYXJjaCUyMGZvciUyMHRoZSUyMGJlc3QlMjBtdXNpYyUyMHJlY29tbWVuZGF0aW9ucyUyMGZvciUyMGElMjBwYXJ0eSUyMGF0JTIwdGhlJTIwV2F5bmUncyUyMG1hbnNpb24uJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> smolagents <span class="hljs-keyword">import</span> ToolCallingAgent, DuckDuckGoSearchTool, InferenceClientModel

agent = ToolCallingAgent(tools=[DuckDuckGoSearchTool()], model=InferenceClientModel())

agent.run(<span class="hljs-string">&quot;Search for the best music recommendations for a party at the Wayne&#x27;s mansion.&quot;</span>)`,wrap:!1}}),v=new Ol({props:{code:"JUUyJTk1JUFEJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTgwJUUyJTk0JTg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lRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTQlODAlRTIlOTUlQUY=",highlighted:`╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Calling tool: &#x27;web_search&#x27; with arguments: {&#x27;query&#x27;: &quot;best music recommendations for a party at Wayne&#x27;s         │
│ mansion&quot;}                                                                                                       │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯`,wrap:!1}}),H=new Ml({props:{title:"Resources",local:"resources",headingTag:"h2"}}),B=new Wl({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/en/unit2/smolagents/tool_calling_agents.mdx"}}),{c(){O=s("meta"),W=J(),N=s("p"),L=J(),U(w.$$.fragment),q=J(),U(p.$$.fragment),E=J(),M=s("blockquote"),M.innerHTML=cl,F=J(),c=s("p"),c.innerHTML=ul,S=J(),u=s("p"),u.innerHTML=jl,V=J(),U(j.$$.fragment),Y=J(),k=s("p"),k.innerHTML=kl,X=J(),U(I.$$.fragment),P=J(),m=s("p"),m.textContent=Il,z=J(),f=s("p"),f.innerHTML=ml,K=J(),h=s("p"),h.innerHTML=fl,ll=J(),U(Q.$$.fragment),el=J(),R=s("p"),R.innerHTML=hl,tl=J(),D=s("p"),D.innerHTML=Ql,Tl=J(),U(d.$$.fragment),Jl=J(),b=s("p"),b.innerHTML=Rl,nl=J(),U(C.$$.fragment),sl=J(),$=s("p"),$.innerHTML=Dl,al=J(),U(v.$$.fragment),ol=J(),x=s("p"),x.innerHTML=dl,Ul=J(),_=s("p"),_.innerHTML=bl,il=J(),U(H.$$.fragment),gl=J(),Z=s("ul"),Z.innerHTML=Cl,Al=J(),U(B.$$.fragment),rl=J(),G=s("p"),this.h()},l(l){const e=Bl("svelte-u9bgzb",document.head);O=a(e,"META",{name:!0,content:!0}),e.forEach(t),W=n(l),N=a(l,"P",{}),$l(N).forEach(t),L=n(l),i(w.$$.fragment,l),q=n(l),i(p.$$.fragment,l),E=n(l),M=a(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),o(M)!=="svelte-1oh0rol"&&(M.innerHTML=cl),F=n(l),c=a(l,"P",{"data-svelte-h":!0}),o(c)!=="svelte-1rmoi6l"&&(c.innerHTML=ul),S=n(l),u=a(l,"P",{"data-svelte-h":!0}),o(u)!=="svelte-1dxa6xl"&&(u.innerHTML=jl),V=n(l),i(j.$$.fragment,l),Y=n(l),k=a(l,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1jax7uc"&&(k.innerHTML=kl),X=n(l),i(I.$$.fragment,l),P=n(l),m=a(l,"P",{"data-svelte-h":!0}),o(m)!=="svelte-yir591"&&(m.textContent=Il),z=n(l),f=a(l,"P",{"data-svelte-h":!0}),o(f)!=="svelte-14p5555"&&(f.innerHTML=ml),K=n(l),h=a(l,"P",{"data-svelte-h":!0}),o(h)!=="svelte-18ub6lf"&&(h.innerHTML=fl),ll=n(l),i(Q.$$.fragment,l),el=n(l),R=a(l,"P",{"data-svelte-h":!0}),o(R)!=="svelte-12pis8u"&&(R.innerHTML=hl),tl=n(l),D=a(l,"P",{"data-svelte-h":!0}),o(D)!=="svelte-npjcu3"&&(D.innerHTML=Ql),Tl=n(l),i(d.$$.fragment,l),Jl=n(l),b=a(l,"P",{"data-svelte-h":!0}),o(b)!=="svelte-u98cxl"&&(b.innerHTML=Rl),nl=n(l),i(C.$$.fragment,l),sl=n(l),$=a(l,"P",{"data-svelte-h":!0}),o($)!=="svelte-1agnc2a"&&($.innerHTML=Dl),al=n(l),i(v.$$.fragment,l),ol=n(l),x=a(l,"P",{"data-svelte-h":!0}),o(x)!=="svelte-kdf7f8"&&(x.innerHTML=dl),Ul=n(l),_=a(l,"P",{"data-svelte-h":!0}),o(_)!=="svelte-160j1pf"&&(_.innerHTML=bl),il=n(l),i(H.$$.fragment,l),gl=n(l),Z=a(l,"UL",{"data-svelte-h":!0}),o(Z)!=="svelte-ebdx7j"&&(Z.innerHTML=Cl),Al=n(l),i(B.$$.fragment,l),rl=n(l),G=a(l,"P",{}),$l(G).forEach(t),this.h()},h(){wl(O,"name","hf:doc:metadata"),wl(O,"content",ql),wl(M,"class","tip")},m(l,e){Nl(document.head,O),T(l,W,e),T(l,N,e),T(l,L,e),g(w,l,e),T(l,q,e),g(p,l,e),T(l,E,e),T(l,M,e),T(l,F,e),T(l,c,e),T(l,S,e),T(l,u,e),T(l,V,e),g(j,l,e),T(l,Y,e),T(l,k,e),T(l,X,e),g(I,l,e),T(l,P,e),T(l,m,e),T(l,z,e),T(l,f,e),T(l,K,e),T(l,h,e),T(l,ll,e),g(Q,l,e),T(l,el,e),T(l,R,e),T(l,tl,e),T(l,D,e),T(l,Tl,e),g(d,l,e),T(l,Jl,e),T(l,b,e),T(l,nl,e),g(C,l,e),T(l,sl,e),T(l,$,e),T(l,al,e),g(v,l,e),T(l,ol,e),T(l,x,e),T(l,Ul,e),T(l,_,e),T(l,il,e),g(H,l,e),T(l,gl,e),T(l,Z,e),T(l,Al,e),g(B,l,e),T(l,rl,e),T(l,G,e),yl=!0},p:xl,i(l){yl||(A(w.$$.fragment,l),A(p.$$.fragment,l),A(j.$$.fragment,l),A(I.$$.fragment,l),A(Q.$$.fragment,l),A(d.$$.fragment,l),A(C.$$.fragment,l),A(v.$$.fragment,l),A(H.$$.fragment,l),A(B.$$.fragment,l),yl=!0)},o(l){r(w.$$.fragment,l),r(p.$$.fragment,l),r(j.$$.fragment,l),r(I.$$.fragment,l),r(Q.$$.fragment,l),r(d.$$.fragment,l),r(C.$$.fragment,l),r(v.$$.fragment,l),r(H.$$.fragment,l),r(B.$$.fragment,l),yl=!1},d(l){l&&(t(W),t(N),t(L),t(q),t(E),t(M),t(F),t(c),t(S),t(u),t(V),t(Y),t(k),t(X),t(P),t(m),t(z),t(f),t(K),t(h),t(ll),t(el),t(R),t(tl),t(D),t(Tl),t(Jl),t(b),t(nl),t(sl),t($),t(al),t(ol),t(x),t(Ul),t(_),t(il),t(gl),t(Z),t(Al),t(rl),t(G)),t(O),y(w,l),y(p,l),y(j,l),y(I,l),y(Q,l),y(d,l),y(C,l),y(v,l),y(H,l),y(B,l)}}}const ql='{"title":"Writing actions as code snippets or JSON blobs","local":"writing-actions-as-code-snippets-or-json-blobs","sections":[{"title":"How Do Tool Calling Agents Work?","local":"how-do-tool-calling-agents-work","sections":[],"depth":2},{"title":"Example: Running a Tool Calling Agent","local":"example-running-a-tool-calling-agent","sections":[],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2}],"depth":1}';function El(pl){return _l(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class zl extends Hl{constructor(O){super(),Zl(this,O,El,Ll,vl,{})}}export{zl as component};
