{"id":587,"date":"2025-01-11T15:16:14","date_gmt":"2025-01-11T15:16:14","guid":{"rendered":"https:\/\/smolagents.org\/?post_type=docs&#038;p=587"},"modified":"2025-01-11T15:16:16","modified_gmt":"2025-01-11T15:16:16","password":"","slug":"agents-guided-tour","status":"publish","type":"docs","link":"https:\/\/smolagents.org\/zh_tw\/docs\/agents-guided-tour\/","title":{"rendered":"\u4ee3\u7406\u5546 - \u5c0e\u89bd"},"content":{"rendered":"<p>\u5728\u6b64\u5c0e\u89bd\u4e2d\uff0c\u60a8\u5c07\u5b78\u7fd2\u5982\u4f55\u5efa\u7acb\u4ee3\u7406\u7a0b\u5f0f\u3001\u5982\u4f55\u57f7\u884c\u4ee3\u7406\u7a0b\u5f0f\uff0c\u4ee5\u53ca\u5982\u4f55\u81ea\u8a02\u4ee3\u7406\u7a0b\u5f0f\u4f7f\u5176\u66f4\u9069\u5408\u60a8\u7684\u4f7f\u7528\u60c5\u6cc1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#building-your-agent\" target=\"_blank\" rel=\"noopener\"><\/a>\u5efa\u7acb\u60a8\u7684\u4ee3\u7406<\/h3>\n\n\n\n<p>\u8981\u521d\u59cb\u5316\u6700\u5c0f\u4ee3\u7406\uff0c\u60a8\u81f3\u5c11\u9700\u8981\u9019\u5169\u500b\u53c3\u6578\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>\u6a21\u578b<\/code>, \u4e00\u500b\u6587\u672c\u751f\u6210\u6a21\u578b\u4f86\u70ba\u60a8\u7684\u4ee3\u7406\u63d0\u4f9b\u52d5\u529b - \u56e0\u70ba\u4ee3\u7406\u4e0d\u540c\u65bc\u7c21\u55ae\u7684 LLM\uff0c\u5b83\u662f\u4e00\u500b\u4f7f\u7528 LLM \u4f5c\u70ba\u5f15\u64ce\u7684\u7cfb\u7d71\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5176\u4e2d\u4efb\u4f55\u4e00\u500b\u9078\u9805\uff1a\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.TransformersModel\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u8b8a\u5f62\u91d1\u525b\u6a21\u578b<\/a>\u00a0\u9700\u8981\u4e00\u500b\u9810\u521d\u59cb\u5316\u7684\u00a0<code>\u8b8a\u58d3\u5668<\/code>\u00a0\u7ba1\u9053\u5728\u672c\u6a5f\u4e0a\u57f7\u884c\u63a8\u7406\uff0c\u4f7f\u7528\u00a0<code>\u8b8a\u58d3\u5668<\/code>.<\/li>\n\n\n\n<li><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.HfApiModel\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">HfApiModel<\/a>\u00a0\u5229\u7528\u00a0<code>huggingface_hub.InferenceClient<\/code>\u00a0\u5728\u5f15\u64ce\u84cb\u4e0b\u3002<\/li>\n\n\n\n<li><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.LiteLLMModel\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">LiteLLMM \u6a21\u578b<\/a>\u00a0\u8b93\u60a8\u900f\u904e\u00a0<a href=\"https:\/\/docs.litellm.ai\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">LiteLLM<\/a>!<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>\u5de5\u5177<\/code>,\u6e05\u55ae\u00a0<code>\u5de5\u5177<\/code>\u00a0\u4ee3\u7406\u53ef\u4ee5\u7528\u4f86\u89e3\u6c7a\u4efb\u52d9\u3002\u5b83\u53ef\u4ee5\u662f\u4e00\u500b\u7a7a\u6e05\u55ae\u3002\u60a8\u4e5f\u53ef\u4ee5\u5c07\u9810\u8a2d\u7684\u5de5\u5177\u7bb1\u52a0\u5728\u60a8\u7684\u00a0<code>\u5de5\u5177<\/code>\u00a0\u900f\u904e\u5b9a\u7fa9\u53ef\u9078\u53c3\u6578\u00a0<code>add_base_tools=True<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>\u4e00\u65e6\u60a8\u6709\u4e86\u9019\u5169\u500b\u8ad6\u9ede\u3001\u00a0<code>\u5de5\u5177<\/code>\u00a0\u548c\u00a0<code>\u6a21\u578b<\/code>, \u60a8\u53ef\u4ee5\u5efa\u7acb\u4e00\u500b\u4ee3\u7406\u7a0b\u5f0f\u4e26\u57f7\u884c\u5b83\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u60a8\u60f3\u8981\u7684 LLM\uff0c\u7121\u8ad6\u662f\u900f\u904e\u00a0<a href=\"https:\/\/huggingface.co\/docs\/api-inference\/en\/index\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u64c1\u62b1\u81c9 API<\/a>,\u00a0<a href=\"https:\/\/github.com\/huggingface\/transformers\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u8b8a\u58d3\u5668<\/a>,\u00a0<a href=\"https:\/\/ollama.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">ollama<\/a>\u6216\u00a0<a href=\"https:\/\/www.litellm.ai\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">LiteLLM<\/a>.<\/p>\n\n\n\n<p>\u64c1\u62b1\u81c9 API<\/p>\n\n\n\n<p>\u672c\u5730\u8b8a\u58d3\u5668\u6a21\u578b<\/p>\n\n\n\n<p>OpenAI \u6216\u4eba\u985e API<\/p>\n\n\n\n<p>Ollama<\/p>\n\n\n\n<p>Hugging Face API \u4e0d\u9700\u8981\u4ee4\u724c\u5373\u53ef\u514d\u8cbb\u4f7f\u7528\uff0c\u4f46\u6703\u6709\u901f\u7387\u9650\u5236\u3002<\/p>\n\n\n\n<p>\u82e5\u8981\u4f7f\u7528 PRO \u5e33\u6236\u5b58\u53d6\u9580\u63a7\u6a21\u578b\u6216\u63d0\u9ad8\u8cbb\u7387\u9650\u5236\uff0c\u60a8\u9700\u8981\u8a2d\u5b9a\u74b0\u5883\u8b8a\u6578&nbsp;<code>HF_TOKEN<\/code>&nbsp;\u6216\u901a\u904e&nbsp;<code>\u7b26\u8a18<\/code>&nbsp;\u8b8a\u6578\u521d\u59cb\u5316\u6642&nbsp;<code>HfApiModel<\/code>.<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smolagents import CodeAgent, HfApiModel\n\nmodel_id = \"meta-llama\/Llama-3.3-70B-Instruct\"\n\nmodel = HfApiModel(model_id=model_id, token=\"\")\nagent = CodeAgent(tools=[], model=model, add_base_tools=True)\n\nagent.run(\n    \"Could you give me the 118th number in the Fibonacci sequence?\"\u3001\n)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#codeagent-and-toolcallingagent\" target=\"_blank\" rel=\"noopener\"><\/a>CodeAgent \u548c ToolCallingAgent<\/h4>\n\n\n\n<p>\u7684\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\u662f\u6211\u5011\u7684\u9810\u8a2d\u4ee3\u7406\u7a0b\u5f0f\u3002\u5b83\u6703\u5728\u6bcf\u500b\u6b65\u9a5f\u4e2d\u5beb\u5165\u4e26\u57f7\u884c python \u7a0b\u5f0f\u78bc\u7247\u6bb5\u3002<\/p>\n\n\n\n<p>\u9810\u8a2d\u662f\u5728\u60a8\u7684\u672c\u6a5f\u74b0\u5883\u4e2d\u57f7\u884c\u3002\u9019\u61c9\u8a72\u662f\u5b89\u5168\u7684\uff0c\u56e0\u70ba\u80fd\u88ab\u547c\u53eb\u7684\u51fd\u6578\u53ea\u6709\u60a8\u63d0\u4f9b\u7684\u5de5\u5177 (\u7279\u5225\u662f\u53ea\u6709 Hugging Face \u7684\u5de5\u5177) \u548c\u4e00\u7d44\u9810\u5148\u5b9a\u7fa9\u7684\u5b89\u5168\u51fd\u6578\uff0c\u4f8b\u5982&nbsp;<code>\u5217\u5370<\/code>&nbsp;\u6216\u529f\u80fd\u5f9e&nbsp;<code>\u6578\u5b78<\/code>&nbsp;\u6a21\u7d44\uff0c\u6240\u4ee5\u60a8\u5728\u57f7\u884c\u4e0a\u5df2\u7d93\u53d7\u5230\u9650\u5236\u3002<\/p>\n\n\n\n<p>Python \u89e3\u8b6f\u5668\u4e5f\u4e0d\u5141\u8a31\u5728\u5b89\u5168\u6e05\u55ae\u4e4b\u5916\u7684\u9810\u8a2d\u532f\u5165\uff0c\u6240\u4ee5\u6240\u6709\u6700\u660e\u986f\u7684\u653b\u64ca\u61c9\u8a72\u90fd\u4e0d\u662f\u554f\u984c\u3002\u60a8\u53ef\u4ee5\u5c07\u6388\u6b0a\u7684\u6a21\u7d44\u4ee5\u5b57\u4e32\u7684\u65b9\u5f0f\u50b3\u7d66\u53c3\u6578\u00a0<code>\u984d\u5916\u7684\u6388\u6b0a\u9032\u53e3<\/code>\u00a0\u5728\u521d\u59cb\u5316\u60a8\u7684\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.CodeAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">CodeAgent<\/a>:<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">model = HfApiModel()\nagent = CodeAgent(tools=[], model=model, additional_authorized_imports=['requests', 'bs4'])\nagent.run(\"Could you get me the title of the page at url 'https:\/\/huggingface.co\/blog'?\")<\/pre>\n\n\n\n<p>LLM \u53ef\u4ee5\u7522\u751f\u96a8\u5f8c\u57f7\u884c\u7684\u4efb\u610f\u7a0b\u5f0f\u78bc\uff1a\u8acb\u52ff\u52a0\u5165\u4efb\u4f55\u4e0d\u5b89\u5168\u7684\u532f\u5165\uff01<\/p>\n\n\n\n<p>\u7576\u4efb\u4f55\u7a0b\u5f0f\u78bc\u5617\u8a66\u57f7\u884c\u975e\u6cd5\u64cd\u4f5c\uff0c\u6216\u4ee3\u7406\u7a0b\u5f0f\u7522\u751f\u7684\u7a0b\u5f0f\u78bc\u51fa\u73fe\u4e00\u822c Python \u932f\u8aa4\u6642\uff0c\u57f7\u884c\u5c31\u6703\u505c\u6b62\u3002<\/p>\n\n\n\n<p>\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u00a0<a href=\"https:\/\/e2b.dev\/docs#what-is-e2-b\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">E2B \u4ee3\u78bc\u57f7\u884c\u5668<\/a>\u00a0\u800c\u4e0d\u662f\u672c\u6a5f Python \u89e3\u8b6f\u5668\uff0c\u65b9\u6cd5\u662f\u5148\u4f7f\u7528\u00a0<a href=\"https:\/\/e2b.dev\/dashboard?tab=keys\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u8a2d\u5b9a\u00a0<code>E2B_API_KEY<\/code>\u00a0\u74b0\u5883\u8b8a\u6578<\/a>\u00a0\u7136\u5f8c\u5c07\u00a0<code>use_e2b_executor=True<\/code>\u00a0\u5728\u4ee3\u7406\u521d\u59cb\u5316\u6642\u3002<\/p>\n\n\n\n<p>\u9032\u4e00\u6b65\u77ad\u89e3\u4ee3\u78bc\u57f7\u884c\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/secure_code_execution\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u5728\u672c\u6559\u7a0b\u4e2d<\/a>.<\/p>\n\n\n\n<p>\u6211\u5011\u4e5f\u652f\u63f4\u5ee3\u6cdb\u4f7f\u7528\u7684\u65b9\u5f0f\uff0c\u5c07\u52d5\u4f5c\u66f8\u5beb\u70ba\u985e\u4f3c JSON \u7684 blob\uff1a\u9019\u662f\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.ToolCallingAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u5de5\u5177\u547c\u53eb\u4ee3\u7406<\/a>\uff0c\u5176\u904b\u4f5c\u65b9\u5f0f\u8207\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.CodeAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">CodeAgent<\/a>\u7576\u7136\u6c92\u6709\u00a0<code>\u984d\u5916\u7684\u6388\u6b0a\u9032\u53e3<\/code>\u00a0\u56e0\u70ba\u5b83\u4e0d\u6703\u57f7\u884c\u7a0b\u5f0f\u78bc\uff1a<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5f9e smolagents \u532f\u5165 ToolCallingAgent\n\nagent = ToolCallingAgent(tools=[], model=model)\nagent.run(\"Could you get me the title of the page at url 'https:\/\/huggingface.co\/blog'?\")<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#inspecting-an-agent-run\" target=\"_blank\" rel=\"noopener\"><\/a>\u6aa2\u67e5\u4ee3\u7406\u7a0b\u5f0f\u57f7\u884c<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6709\u7528\u7684\u5c6c\u6027\uff0c\u53ef\u6aa2\u67e5\u904b\u884c\u5f8c\u767c\u751f\u7684\u4e8b\u60c5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>agent.logs<\/code>\u00a0\u5132\u5b58\u4ee3\u7406\u7684\u7cbe\u7d30\u8a18\u9304\u3002\u5728\u4ee3\u7406\u904b\u884c\u7684\u6bcf\u4e00\u6b65\u9a5f\u4e2d\uff0c\u6240\u6709\u5167\u5bb9\u90fd\u6703\u5132\u5b58\u5728\u5b57\u5178\u4e2d\uff0c\u7136\u5f8c\u88ab\u8ffd\u52a0\u5230\u00a0<code>agent.logs<\/code>.<\/li>\n\n\n\n<li>\u904b\u884c\u00a0<code>agent.write_inner_memory_from_logs()<\/code>\u00a0\u5efa\u7acb\u4ee3\u7406\u65e5\u8a8c\u7684\u5167\u90e8\u8a18\u61b6\u9ad4\uff0c\u4f9b LLM \u6aa2\u8996\uff0c\u4f5c\u70ba\u804a\u5929\u8a0a\u606f\u6e05\u55ae\u3002\u6b64\u65b9\u6cd5\u6703\u6aa2\u8996\u65e5\u8a8c\u7684\u6bcf\u500b\u6b65\u9a5f\uff0c\u4e26\u53ea\u5c07\u5176\u611f\u8208\u8da3\u7684\u5167\u5bb9\u5132\u5b58\u70ba\u8a0a\u606f\uff1a\u4f8b\u5982\uff0c\u5b83\u6703\u5c07\u7cfb\u7d71\u63d0\u793a\u548c\u4efb\u52d9\u5206\u5225\u5132\u5b58\u70ba\u4e0d\u540c\u7684\u8a0a\u606f\uff0c\u7136\u5f8c\u6bcf\u4e00\u6b65\u9a5f\u90fd\u6703\u5c07 LLM \u8f38\u51fa\u5132\u5b58\u70ba\u8a0a\u606f\uff0c\u4e26\u5c07\u5de5\u5177\u547c\u53eb\u8f38\u51fa\u5132\u5b58\u70ba\u53e6\u4e00\u500b\u8a0a\u606f\u3002\u5982\u679c\u60a8\u60f3\u8981\u5c0d\u6240\u767c\u751f\u7684\u4e8b\u60c5\u6709\u66f4\u9ad8\u5c64\u6b21\u7684\u6aa2\u8996\uff0c\u8acb\u4f7f\u7528\u9019\u500b\u65b9\u6cd5 - \u4f46\u4e0d\u662f\u6bcf\u500b\u8a18\u9304\u90fd\u6703\u7528\u9019\u500b\u65b9\u6cd5\u4f86\u8a18\u9304\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#tools\" target=\"_blank\" rel=\"noopener\"><\/a>\u5de5\u5177<\/h2>\n\n\n\n<p>\u5de5\u5177\u662f\u4ee3\u7406\u4f7f\u7528\u7684\u539f\u5b50\u51fd\u6578\u3002\u8981\u88ab LLM \u4f7f\u7528\uff0c\u5b83\u9084\u9700\u8981\u4e00\u4e9b\u5c6c\u6027\uff0c\u9019\u4e9b\u5c6c\u6027\u69cb\u6210\u4e86\u5b83\u7684 API\uff0c\u4e26\u5c07\u7528\u4f86\u5411 LLM \u63cf\u8ff0\u5982\u4f55\u547c\u53eb\u6b64\u5de5\u5177\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u540d\u7a31<\/li>\n\n\n\n<li>\u8aaa\u660e<\/li>\n\n\n\n<li>\u8f38\u5165\u985e\u578b\u548c\u8aaa\u660e<\/li>\n\n\n\n<li>\u8f38\u51fa\u985e\u578b<\/li>\n<\/ul>\n\n\n\n<p>\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6aa2\u67e5\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/tools#smolagents.PythonInterpreterTool\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">PythonInterpreterTool<\/a>\uff1a\u5b83\u6709\u4e00\u500b\u540d\u7a31\u3001\u63cf\u8ff0\u3001\u8f38\u5165\u63cf\u8ff0\u3001\u8f38\u51fa\u985e\u578b\u548c\u00a0<code>\u524d\u8a00<\/code>\u00a0\u65b9\u6cd5\u4f86\u57f7\u884c\u52d5\u4f5c\u3002<\/p>\n\n\n\n<p>\u7576\u4ee3\u7406\u7a0b\u5f0f\u521d\u59cb\u5316\u6642\uff0c\u5de5\u5177\u5c6c\u6027\u6703\u88ab\u7528\u4f86\u7522\u751f\u4e00\u500b\u5de5\u5177\u63cf\u8ff0\uff0c\u9019\u500b\u5de5\u5177\u63cf\u8ff0\u6703\u88ab\u690d\u5165\u4ee3\u7406\u7a0b\u5f0f\u7684\u7cfb\u7d71\u63d0\u793a\u4e2d\u3002\u9019\u53ef\u8b93\u4ee3\u7406\u7a0b\u5f0f\u77e5\u9053\u5b83\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u5de5\u5177\uff0c\u4ee5\u53ca\u4f7f\u7528\u7684\u539f\u56e0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#default-toolbox\" target=\"_blank\" rel=\"noopener\"><\/a>\u9810\u8a2d\u5de5\u5177\u7bb1<\/h3>\n\n\n\n<p>Transformers \u96a8\u9644\u4e00\u500b\u9810\u8a2d\u7684\u5de5\u5177\u7bb1\uff0c\u7528\u4f86\u8ce6\u4e88\u4ee3\u7406\u6b0a\u529b\uff0c\u60a8\u53ef\u4ee5\u5728\u521d\u59cb\u5316\u6642\u5c07\u5b83\u52a0\u5165\u4ee3\u7406\uff0c\u4e26\u4f7f\u7528\u53c3\u6578&nbsp;<code>add_base_tools = True<\/code>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DuckDuckGo \u7db2\u8def\u641c\u5c0b*<\/strong>\uff1a\u4f7f\u7528 DuckDuckGo \u700f\u89bd\u5668\u57f7\u884c\u7db2\u8def\u641c\u5c0b\u3002<\/li>\n\n\n\n<li><strong>Python \u7a0b\u5f0f\u78bc\u89e3\u8b6f\u5668<\/strong>\uff1a\u5728\u5b89\u5168\u7684\u74b0\u5883\u4e2d\u57f7\u884c\u60a8\u7684 LLM \u6240\u7522\u751f\u7684 Python \u7a0b\u5f0f\u78bc\u3002\u9019\u500b\u5de5\u5177\u53ea\u6703\u88ab\u52a0\u5165\u5230\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.ToolCallingAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u5de5\u5177\u547c\u53eb\u4ee3\u7406<\/a>\u00a0\u5982\u679c\u60a8\u7528\u00a0<code>add_base_tools=True<\/code>, \u56e0\u70ba\u57fa\u65bc\u4ee3\u78bc\u7684\u4ee3\u7406\u5df2\u7d93\u53ef\u4ee5\u672c\u6a5f\u57f7\u884c Python \u4ee3\u78bc<\/li>\n\n\n\n<li><strong>\u8b04\u5beb\u54e1<\/strong>\uff1a\u5efa\u7acb\u5728 Whisper-Turbo \u4e0a\u7684\u8a9e\u97f3\u8f49\u6587\u5b57\u7ba1\u9053\uff0c\u53ef\u5c07\u97f3\u8a0a\u8f49\u9304\u70ba\u6587\u5b57\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u624b\u52d5\u4f7f\u7528\u5de5\u5177\uff0c\u65b9\u6cd5\u662f\u4f7f\u7528\u5de5\u5177\u7684\u53c3\u6578\u4f86\u547c\u53eb\u5b83\u3002<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smolagents import DuckDuckGoSearchTool\n\nsearch_tool = DuckDuckGoSearchTool()\nprint(search_tool(\"Who's the current president of Russia?\"))<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#create-a-new-tool\" target=\"_blank\" rel=\"noopener\"><\/a>\u5efa\u7acb\u65b0\u5de5\u5177<\/h3>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u91dd\u5c0d Hugging Face \u9810\u8a2d\u5de5\u5177\u672a\u6db5\u84cb\u7684\u4f7f\u7528\u500b\u6848\uff0c\u5efa\u7acb\u81ea\u5df1\u7684\u5de5\u5177\u3002\u4f8b\u5982\uff0c\u8b93\u6211\u5011\u5efa\u7acb\u4e00\u500b\u5de5\u5177\uff0c\u5f9e Hub \u50b3\u56de\u7d66\u5b9a\u4efb\u52d9\u4e0b\u8f09\u6700\u591a\u7684\u6a21\u578b\u3002<\/p>\n\n\n\n<p>\u60a8\u5c07\u5f9e\u4e0b\u9762\u7684\u7a0b\u5f0f\u78bc\u958b\u59cb\u3002<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5f9e huggingface_hub \u532f\u5165 list_models\n\n\u4efb\u52d9 = \u300c\u6587\u5b57\u5206\u985e\u300d\n\nmost_downloaded_model = next(iter(list_models(filter=task, sort=\"downloads\",direction=-1)))\nprint(most_downloaded_model.id)<\/pre>\n\n\n\n<p>\u9019\u4e9b\u7a0b\u5f0f\u78bc\u53ef\u4ee5\u5feb\u901f\u8f49\u63db\u6210\u5de5\u5177\uff0c\u53ea\u8981\u5c07\u5b83\u5305\u88dd\u6210\u51fd\u5f0f\uff0c\u4e26\u52a0\u5165\u00a0<code>\u5de5\u5177<\/code>\u00a0\u88dd\u98fe\u5668\uff1a\u9019\u4e0d\u662f\u5efa\u7acb\u5de5\u5177\u7684\u552f\u4e00\u65b9\u6cd5\uff1a\u60a8\u53ef\u4ee5\u76f4\u63a5\u5c07\u5b83\u5b9a\u7fa9\u70ba\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/tools#smolagents.Tool\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u5de5\u5177<\/a>\uff0c\u8b93\u60a8\u6709\u66f4\u591a\u5f48\u6027\uff0c\u4f8b\u5982\u53ef\u4ee5\u521d\u59cb\u5316\u91cd\u985e\u5c6c\u6027\u3002<\/p>\n\n\n\n<p>\u8b93\u6211\u5011\u770b\u770b\u9019\u5169\u500b\u9078\u9805\u662f\u5982\u4f55\u904b\u4f5c\u7684\uff1a<\/p>\n\n\n\n<p>\u4f7f\u7528 @tool \u4f86\u88dd\u98fe\u51fd\u6578<\/p>\n\n\n\n<p>\u5b50\u985e\u5de5\u5177<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5f9e smolagents \u532f\u5165\u5de5\u5177\n\n@tool\ndef model_download_tool(task: str) -&gt; str\uff1a\n    \"\"\"\n    \u9019\u662f\u4e00\u500b\u5de5\u5177\uff0c\u7528\u4f86\u56de\u50b3 Hugging Face Hub \u4e0a\u6307\u5b9a\u4efb\u52d9\u6700\u5e38\u4e0b\u8f09\u7684\u6a21\u578b\u3002\n    \u5b83\u6703\u8fd4\u56de\u6aa2\u67e5\u9ede\u7684\u540d\u7a31\u3002\n\n    Args\uff1a\n        \u4efb\u52d9\uff1a\u8981\u53d6\u5f97\u4e0b\u8f09\u6b21\u6578\u7684\u4efb\u52d9\u3002\n    \"\"\"\n    most_downloaded_model = next(iter(list_models(filter=task, sort=\"downloads\", direction=-1)))\n    return most_downloaded_model.id<\/pre>\n\n\n\n<p>\u529f\u80fd\u9700\u6c42\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6e05\u6670\u7684\u540d\u7a31\u3002\u9019\u500b\u540d\u7a31\u61c9\u8a72\u8db3\u4ee5\u63cf\u8ff0\u9019\u500b\u5de5\u5177\u7684\u529f\u80fd\uff0c\u4ee5\u5354\u52a9 LLM \u8166\u90e8\u70ba\u4ee3\u7406\u7a0b\u5f0f\u63d0\u4f9b\u52d5\u529b\u3002\u7531\u65bc\u9019\u500b\u5de5\u5177\u6703\u56de\u50b3\u4e00\u500b\u4efb\u52d9\u4e2d\u4e0b\u8f09\u6b21\u6578\u6700\u591a\u7684\u6a21\u578b\uff0c\u6240\u4ee5\u6211\u5011\u5c07\u5b83\u547d\u540d\u70ba\u00a0<code>\u6a21\u578b\u4e0b\u8f09\u5de5\u5177<\/code>.<\/li>\n\n\n\n<li>\u8f38\u5165\u548c\u8f38\u51fa\u7684\u985e\u578b\u63d0\u793a<\/li>\n\n\n\n<li>\u63cf\u8ff0\uff0c\u5176\u4e2d\u5305\u62ec\u300cArgs:\u300d\u90e8\u5206\uff0c\u63cf\u8ff0\u6bcf\u500b\u53c3\u6578\uff08\u9019\u6b21\u6c92\u6709\u985e\u578b\u6307\u793a\uff0c\u6703\u5f9e\u985e\u578b\u63d0\u793a\u4e2d\u53d6\u5f97\uff09\u3002\u8207\u5de5\u5177\u540d\u7a31\u4e00\u6a23\uff0c\u6b64\u63cf\u8ff0\u662f\u70ba\u60a8\u7684\u4ee3\u7406\u7a0b\u5f0f\u63d0\u4f9b\u52d5\u529b\u7684 LLM \u7684\u8aaa\u660e\u624b\u518a\uff0c\u56e0\u6b64\u8acb\u52ff\u5ffd\u7565\u3002\u6240\u6709\u9019\u4e9b\u5143\u7d20\u90fd\u6703\u5728\u521d\u59cb\u5316\u6642\u81ea\u52d5\u7d0d\u5165\u4ee3\u7406\u7a0b\u5f0f\u7684\u7cfb\u7d71\u63d0\u793a\u4e2d\uff1a\u56e0\u6b64\u8acb\u76e1\u53ef\u80fd\u8b93\u5b83\u5011\u6e05\u695a\u660e\u77ad\uff01<\/li>\n<\/ul>\n\n\n\n<p>\u6b64\u5b9a\u7fa9\u683c\u5f0f\u8207\u5728\u00a0<code>\u5957\u7528\u804a\u5929\u7bc4\u672c<\/code>\uff0c\u552f\u4e00\u7684\u5dee\u5225\u662f\u589e\u52a0\u4e86\u00a0<code>\u5de5\u5177<\/code>\u00a0\u88dd\u98fe\u5668\uff1a\u8a73\u7d30\u95b1\u8b80\u6211\u5011\u7684\u5de5\u5177\u4f7f\u7528 API\u00a0<a href=\"https:\/\/huggingface.co\/blog\/unified-tool-use#passing-tools-to-a-chat-template\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u9019\u88e1<\/a>.<\/p>\n\n\n\n<p>\u4e4b\u5f8c\u60a8\u5c31\u53ef\u4ee5\u76f4\u63a5\u521d\u59cb\u5316\u60a8\u7684\u4ee3\u7406\u7a0b\u5f0f\uff1a<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smolagents import CodeAgent, HfApiModel\nagent = CodeAgent(tools=[model_download_tool], model=HfApiModel())\nagent.run(\n    \"Can you give me the name of the model that has the most downloads in the 'text-to-video' task on the Hugging Face Hub?\" \"\u60a8\u80fd\u544a\u8a34\u6211\u5728\u62b1\u62b1\u81c9\u6a1e\u7d10\u7684\u300c\u6587\u5b57\u8f49\u5f71\u7247\u300d\u4efb\u52d9\u4e2d\uff0c\u4e0b\u8f09\u6b21\u6578\u6700\u591a\u7684\u6a21\u578b\u540d\u7a31\u55ce\uff1f\n)<\/pre>\n\n\n\n<p>\u60a8\u6703\u5f97\u5230\u4ee5\u4e0b\u8a18\u9304\uff1a<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\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 run \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 \u2502\n\n\u2502 Hugging Face Hub \u4e0a\u7684\u4efb\u52d9\uff1f                                                            \u2502\n\u2502 \u2502\n\u2570\u2500 HfApiModel - Qwen\/Qwen2.5-Coder-32B-Instruct \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 \u6b65\u9a5f 0 \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\u256d\u2500 \u57f7\u884c\u6b64\u7a0b\u5f0f\u78bc\uff1a\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 1 model_name = model_download_tool(task=\"text-to-video\") \u2502 \u2502 2 print(model_name)\n\u2502 2 print(model_name) \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\u57f7\u884c\u8a18\u9304\uff1a\nByteDance\/AnimateDiff-Lightning\n\n\u8f38\u51fa\uff1a\u7121\n[Step 0: Duration 0.27 seconds| Input tokens: 2,069 | Output tokens: 60] [\u6b65\u9a5f 0\uff1a\u6301\u7e8c\u6642\u9593 0.27 \u79d2| \u8f38\u5165\u4ee3\u5e63\uff1a2,069 | \u8f38\u51fa\u4ee3\u5e63\uff1a60\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501 \u6b65\u9a5f 1 \u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\u256d\u2500\u57f7\u884c\u9019\u6bb5\u7a0b\u5f0f\u78bc\uff1a\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 1 final_answer(\"ByteDance\/AnimateDiff-Lightning\")\u2502\u3002\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\nOut - \u6700\u7d42\u7b54\u6848\uff1aByteDance\/AnimateDiff-Lightning\n[Step 1: Duration 0.10 seconds| Input tokens: 4,288 | Output tokens: 148] [\u6b65\u9a5f 1: \u6642\u9593 0.10 \u79d2| \u8f38\u5165\u7b26\u865f\uff1a4,288 | \u8f38\u51fa\u7b26\u865f\uff1a148\nOut[20]: \"ByteDance\/AnimateDiff-Lightning<\/pre>\n\n\n\n<p>\u95b1\u8b80\u66f4\u591a\u95dc\u65bc\u5de5\u5177\u7684\u8cc7\u8a0a\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/tools#what-is-a-tool-and-how-to-build-one\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u5c08\u7528\u6559\u5b78<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#multi-agents\" target=\"_blank\" rel=\"noopener\"><\/a>\u591a\u91cd\u4ee3\u7406<\/h2>\n\n\n\n<p>\u591a\u4ee3\u7406\u7cfb\u7d71\u5df2\u88ab\u5f15\u5165\u5fae\u8edf\u7684\u6846\u67b6\u00a0<a href=\"https:\/\/huggingface.co\/papers\/2308.08155\" target=\"_blank\" rel=\"noopener\">Aut<\/a><a href=\"https:\/\/huggingface.co\/papers\/2308.08155\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">o<\/a><a href=\"https:\/\/huggingface.co\/papers\/2308.08155\" target=\"_blank\" rel=\"noopener\">\u57fa\u56e0<\/a>.<\/p>\n\n\n\n<p>\u5728\u9019\u985e\u578b\u7684\u67b6\u69cb\u4e2d\uff0c\u60a8\u6709\u6578\u500b\u4ee3\u7406\u5171\u540c\u89e3\u6c7a\u60a8\u7684\u4efb\u52d9\uff0c\u800c\u4e0d\u662f\u53ea\u6709\u4e00\u500b\u4ee3\u7406\u3002\u6839\u64da\u7d93\u9a57\uff0c\u5b83\u5728\u5927\u591a\u6578\u7684\u57fa\u6e96\u4e0a\u90fd\u6709\u66f4\u597d\u7684\u6548\u80fd\u3002\u6548\u80fd\u8f03\u4f73\u7684\u539f\u56e0\u5728\u6982\u5ff5\u4e0a\u5f88\u7c21\u55ae\uff1a\u5c0d\u65bc\u8a31\u591a\u4efb\u52d9\u800c\u8a00\uff0c\u8207\u5176\u4f7f\u7528\u842c\u80fd\u7cfb\u7d71\uff0c\u60a8\u66f4\u9858\u610f\u5c08\u7cbe\u65bc\u5b50\u4efb\u52d9\u4e0a\u7684\u55ae\u5143\u3002\u5728\u6b64\uff0c\u8b93\u4ee3\u7406\u64c1\u6709\u7368\u7acb\u7684\u5de5\u5177\u96c6\u548c\u8a18\u61b6\u9ad4\uff0c\u53ef\u4ee5\u9054\u5230\u6709\u6548\u7387\u7684\u5c08\u696d\u5316\u3002\u4f8b\u5982\uff0c\u70ba\u4ec0\u9ebc\u8981\u5728\u7a0b\u5f0f\u78bc\u7522\u751f\u4ee3\u7406\u7684\u8a18\u61b6\u9ad4\u4e2d\u586b\u6eff\u7db2\u9801\u641c\u5c0b\u4ee3\u7406\u6240\u700f\u89bd\u7684\u6240\u6709\u7db2\u9801\u5167\u5bb9\uff1f\u6700\u597d\u5c07\u5b83\u5011\u5206\u958b\u3002<\/p>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>smolagents<\/code>.<\/p>\n\n\n\n<p>\u70ba\u6b64\uff0c\u8acb\u5c07\u4ee3\u7406\u5c01\u88dd\u5728\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/agents#smolagents.ManagedAgent\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">ManagedAgent<\/a>\u00a0\u7269\u4ef6\u3002\u6b64\u7269\u4ef6\u9700\u8981\u53c3\u6578\u00a0<code>\u4ee3\u7406<\/code>,\u00a0<code>\u59d3\u540d<\/code>\u548c\u4e00\u500b\u00a0<code>\u63cf\u8ff0<\/code>\uff0c\u7136\u5f8c\u5d4c\u5165\u7ba1\u7406\u54e1\u4ee3\u7406\u7684\u7cfb\u7d71\u63d0\u793a\u4e2d\uff0c\u8b93\u5b83\u77e5\u9053\u5982\u4f55\u547c\u53eb\u6b64\u7ba1\u7406\u4ee3\u7406\uff0c\u5c31\u50cf\u6211\u5011\u5c0d\u5de5\u5177\u6240\u505a\u7684\u4e00\u6a23\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u500b\u88fd\u4f5c\u4ee3\u7406\u7a0b\u5f0f\u7684\u7bc4\u4f8b\uff0c\u9019\u500b\u4ee3\u7406\u7a0b\u5f0f\u4f7f\u7528\u6211\u5011\u7684\u00a0<a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/tools#smolagents.DuckDuckGoSearchTool\" target=\"_blank\" rel=\"noopener\">\u9d28\u5b50<\/a><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/tools#smolagents.DuckDuckGoSearchTool\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">k<\/a><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/v1.2.2\/en\/reference\/tools#smolagents.DuckDuckGoSearchTool\" target=\"_blank\" rel=\"noopener\">GoSearchTool<\/a>:<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, ManagedAgent\n\nmodel = HfApiModel()\n\nweb_agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)\n\nmanaged_web_agent = ManagedAgent(\n    agent=web_agent\u3001\n    name=\"web_search\"\u3001\n    description=\"\u70ba\u60a8\u57f7\u884c\u7db2\u8def\u641c\u5c0b\u3002\u5c07\u60a8\u7684\u67e5\u8a62\u4f5c\u70ba\u53c3\u6578\u7d66\u5b83\"\u3002\n)\n\nmanager_agent = CodeAgent(\n    tools=[], model=model, managed_agents=[managed_web_agent]\n)\n\nmanager_agent.run(\"Who is the CEO of Hugging Face?\")<\/pre>\n\n\n\n<p>\u6709\u95dc\u9ad8\u6548\u7387\u591a\u6a5f\u9ad4\u5be6\u4f5c\u7684\u6df1\u5165\u7bc4\u4f8b\uff0c\u8acb\u53c3\u95b1\u00a0<a href=\"https:\/\/huggingface.co\/blog\/beating-gaia\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u6211\u5011\u5982\u4f55\u5c07\u6211\u5011\u7684\u591a\u6a5f\u5668\u4eba\u7cfb\u7d71\u63a8\u5411 GAIA \u6392\u884c\u699c\u7684\u9802\u7aef<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#talk-with-your-agent-and-visualize-its-thoughts-in-a-cool-gradio-interface\" target=\"_blank\" rel=\"noopener\"><\/a>\u5728\u9177\u70ab\u7684 Gradio \u4ecb\u9762\u4e2d\u8207\u60a8\u7684\u4ee3\u7406\u4ea4\u8ac7\uff0c\u4e26\u8996\u89ba\u5316\u5176\u60f3\u6cd5<\/h2>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>GradioUI<\/code>&nbsp;\u4ee5\u4e92\u52d5\u65b9\u5f0f\u5411\u60a8\u7684\u4ee3\u7406\u63d0\u4ea4\u4efb\u52d9\uff0c\u4e26\u89c0\u5bdf\u5b83\u7684\u601d\u8003\u548c\u57f7\u884c\u904e\u7a0b\uff0c\u4ee5\u4e0b\u662f\u4e00\u500b\u7bc4\u4f8b\uff1a<\/p>\n\n\n\n<p>\u8907\u88fd<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5f9e smolagents import (\n    load_tool\u3001\n    CodeAgent\u3001\n    HfApiModel\u3001\n    GradioUI\n)\n\n<em># \u5f9e Hub \u532f\u5165\u5de5\u5177<\/em>\nimage_generation_tool = load_tool(\"m-ric\/text-to-image\")\n\nmodel = HfApiModel(model_id)\n\n<em># \u4f7f\u7528\u5f71\u50cf\u7522\u751f\u5de5\u5177\u521d\u59cb\u5316\u4ee3\u7406\u7a0b\u5f0f<\/em>\nagent = CodeAgent(tools=[image_generation_tool], model=model)\n\nGradioUI(agent).launch()<\/pre>\n\n\n\n<p>\u5728\u5f15\u64ce\u84cb\u4e0b\uff0c\u7576\u4f7f\u7528\u8005\u8f38\u5165\u65b0\u7684\u7b54\u6848\u6642\uff0c\u4ee3\u7406\u7a0b\u5f0f\u6703\u4ee5\u4e0b\u5217\u65b9\u5f0f\u555f\u52d5&nbsp;<code>agent.run(user_request, reset=False)<\/code>.......\u3002&nbsp;<code>\u91cd\u8a2d=\u5047<\/code>&nbsp;flag \u8868\u793a\u4ee3\u7406\u7a0b\u5f0f\u7684\u8a18\u61b6\u9ad4\u5728\u555f\u52d5\u9019\u9805\u65b0\u4efb\u52d9\u524d\u4e0d\u6703\u88ab\u5237\u65b0\uff0c\u9019\u53ef\u8b93\u5c0d\u8a71\u7e7c\u7e8c\u9032\u884c\u3002<\/p>\n\n\n\n<p>\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6b64&nbsp;<code>\u91cd\u8a2d=\u5047<\/code>&nbsp;\u8ad6\u9ede\uff0c\u8b93\u5c0d\u8a71\u5728\u4efb\u4f55\u5176\u4ed6\u4ee3\u7406\u61c9\u7528\u7a0b\u5f0f\u4e2d\u6301\u7e8c\u9032\u884c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/guided_tour#next-steps\" target=\"_blank\" rel=\"noopener\"><\/a>\u63a5\u4e0b\u4f86\u7684\u6b65\u9a5f<\/h2>\n\n\n\n<p>\u5982\u9700\u66f4\u6df1\u5165\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u8acb\u53c3\u95b1\u6211\u5011\u7684\u6559\u5b78\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/secure_code_execution\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u89e3\u91cb\u6211\u5011\u7684\u4ee3\u78bc\u4ee3\u7406\u5982\u4f55\u904b\u4f5c<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u672c\u6307\u5357\u8aaa\u660e\u5982\u4f55\u5efa\u7acb\u826f\u597d\u7684\u4ee3\u7406\u5546<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/huggingface.co\/docs\/smolagents\/tutorials\/building_good_agents\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">\u5de5\u5177\u4f7f\u7528\u6df1\u5165\u6307\u5357<\/a>.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>In this guided visit, you will learn how to build an agent, how to run it, and how to customize it to make it work better for your use-case. Building your agent To initialize a minimal agent, you need at least these two arguments: Once you have these two arguments,\u00a0tools\u00a0and\u00a0model, you can create an agent&#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":[7],"doc_tag":[],"class_list":["post-587","docs","type-docs","status-publish","hentry","doc_category-get-started"],"year_month":"2026-04","word_count":1967,"total_views":"5542","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"smolagents","author_nicename":"wd-gstargmail-com","author_url":"https:\/\/smolagents.org\/zh_tw\/author\/wd-gstargmail-com\/"},"doc_category_info":[{"term_name":"Get started","term_url":"https:\/\/smolagents.org\/zh_tw\/docs-category\/get-started\/"}],"doc_tag_info":[],"_links":{"self":[{"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/docs\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/comments?post=587"}],"version-history":[{"count":1,"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/docs\/587\/revisions"}],"predecessor-version":[{"id":588,"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/docs\/587\/revisions\/588"}],"wp:attachment":[{"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/doc_category?post=587"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/smolagents.org\/zh_tw\/wp-json\/wp\/v2\/doc_tag?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}