Spaces:
Running
Running
<!--Copyright 2024 The HuggingFace Team. All rights reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
specific language governing permissions and limitations under the License. | |
โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | |
rendered properly in your Markdown viewer. | |
--> | |
# ๆๅปบๅฅฝ็จ็ agent | |
[[open-in-colab]] | |
่ฝ่ฏๅฅฝๅทฅไฝ็ agent ๅไธ่ฝๅทฅไฝ็ agent ไน้ด๏ผๆๅคฉๅฃคไนๅซใ | |
ๆไปฌๆไนๆ ทๆ่ฝๆๅปบๅบๅฑไบๅ่ ็ agent ๅข๏ผ | |
ๅจๆฌๆๅไธญ๏ผๆไปฌๅฐ็ๅฐๆๅปบ agent ็ๆไฝณๅฎ่ทตใ | |
> [!TIP] | |
> ๅฆๆไฝ ๆฏ agent ๆๅปบ็ๆฐๆ๏ผ่ฏท็กฎไฟ้ฆๅ ้ ่ฏป [agent ไป็ป](../conceptual_guides/intro_agents) ๅ [smolagents ๅฏผ่ง](../guided_tour)ใ | |
### ๆๅฅฝ็ agent ็ณป็ปๆฏๆ็ฎๅ็๏ผๅฐฝๅฏ่ฝ็ฎๅๅทฅไฝๆต | |
ๅจไฝ ็ๅทฅไฝๆตไธญ่ตไบ LLM ไธไบ่ชไธปๆ๏ผไผๅผๅ ฅไธไบ้่ฏฏ้ฃ้ฉใ | |
็ป่ฟ่ฏๅฅฝ็ผ็จ็ agent ็ณป็ป๏ผ้ๅธธๅ ทๆ่ฏๅฅฝ็้่ฏฏๆฅๅฟ่ฎฐๅฝๅ้่ฏๆบๅถ๏ผๅ ๆญค LLM ๅผๆๆๆบไผ่ชๆ็บ ้ใไฝไธบไบๆๅคง้ๅบฆๅฐ้ไฝ LLM ้่ฏฏ็้ฃ้ฉ๏ผไฝ ๅบ่ฏฅ็ฎๅไฝ ็ๅทฅไฝๆต๏ผ | |
่ฎฉๆไปฌๅ้กพไธไธ [agent ไป็ป](../conceptual_guides/intro_agents) ไธญ็ไพๅญ๏ผไธไธชไธบๅฒๆตชๆ ่กๅ ฌๅธๅ็ญ็จๆทๅจ่ฏข็ๆบๅจไบบใ | |
ไธๅ ถ่ฎฉ agent ๆฏๆฌก่ขซ้ฎๅๆฐ็ๅฒๆตชๅฐ็นๆถ๏ผ้ฝๅๅซ่ฐ็จ "ๆ ่ก่ท็ฆป API" ๅ "ๅคฉๆฐ API"๏ผไฝ ๅฏไปฅๅชๅๅปบไธไธช็ปไธ็ๅทฅๅ ท "return_spot_information"๏ผไธไธชๅๆถ่ฐ็จ่ฟไธคไธช API๏ผๅนถ่ฟๅๅฎไปฌ่ฟๆฅ่พๅบ็ๅฝๆฐใ | |
่ฟๅฏไปฅ้ไฝๆๆฌใๅปถ่ฟๅ้่ฏฏ้ฃ้ฉ๏ผ | |
ไธป่ฆ็ๆๅฏผๅๅๆฏ๏ผๅฐฝๅฏ่ฝๅๅฐ LLM ่ฐ็จ็ๆฌกๆฐใ | |
่ฟๅฏไปฅๅธฆๆฅไธไบๅฏๅ๏ผ | |
- ๅฐฝๅฏ่ฝๆไธคไธชๅทฅๅ ทๅๅนถไธบไธไธช๏ผๅฐฑๅๆไปฌไธคไธช API ็ไพๅญใ | |
- ๅฐฝๅฏ่ฝๅบไบ็กฎๅฎๆงๅฝๆฐ๏ผ่ไธๆฏ agent ๅณ็ญ๏ผๆฅๅฎ็ฐ้ป่พใ | |
### ๆนๅๆตๅ LLM ๅผๆ็ไฟกๆฏๆต | |
่ฎฐไฝ๏ผไฝ ็ LLM ๅผๆๅฐฑๅไธไธช ~ๆบ่ฝ~ ๆบๅจไบบ๏ผ่ขซๅ ณๅจไธไธชๆฟ้ด้๏ผไธๅค็ๅฏไธ็ไบคๆตๆนๅผๆฏ้่ฟ้จ็ผไผ ้็็บธๆกใ | |
ๅฆๆไฝ ๆฒกๆๆ็กฎๅฐๅฐไฟกๆฏๆพๅ ฅๅ ถๆ็คบไธญ๏ผๅฎๅฐไธ็ฅ้ๅ็็ไปปไฝไบๆ ใ | |
ๆไปฅ้ฆๅ ่ฆ่ฎฉไฝ ็ไปปๅก้ๅธธๆธ ๆฐ๏ผ | |
็ฑไบ agent ็ฑ LLM ้ฉฑๅจ๏ผไปปๅก่กจ่ฟฐ็ๅพฎๅฐๅๅๅฏ่ฝไผไบง็ๅฎๅ จไธๅ็็ปๆใ | |
็ถๅ๏ผๆนๅๅทฅๅ ทไฝฟ็จไธญๆตๅ agent ็ไฟกๆฏๆตใ | |
้่ฆ้ตๅพช็ๅ ทไฝๆๅ๏ผ | |
- ๆฏไธชๅทฅๅ ท้ฝๅบ่ฏฅ่ฎฐๅฝ๏ผๅช้ๅจๅทฅๅ ท็ `forward` ๆนๆณไธญไฝฟ็จ `print` ่ฏญๅฅ๏ผๅฏน LLM ๅผๆๅฏ่ฝๆ็จ็ๆๆไฟกๆฏใ | |
- ็นๅซๆฏ๏ผ่ฎฐๅฝๅทฅๅ ทๆง่ก้่ฏฏ็่ฏฆ็ปไฟกๆฏไผๅพๆๅธฎๅฉ๏ผ | |
ไพๅฆ๏ผ่ฟ้ๆไธไธชๆ นๆฎไฝ็ฝฎๅๆฅๆๆถ้ดๆฃ็ดขๅคฉๆฐๆฐๆฎ็ๅทฅๅ ท๏ผ | |
้ฆๅ ๏ผ่ฟๆฏไธไธช็ณ็ณ็็ๆฌ๏ผ | |
```python | |
import datetime | |
from smolagents import tool | |
def get_weather_report_at_coordinates(coordinates, date_time): | |
# ่ๆๅฝๆฐ๏ผ่ฟๅ [ๆธฉๅบฆ๏ผยฐC๏ผ๏ผ้้จ้ฃ้ฉ๏ผ0-1๏ผ๏ผๆตช้ซ๏ผm๏ผ] | |
return [28.0, 0.35, 0.85] | |
def get_coordinates_from_location(location): | |
# ่ฟๅ่ๆๅๆ | |
return [3.3, -42.0] | |
@tool | |
def get_weather_api(location: str, date_time: str) -> str: | |
""" | |
Returns the weather report. | |
Args: | |
location: the name of the place that you want the weather for. | |
date_time: the date and time for which you want the report. | |
""" | |
lon, lat = convert_location_to_coordinates(location) | |
date_time = datetime.strptime(date_time) | |
return str(get_weather_report_at_coordinates((lon, lat), date_time)) | |
``` | |
ไธบไปไนๅฎไธๅฅฝ๏ผ | |
- ๆฒกๆ่ฏดๆ `date_time` ๅบ่ฏฅไฝฟ็จ็ๆ ผๅผ | |
- ๆฒกๆ่ฏดๆไฝ็ฝฎๅบ่ฏฅๅฆไฝๆๅฎ | |
- ๆฒกๆ่ฎฐๅฝๆบๅถๆฅๅค็ๆ็กฎ็ๆฅ้ๆ ๅต๏ผๅฆไฝ็ฝฎๆ ผๅผไธๆญฃ็กฎๆ date_time ๆ ผๅผไธๆญฃ็กฎ | |
- ่พๅบๆ ผๅผ้พไปฅ็่งฃ | |
ๅฆๆๅทฅๅ ท่ฐ็จๅคฑ่ดฅ๏ผๅ ๅญไธญ่ฎฐๅฝ็้่ฏฏ่ท่ธช๏ผๅฏไปฅๅธฎๅฉ LLM ้ๅๅทฅ็จๅทฅๅ ทๆฅไฟฎๅค้่ฏฏใไฝไธบไปไน่ฆ่ฎฉๅฎๅ่ฟไนๅค็น้็ๅทฅไฝๅข๏ผ | |
ๆๅปบ่ฟไธชๅทฅๅ ท็ๆดๅฅฝๆนๅผๅฆไธ๏ผ | |
```python | |
@tool | |
def get_weather_api(location: str, date_time: str) -> str: | |
""" | |
Returns the weather report. | |
Args: | |
location: the name of the place that you want the weather for. Should be a place name, followed by possibly a city name, then a country, like "Anchor Point, Taghazout, Morocco". | |
date_time: the date and time for which you want the report, formatted as '%m/%d/%y %H:%M:%S'. | |
""" | |
lon, lat = convert_location_to_coordinates(location) | |
try: | |
date_time = datetime.strptime(date_time) | |
except Exception as e: | |
raise ValueError("Conversion of `date_time` to datetime format failed, make sure to provide a string in format '%m/%d/%y %H:%M:%S'. Full trace:" + str(e)) | |
temperature_celsius, risk_of_rain, wave_height = get_weather_report_at_coordinates((lon, lat), date_time) | |
return f"Weather report for {location}, {date_time}: Temperature will be {temperature_celsius}ยฐC, risk of rain is {risk_of_rain*100:.0f}%, wave height is {wave_height}m." | |
``` | |
ไธ่ฌๆฅ่ฏด๏ผไธบไบๅ่ฝป LLM ็่ดๆ ๏ผ่ฆ้ฎ่ชๅทฑ็ๅฅฝ้ฎ้ขๆฏ๏ผ"ๅฆๆๆๆฏไธไธช็ฌฌไธๆฌกไฝฟ็จ่ฟไธชๅทฅๅ ท็ๅป็๏ผไฝฟ็จ่ฟไธชๅทฅๅ ท็ผ็จๅนถ็บ ๆญฃ่ชๅทฑ็้่ฏฏๆๅคๅฎนๆ๏ผ"ใ | |
### ็ป agent ๆดๅคๅๆฐ | |
้คไบ็ฎๅ็ไปปๅกๆ่ฟฐๅญ็ฌฆไธฒๅค๏ผไฝ ่ฟๅฏไปฅไฝฟ็จ `additional_args` ๅๆฐไผ ้ไปปไฝ็ฑปๅ็ๅฏน่ฑก๏ผ | |
```py | |
from smolagents import CodeAgent, HfApiModel | |
model_id = "meta-llama/Llama-3.3-70B-Instruct" | |
agent = CodeAgent(tools=[], model=HfApiModel(model_id=model_id), add_base_tools=True) | |
agent.run( | |
"Why does Mike not know many people in New York?", | |
additional_args={"mp3_sound_file_url":'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/recording.mp3'} | |
) | |
``` | |
ไพๅฆ๏ผไฝ ๅฏไปฅไฝฟ็จ่ฟไธช `additional_args` ๅๆฐไผ ้ไฝ ๅธๆ agent ๅฉ็จ็ๅพๅๆๅญ็ฌฆไธฒใ | |
## ๅฆไฝ่ฐ่ฏไฝ ็ agent | |
### 1. ไฝฟ็จๆดๅผบๅคง็ LLM | |
ๅจ agent ๅทฅไฝๆตไธญ๏ผๆไบ้่ฏฏๆฏๅฎ้ ้่ฏฏ๏ผๆไบๅๆฏไฝ ็ LLM ๅผๆๆฒกๆๆญฃ็กฎๆจ็็็ปๆใ | |
ไพๅฆ๏ผๅ่่ฟไธชๆ่ฆๆฑๅๅปบไธไธชๆฑฝ่ฝฆๅพ็็ `CodeAgent` ็่ฟ่ก่ฎฐๅฝ๏ผ | |
```text | |
==================================================================================================== New task ==================================================================================================== | |
Make me a cool car picture | |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ New step โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
Agent is executing the code below: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
image_generator(prompt="A cool, futuristic sports car with LED headlights, aerodynamic design, and vibrant color, high-res, photorealistic") | |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
Last output from code snippet: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png | |
Step 1: | |
- Time taken: 16.35 seconds | |
- Input tokens: 1,383 | |
- Output tokens: 77 | |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ New step โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
Agent is executing the code below: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
final_answer("/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png") | |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
Print outputs: | |
Last output from code snippet: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png | |
Final answer: | |
/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmpx09qfsdd/652f0007-3ee9-44e2-94ac-90dae6bb89a4.png | |
``` | |
็จๆท็ๅฐ็ๆฏ่ฟๅไบไธไธช่ทฏๅพ๏ผ่ไธๆฏๅพๅใ | |
่ฟ็่ตทๆฅๅๆฏ็ณป็ป็้่ฏฏ๏ผไฝๅฎ้ ไธ agent ็ณป็ปๅนถๆฒกๆๅฏผ่ด้่ฏฏ๏ผๅชๆฏ LLM ๅคง่็ฏไบไธไธช้่ฏฏ๏ผๆฒกๆๆๅพๅ่พๅบ๏ผไฟๅญๅฐๅ้ไธญใ | |
ๅ ๆญค๏ผๅฎๆ ๆณๅๆฌก่ฎฟ้ฎๅพๅ๏ผๅช่ฝๅฉ็จไฟๅญๅพๅๆถ่ฎฐๅฝ็่ทฏๅพ๏ผๆไปฅๅฎ่ฟๅ็ๆฏ่ทฏๅพ๏ผ่ไธๆฏๅพๅใ | |
่ฐ่ฏ agent ็็ฌฌไธๆญฅๆฏ"ไฝฟ็จๆดๅผบๅคง็ LLM"ใๅ `Qwen2.5-72B-Instruct` ่ฟๆ ท็ๆฟไปฃๆนๆกไธไผ็ฏ่ฟ็ง้่ฏฏใ | |
### 2. ๆไพๆดๅคๆๅฏผ/ๆดๅคไฟกๆฏ | |
ไฝ ไนๅฏไปฅไฝฟ็จไธๅคชๅผบๅคง็ๆจกๅ๏ผๅช่ฆไฝ ๆดๆๆๅฐๆๅฏผๅฎไปฌใ | |
็ซๅจๆจกๅ็่งๅบฆๆ่๏ผๅฆๆไฝ ๆฏๆจกๅๅจ่งฃๅณไปปๅก๏ผไฝ ไผๅ ไธบ็ณป็ปๆ็คบ+ไปปๅก่กจ่ฟฐ+ๅทฅๅ ทๆ่ฟฐไธญๆไพ็ไฟกๆฏ่ๆฃๆๅ๏ผ | |
ไฝ ้่ฆไธไบ้ขๅค็่ฏดๆๅ๏ผ | |
ไธบไบๆไพ้ขๅคไฟกๆฏ๏ผๆไปฌไธๅปบ่ฎฎ็ซๅณๆดๆน็ณป็ปๆ็คบ๏ผ้ป่ฎค็ณป็ปๆ็คบๆ่ฎธๅค่ฐๆด๏ผ้ค้ไฝ ้ๅธธไบ่งฃๆ็คบ๏ผๅฆๅไฝ ๅพๅฎนๆ็ฟป่ฝฆใ | |
ๆดๅฅฝ็ๆๅฏผ LLM ๅผๆ็ๆนๆณๆฏ๏ผ | |
- ๅฆๆๆฏๅ ณไบ่ฆ่งฃๅณ็ไปปๅก๏ผๆๆๆ็ป่ๆทปๅ ๅฐไปปๅกไธญใไปปๅกๅฏไปฅๆๅ ็พ้กต้ฟใ | |
- ๅฆๆๆฏๅ ณไบๅฆไฝไฝฟ็จๅทฅๅ ท๏ผไฝ ็ๅทฅๅ ท็ description ๅฑๆงใ | |
### 3. ๆดๆน็ณป็ปๆ็คบ๏ผ้ๅธธไธๅปบ่ฎฎ๏ผ | |
ๅฆๆไธ่ฟฐ่ฏดๆไธๅค๏ผไฝ ๅฏไปฅๆดๆน็ณป็ปๆ็คบใ | |
่ฎฉๆไปฌ็็ๅฎๆฏๅฆไฝๅทฅไฝ็ใไพๅฆ๏ผ่ฎฉๆไปฌๆฃๆฅ [`CodeAgent`] ็้ป่ฎค็ณป็ปๆ็คบ๏ผไธ้ข็็ๆฌ้่ฟ่ทณ่ฟ้ถๆ ทๆฌ็คบไพ่ฟ่กไบ็ผฉ็ญ๏ผใ | |
```python | |
print(agent.prompt_templates["system_prompt"]) | |
``` | |
ไฝ ไผๅพๅฐ๏ผ | |
```text | |
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. | |
To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code. | |
To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences. | |
At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use. | |
Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_code>' sequence. | |
During each intermediate step, you can use 'print()' to save whatever important information you will then need. | |
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step. | |
In the end you have to return a final answer using the `final_answer` tool. | |
Here are a few examples using notional tools: | |
--- | |
{examples} | |
Above 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: | |
{{tool_descriptions}} | |
{{managed_agents_descriptions}} | |
Here are the rules you should always follow to solve your task: | |
1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_code>' sequence, else you will fail. | |
2. Use only variables that you have defined! | |
3. 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?")'. | |
4. 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. | |
5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters. | |
6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'. | |
7. Never create any notional variables in our code, as having these in your logs might derail you from the true variables. | |
8. You can use imports in your code, but only from the following list of modules: {{authorized_imports}} | |
9. The state persists between code executions: so if in one step you've created variables or imported modules, these will all persist. | |
10. Don't give up! You're in charge of solving the task, not providing directions to solve it. | |
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000. | |
``` | |
ๅฆไฝ ๆ่ง๏ผๆไธไบๅ ไฝ็ฌฆ๏ผๅฆ `"{{tool_descriptions}}"`๏ผ่ฟไบๅฐๅจ agent ๅๅงๅๆถ็จไบๆๅ ฅๆไบ่ชๅจ็ๆ็ๅทฅๅ ทๆ็ฎก็ agent ็ๆ่ฟฐใ | |
ๅ ๆญค๏ผ่ฝ็ถไฝ ๅฏไปฅ้่ฟๅฐ่ชๅฎไนๆ็คบไฝไธบๅๆฐไผ ้็ป `system_prompt` ๅๆฐๆฅ่ฆ็ๆญค็ณป็ปๆ็คบๆจกๆฟ๏ผไฝไฝ ็ๆฐ็ณป็ปๆ็คบๅฟ ้กปๅ ๅซไปฅไธๅ ไฝ็ฌฆ๏ผ | |
- `"{{tool_descriptions}}"` ็จไบๆๅ ฅๅทฅๅ ทๆ่ฟฐใ | |
- `"{{managed_agents_description}}"` ็จไบๆๅ ฅ managed agent ็ๆ่ฟฐ๏ผๅฆๆๆ๏ผใ | |
- ไป ้ `CodeAgent`๏ผ`"{{authorized_imports}}"` ็จไบๆๅ ฅๆๆๅฏผๅ ฅๅ่กจใ | |
็ถๅไฝ ๅฏไปฅๆ นๆฎๅฆไธ๏ผๆดๆน็ณป็ปๆ็คบ๏ผ | |
```py | |
agent.prompt_templates["system_prompt"] = agent.prompt_templates["system_prompt"] + "\nHere you go!" | |
``` | |
่ฟไน้็จไบ [`ToolCallingAgent`]ใ | |
### 4. ้ขๅค่งๅ | |
ๆไปฌๆไพไบไธไธช็จไบ่กฅๅ ่งๅๆญฅ้ชค็ๆจกๅ๏ผagent ๅฏไปฅๅจๆญฃๅธธๆไฝๆญฅ้ชคไน้ดๅฎๆ่ฟ่กใๅจๆญคๆญฅ้ชคไธญ๏ผๆฒกๆๅทฅๅ ท่ฐ็จ๏ผLLM ๅชๆฏ่ขซ่ฆๆฑๆดๆฐๅฎ็ฅ้็ไบๅฎๅ่กจ๏ผๅนถๆ นๆฎ่ฟไบไบๅฎๅๆจๅฎๅบ่ฏฅ้ๅ็ไธไธๆญฅใ | |
```py | |
from smolagents import load_tool, CodeAgent, HfApiModel, DuckDuckGoSearchTool | |
from dotenv import load_dotenv | |
load_dotenv() | |
# ไป Hub ๅฏผๅ ฅๅทฅๅ ท | |
image_generation_tool = load_tool("m-ric/text-to-image", trust_remote_code=True) | |
search_tool = DuckDuckGoSearchTool() | |
agent = CodeAgent( | |
tools=[search_tool], | |
model=HfApiModel("Qwen/Qwen2.5-72B-Instruct"), | |
planning_interval=3 # ่ฟๆฏไฝ ๆฟๆดป่งๅ็ๅฐๆน๏ผ | |
) | |
# ่ฟ่กๅฎ๏ผ | |
result = agent.run( | |
"How long would a cheetah at full speed take to run the length of Pont Alexandre III?", | |
) | |
``` |