{"id":589,"date":"2025-01-11T15:17:25","date_gmt":"2025-01-11T15:17:25","guid":{"rendered":"https:\/\/smolagents.org\/?post_type=docs&#038;p=589"},"modified":"2025-01-11T15:41:32","modified_gmt":"2025-01-11T15:41:32","password":"","slug":"building-good-smolagents","status":"publish","type":"docs","link":"https:\/\/smolagents.org\/de\/docs\/building-good-smolagents\/","title":{"rendered":"Gute Smolagents aufbauen"},"content":{"rendered":"<p>Es besteht ein himmelweiter Unterschied zwischen einem Agenten, der funktioniert, und einem, der nicht funktioniert. Wie k\u00f6nnen wir Agenten erstellen, die in die letztere Kategorie fallen? In diesem Leitfaden werden wir uns bew\u00e4hrte Verfahren f\u00fcr die Erstellung von Agenten ansehen.<\/p>\n\n\n\n<p>Wenn Sie neu im Bereich der Bauagenten sind, sollten Sie zuerst die\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/conceptual_guides\/intro_agents\" target=\"_blank\" rel=\"noopener\">Einleitung<\/a><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/conceptual_guides\/intro_agents\" target=\"_blank\" rel=\"noreferrer noopener nofollow\"> <\/a><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/conceptual_guides\/intro_agents\" target=\"_blank\" rel=\"noopener\">an Agenten<\/a>\u00a0und die\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">gef\u00fchrte Besichtigung von smolagents<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#the-best-agentic-systems-are-the-simplest-simplify-the-workflow-as-much-as-you-can\" target=\"_blank\" rel=\"noopener\"><\/a>Die besten Agentensysteme sind die einfachsten: vereinfachen Sie den Arbeitsablauf so weit wie m\u00f6glich<\/h3>\n\n\n\n<p>Die Einbindung eines LLM in Ihren Arbeitsablauf birgt ein gewisses Fehlerrisiko.<\/p>\n\n\n\n<p>Gut programmierte Agentensysteme verf\u00fcgen ohnehin \u00fcber eine gute Fehlerprotokollierung und Wiederholungsmechanismen, so dass die LLM-Engine eine Chance hat, ihren Fehler selbst zu korrigieren. Aber um das Risiko von LLM-Fehlern auf ein Maximum zu reduzieren, sollten Sie Ihren Arbeitsablauf vereinfachen!<\/p>\n\n\n\n<p>Schauen wir uns noch einmal das Beispiel aus [intro_agents] an: ein Bot, der Benutzeranfragen f\u00fcr ein Surfreiseunternehmen beantwortet. Anstatt den Agenten jedes Mal, wenn er nach einem neuen Surfspot gefragt wird, zwei verschiedene Aufrufe f\u00fcr die \"Reiseentfernungs-API\" und die \"Wetter-API\" machen zu lassen, k\u00f6nnte man einfach ein einheitliches Tool \"return_spot_information\" erstellen, eine Funktion, die beide APIs auf einmal aufruft und deren verkettete Ausgaben an den Benutzer zur\u00fcckgibt.<\/p>\n\n\n\n<p>Dadurch werden Kosten, Latenzzeiten und das Fehlerrisiko reduziert!<\/p>\n\n\n\n<p>Die wichtigste Leitlinie ist: Verringern Sie die Anzahl der Anrufe von LLM so weit wie m\u00f6glich.<\/p>\n\n\n\n<p>Daraus ergeben sich einige Schlussfolgerungen:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Wenn immer m\u00f6glich, gruppieren Sie 2 Werkzeuge in einem, wie in unserem Beispiel der beiden APIs.<\/li>\n\n\n\n<li>Wann immer m\u00f6glich, sollte die Logik auf deterministischen Funktionen und nicht auf agentenbasierten Entscheidungen beruhen.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#improve-the-information-flow-to-the-llm-engine\" target=\"_blank\" rel=\"noopener\"><\/a>Verbesserung des Informationsflusses zur LLM-Engine<\/h3>\n\n\n\n<p>Denken Sie daran, dass Ihre LLM-Engine wie ein ~intelligenter~ Roboter ist, der in einem Raum eingeschlossen ist und dessen einzige Kommunikation mit der Au\u00dfenwelt aus Notizen besteht, die unter einer T\u00fcr hindurchgef\u00fchrt werden.<\/p>\n\n\n\n<p>Es wei\u00df nicht, was passiert ist, wenn Sie dies nicht ausdr\u00fccklich in der Eingabeaufforderung angeben.<\/p>\n\n\n\n<p>Fangen Sie also damit an, dass Sie Ihre Aufgabe sehr klar formulieren! Da ein Agent von einem LLM angetrieben wird, k\u00f6nnen geringf\u00fcgige Abweichungen bei der Formulierung Ihrer Aufgabe zu v\u00f6llig anderen Ergebnissen f\u00fchren.<\/p>\n\n\n\n<p>Verbessern Sie dann den Informationsfluss zu Ihrem Agenten bei der Verwendung von Tools.<\/p>\n\n\n\n<p>Besondere Leitlinien zu beachten:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Jedes Werkzeug sollte protokollieren (durch einfache Verwendung von\u00a0<code>drucken<\/code>\u00a0Anweisungen innerhalb des Werkzeugs\u00a0<code>weiter<\/code>\u00a0Methode) alles, was f\u00fcr die LLM-Maschine n\u00fctzlich sein k\u00f6nnte.\n<ul class=\"wp-block-list\">\n<li>Insbesondere die detaillierte Protokollierung von Ausf\u00fchrungsfehlern w\u00e4re eine gro\u00dfe Hilfe!<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>Hier ist zum Beispiel ein Tool, das Wetterdaten auf der Grundlage von Standort und Datum\/Zeit abruft:<\/p>\n\n\n\n<p>Hier ist zun\u00e4chst eine schlechte Version:<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">importieren datetime\nvon smolagents importieren tool\n\ndef get_weather_report_at_coordinates(coordinates, date_time):\n    <em># Dummy-Funktion, liefert eine Liste von [Temperatur in \u00b0C, Regenrisiko auf einer Skala von 0-1, Wellenh\u00f6he in m]<\/em>\n    return [28.0, 0.35, 0.85]\n\ndef get_coordinates_from_location(location):\n    <em># Gibt Dummy-Koordinaten zur\u00fcck<\/em>\n    return [3.3, -42.0]\n\n@tool\ndef get_weather_api(location: str, date_time: str) -&gt; str:\n    \"\"\"\n    Gibt den Wetterbericht zur\u00fcck.\n\n    Args:\n        location: der Name des Ortes, f\u00fcr den Sie den Wetterbericht w\u00fcnschen.\n        date_time: das Datum und die Uhrzeit, f\u00fcr die Sie den Bericht haben m\u00f6chten.\n    \"\"\"\n    lon, lat = convert_location_to_coordinates(ort)\n    date_time = datetime.strptime(date_time)\n    return str(get_weather_report_at_coordinates((lon, lat), date_time))<\/pre>\n\n\n\n<p>Warum ist das schlecht?<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Es gibt keine genaue Angabe des Formats, das f\u00fcr\u00a0<code>Datum_Zeit<\/code><\/li>\n\n\n\n<li>Es gibt keine Angaben dar\u00fcber, wie der Standort angegeben werden sollte.<\/li>\n\n\n\n<li>Es gibt keinen Protokollierungsmechanismus f\u00fcr explizite Fehlerf\u00e4lle, z. B. wenn der Ort nicht im richtigen Format vorliegt oder die Datumsangabe nicht richtig formatiert ist.<\/li>\n\n\n\n<li>das Ausgabeformat ist schwer zu verstehen<\/li>\n<\/ul>\n\n\n\n<p>Wenn der Werkzeugaufruf fehlschl\u00e4gt, kann die im Speicher protokollierte Fehlerspur dem LLM helfen, das Werkzeug zur\u00fcckzuentwickeln und die Fehler zu beheben. Aber warum sollte man ihm so viel Arbeit aufb\u00fcrden?<\/p>\n\n\n\n<p>Ein besserer Weg, dieses Instrument zu entwickeln, w\u00e4re der folgende gewesen:<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@tool\ndef get_weather_api(location: str, date_time: str) -&gt; str:\n    \"\"\"\n    Gibt den Wetterbericht zur\u00fcck.\n\n    Args:\n        location: der Name des Ortes, f\u00fcr den Sie das Wetter haben m\u00f6chten. Es sollte ein Ortsname sein, gefolgt von einem St\u00e4dtenamen und einem Land, z. B. \"Anchor Point, Taghazout, Marokko\".\n        date_time: das Datum und die Uhrzeit, f\u00fcr die Sie den Bericht w\u00fcnschen, formatiert als '%m\/%d\/%y %H:%M:%S'.\n    \"\"\"\n    lon, lat = convert_location_to_coordinates(location)\n    try:\n        date_time = datetime.strptime(date_time)\n    except Exception as e:\n        raise ValueError(\"Konvertierung von `date_time` in datetime-Format fehlgeschlagen, stellen Sie sicher, dass Sie einen String im Format '%m\/%d\/%y %H:%M:%S' bereitstellen. Vollst\u00e4ndiger Trace:\" + str(e))\n    temperature_celsius, risk_of_rain, wave_height = get_weather_report_at_coordinates((lon, lat), date_time)\n    return f \"Wetterbericht f\u00fcr {Ort}, {Datum_Zeit}: Die Temperatur wird {Temperatur_celsius}\u00b0C betragen, das Regenrisiko ist {Risiko_des_Regens*100:.0f}%, die Wellenh\u00f6he ist {wave_height}m.\"<\/pre>\n\n\n\n<p>Um Ihr LLM zu entlasten, sollten Sie sich generell die Frage stellen: \"Wie einfach w\u00e4re es f\u00fcr mich, wenn ich dumm w\u00e4re und dieses Tool zum ersten Mal benutzen w\u00fcrde, mit diesem Tool zu programmieren und meine eigenen Fehler zu korrigieren?\".<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#give-more-arguments-to-the-agent\" target=\"_blank\" rel=\"noopener\"><\/a>Geben Sie dem Agenten mehr Argumente<\/h3>\n\n\n\n<p>Um Ihrem Agenten neben der einfachen Zeichenkette, die die Aufgabe beschreibt, weitere Objekte zu \u00fcbergeben, k\u00f6nnen Sie die&nbsp;<code>zus\u00e4tzliche_args<\/code>&nbsp;Argument, um jede Art von Objekt zu \u00fcbergeben:<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">von smolagents importieren CodeAgent, HfApiModel\n\nmodel_id = \"meta-llama\/Llama-3.3-70B-Instruct\"\n\nagent = CodeAgent(tools=[], model=HfApiModel(model_id=model_id), add_base_tools=True)\n\nagent.run(\n    \"Warum kennt Mike nicht viele Leute in New York?\",\n    additional_args={\"mp3_sound_file_url\":'https:\/\/huggingface.co\/datasets\/huggingface\/documentation-images\/resolve\/main\/transformers\/recording.mp3'}\n)<\/pre>\n\n\n\n<p>Sie k\u00f6nnen zum Beispiel Folgendes verwenden&nbsp;<code>zus\u00e4tzliche_args<\/code>&nbsp;Argument, um Bilder oder Zeichenketten zu \u00fcbergeben, die Ihr Agent nutzen soll.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#how-to-debug-your-agent\" target=\"_blank\" rel=\"noopener\"><\/a>Wie Sie Ihren Agenten debuggen<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#1-use-a-stronger-llm\" target=\"_blank\" rel=\"noopener\"><\/a>1. Verwenden Sie ein st\u00e4rkeres LLM<\/h3>\n\n\n\n<p>In einem agentenbasierten Arbeitsablauf sind einige der Fehler tats\u00e4chliche Fehler, andere sind der Fehler Ihrer LLM-Engine, die nicht richtig argumentiert. Betrachten Sie zum Beispiel diesen Trace f\u00fcr eine&nbsp;<code>CodeAgent<\/code>&nbsp;that I asked to create a car picture:<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">==================================================================================================== New task ====================================================================================================\nMake me a cool car picture\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 New step \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nAgent is executing the code below: \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nimage_generator(prompt=\"A cool, futuristic sports car with LED headlights, aerodynamic design, and vibrant color, high-res, photorealistic\")\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nLast output from code snippet: \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\/var\/folders\/6m\/9b1tts6d5w960j80wbw9tx3m0000gn\/T\/tmpx09qfsdd\/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png\nStep 1:\n\n- Time taken: 16.35 seconds\n- Input tokens: 1,383\n- Output tokens: 77\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 New step \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nAgent is executing the code below: \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nfinal_answer(\"\/var\/folders\/6m\/9b1tts6d5w960j80wbw9tx3m0000gn\/T\/tmpx09qfsdd\/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png\")\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nPrint outputs:\n\nLast output from code snippet: \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\/var\/folders\/6m\/9b1tts6d5w960j80wbw9tx3m0000gn\/T\/tmpx09qfsdd\/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png\nFinal answer:\n\/var\/folders\/6m\/9b1tts6d5w960j80wbw9tx3m0000gn\/T\/tmpx09qfsdd\/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png<\/pre>\n\n\n\n<p>The user sees, instead of an image being returned, a path being returned to them. It could look like a bug from the system, but actually the agentic system didn\u2019t cause the error: it\u2019s just that the LLM brain did the mistake of not saving the image output into a variable. Thus it cannot access the image again except by leveraging the path that was logged while saving the image, so it returns the path instead of an image.<\/p>\n\n\n\n<p>The first step to debugging your agent is thus \u201cUse a more powerful LLM\u201d. Alternatives like&nbsp;<code>Qwen2\/5-72B-Instruct<\/code>&nbsp;wouldn\u2019t have made that mistake.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#2-provide-more-guidance--more-information\" target=\"_blank\" rel=\"noopener\"><\/a>2. Provide more guidance \/ more information<\/h3>\n\n\n\n<p>You can also use less powerful models, provided you guide them more effectively.<\/p>\n\n\n\n<p>Put yourself in the shoes of your model: if you were the model solving the task, would you struggle with the information available to you (from the system prompt + task formulation + tool description) ?<\/p>\n\n\n\n<p>Would you need some added clarifications?<\/p>\n\n\n\n<p>To provide extra information, we do not recommend to change the system prompt right away: the default system prompt has many adjustments that you do not want to mess up except if you understand the prompt very well. Better ways to guide your LLM engine are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If it \u2018s about the task to solve: add all these details to the task. The task could be 100s of pages long.<\/li>\n\n\n\n<li>If it\u2019s about how to use tools: the description attribute of your tools.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#3-change-the-system-prompt-generally-not-advised\" target=\"_blank\" rel=\"noopener\"><\/a>3. Change the system prompt (generally not advised)<\/h3>\n\n\n\n<p>If above clarifications above are not sufficient, you can change the system prompt.<\/p>\n\n\n\n<p>Let\u2019s see how it works. For example, let us check the default system prompt for the\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.CodeAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">CodeAgent<\/a>\u00a0(below version is shortened by skipping zero-shot examples).<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(agent.system_prompt_template)<\/pre>\n\n\n\n<p>Here is what you get:<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can.\nTo do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.\nTo solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.\n\nAt each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.\nThen in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '&lt;end_code&gt;' sequence.\nDuring each intermediate step, you can use 'print()' to save whatever important information you will then need.\nThese print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.\nIn the end you have to return a final answer using the `final_answer` tool.\n\nHere are a few examples using notional tools:\n---\n{examples}\n\nAbove example were using notional tools that might not exist for you. On top of performing computations in the Python code snippets that you create, you only have access to these tools:\n\n{{tool_descriptions}}\n\n{{managed_agents_descriptions}}\n\nHere are the rules you should always follow to solve your task:\n1. Always provide a 'Thought:' sequence, and a 'Code:\\n```py' sequence ending with '```&lt;end_code&gt;' sequence, else you will fail.\n2. Use only variables that you have defined!\n3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = wiki({'query': \"What is the place where James Bond lives?\"})', but use the arguments directly as in 'answer = wiki(query=\"What is the place where James Bond lives?\")'.\n4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.\n5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.\n6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.\n7. Never create any notional variables in our code, as having these in your logs might derail you from the true variables.\n8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}}\n9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist.\n10. Don't give up! You're in charge of solving the task, not providing directions to solve it.\n\nNow Begin! If you solve the task correctly, you will receive a reward of $1,000,000.<\/pre>\n\n\n\n<p>As you can see, there are placeholders like&nbsp;<code>\"{{tool_descriptions}}\"<\/code>: these will be used upon agent initialization to insert certain automatically generated descriptions of tools or managed agents.<\/p>\n\n\n\n<p>So while you can overwrite this system prompt template by passing your custom prompt as an argument to the&nbsp;<code>system_prompt<\/code>&nbsp;parameter, your new system prompt must contain the following placeholders:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\"{{tool_descriptions}}\"<\/code>\u00a0to insert tool descriptions.<\/li>\n\n\n\n<li><code>\"{{managed_agents_description}}\"<\/code>\u00a0to insert the description for managed agents if there are any.<\/li>\n\n\n\n<li>For\u00a0<code>CodeAgent<\/code>\u00a0only:\u00a0<code>\"{{authorized_imports}}\"<\/code>\u00a0to insert the list of authorized imports.<\/li>\n<\/ul>\n\n\n\n<p>Then you can change the system prompt as follows:<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smolagents.prompts import CODE_SYSTEM_PROMPT\n\nmodified_system_prompt = CODE_SYSTEM_PROMPT + \"\\nHere you go!\" <em># Change the system prompt here<\/em>\n\nagent = CodeAgent(\n    tools=[], \n    model=HfApiModel(), \n    system_prompt=modified_system_prompt\n)<\/pre>\n\n\n\n<p>This also works with the\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.ToolCallingAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">ToolCallingAgent<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents#4-extra-planning\" target=\"_blank\" rel=\"noopener\"><\/a>4. Extra planning<\/h3>\n\n\n\n<p>We provide a model for a supplementary planning step, that an agent can run regularly in-between normal action steps. In this step, there is no tool call, the LLM is simply asked to update a list of facts it knows and to reflect on what steps it should take next based on those facts.<\/p>\n\n\n\n<p>Kopiert<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smolagents import load_tool, CodeAgent, HfApiModel, DuckDuckGoSearchTool\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\n<em># Import tool from Hub<\/em>\nimage_generation_tool = load_tool(\"m-ric\/text-to-image\", trust_remote_code=True)\n\nsearch_tool = DuckDuckGoSearchTool()\n\nagent = CodeAgent(\n    tools=[search_tool],\n    model=HfApiModel(\"Qwen\/Qwen2.5-72B-Instruct\"),\n    planning_interval=3 <em># This is where you activate planning!<\/em>\n)\n\n<em># Run it!<\/em>\nresult = agent.run(\n    \"How long would a cheetah at full speed take to run the length of Pont Alexandre III?\",\n)<\/pre>","protected":false},"excerpt":{"rendered":"<p>There\u2019s a world of difference between building an agent that works and one that doesn\u2019t. How can we build agents that fall into the latter category? In this guide, we\u2019re going to see best practices for building agents. If you\u2019re new to building agents, make sure to first read the\u00a0intro to agents\u00a0and the\u00a0guided tour of&#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"doc_category":[8],"doc_tag":[],"class_list":["post-589","docs","type-docs","status-publish","hentry","doc_category-tutorials"],"year_month":"2026-04","word_count":2268,"total_views":"6124","reactions":{"happy":"2","normal":"1","sad":"1"},"author_info":{"name":"smolagents","author_nicename":"wd-gstargmail-com","author_url":"https:\/\/smolagents.org\/de\/author\/wd-gstargmail-com\/"},"doc_category_info":[{"term_name":"Tutorials","term_url":"https:\/\/smolagents.org\/de\/docs-category\/tutorials\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/docs\/589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/comments?post=589"}],"version-history":[{"count":1,"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/docs\/589\/revisions"}],"predecessor-version":[{"id":590,"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/docs\/589\/revisions\/590"}],"wp:attachment":[{"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/media?parent=589"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/doc_category?post=589"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/smolagents.org\/de\/wp-json\/wp\/v2\/doc_tag?post=589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}