成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

smolagents:Hugging Face 開源的Agent框架,用代碼驅動 Agent 的新思路 精華

發布于 2025-1-10 13:38
瀏覽
0收藏

近日,Hugging Face 最近開源的一個Agent項目:smolagents。相較于其它框架,它的理念和實現都比較簡單。基于python開發,核心設計理念是 “少即是多”。相比市面上動輒幾萬行代碼的 Agent 框架,它保持了極簡的風格,核心代碼僅有數千行,但功能卻毫不遜色。Hugging Face 團隊希望通過這種方式,降低 Agent 開發的門檻,讓更多開發者能夠快速上手。

smolagents:Hugging Face 開源的Agent框架,用代碼驅動 Agent 的新思路-AI.x社區

設計亮點

smolagents:Hugging Face 開源的Agent框架,用代碼驅動 Agent 的新思路-AI.x社區

smolagents 的最大亮點在于其對“代碼 Agent” 的原生支持。這意味著 Agent 的行為將直接通過 Python 代碼來表達,而非傳統的 JSON 或者文本指令。這種設計思路有以下幾點優勢:

  • 執行效率更高:代碼 Agent 可以減少 LLM 的調用次數,從而提高整體的執行效率。
  • 表達能力更強:代碼本身就是一種清晰、簡潔的表達方式,更適合描述復雜的 Agent 行為。
  • 復用性更好:代碼的模塊化設計,能夠更好地復用和擴展 Agent 的功能。
  • 避免 JSON 的復雜性:省去了 JSON 結構定義、解析等環節,讓 Agent 開發回歸本質。

關鍵特性解讀:

  • 極簡架構:核心代碼簡潔,易于理解和定制,避免了不必要的框架抽象。
  • 安全沙箱:集成 E2B 等沙箱環境,確保代碼執行的安全性,降低潛在的安全風險。
  • Hub 集成:無縫對接 Hugging Face Hub,方便工具和模型的共享與復用。
  • 模型兼容性:支持 Hugging Face Hub 上的開源模型,以及 OpenAI、Anthropic 等主流 LLM。

代碼示例

smolagents 的上手門檻非常低,以下是一個簡單的代碼示例:

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel

agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())

agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?")

可以看到,開發者只需要幾行代碼,就能創建一個可以執行網絡搜索任務的 Agent。

更復雜的例子:

from typing import Optional
from smolagents import CodeAgent, HfApiModel, tool

@tool
def get_travel_duration(start_location: str, destination_location: str, departure_time: Optional[int] = None) -> str:
    """Gets the travel time in car between two places.
    
    Args:
        start_location: the place from which you start your ride
        destination_location: the place of arrival
        departure_time: the departure time, provide only a `datetime.datetime` if you want to specify this
    """
    import googlemaps # All imports are placed within the function, to allow for sharing to Hub.
    import os

    gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))

    if departure_time is None:
        from datetime import datetime
        departure_time = datetime(2025, 1, 6, 11, 0)

    directions_result = gmaps.directions(
        start_location,
        destination_location,
        mode="transit",
        departure_time=departure_time
    )
    return directions_result[0]["legs"][0]["duration"]["text"]

agent = CodeAgent(tools=[get_travel_duration], model=HfApiModel(), additional_authorized_imports=["datetime"])

agent.run("Can you give me a nice one-day trip around Paris with a few locations and the times? Could be in the city or outside, but should fit in one day. I'm travelling only via public transportation.")

開源模型的潛力

smolagents 的實驗結果表明,在一些復雜任務中,基于開源模型構建的代碼 Agent,已經展現出了不俗的性能,甚至可以和一些閉源模型相媲美。這對開源 Agent 技術的發展無疑是一個利好。

smolagents:Hugging Face 開源的Agent框架,用代碼驅動 Agent 的新思路-AI.x社區

總結

Hugging Face 向來對開發者用戶理解深入,加上它社區的優勢,它發布的很多框架都能夠獲得不錯的反響,smolagents 是 Hugging Face 在 AI Agent 領域的一次嘗試,上線沒幾天就已經4k的星標,建議大家也使用使用,一起交流使用心得和體驗。

項目地址:https://github.com/huggingface/smolagents

本文轉載自 ??AI工程化??,作者: ully

收藏
回復
舉報
回復
相關推薦
主站蜘蛛池模板: 日本一区二区三区四区 | 2019天天操 | 91精品国产综合久久久亚洲 | 成人在线观看免费爱爱 | 免费国产视频在线观看 | 祝你幸福电影在线观看 | 久优草 | 成年人在线观看 | 国产日韩精品一区 | 日本人麻豆 | 日韩不卡在线 | 在线视频亚洲 | www.天天操.com | 亚洲色欲色欲www | 欧美成年黄网站色视频 | 久久久成人网 | av大全在线观看 | 中文字幕1区 | 国产在线观看av | 99re国产精品 | 不卡在线视频 | 久久99精品久久久 | 久久伊人操 | 日韩在线一区二区三区 | 国产亚洲一区二区三区 | 国产精品中文字幕在线 | 日日精品| 99只有精品| 中文字幕亚洲专区 | 中文字幕四虎 | 亚洲午夜视频 | 日韩1区 | 激情亚洲 | 日韩爱爱网| 最新中文字幕在线 | 伊人网站 | 日韩欧美三区 | 午夜精品一区二区三区免费视频 | 中文字幕免费 | 精品www| 激情网站|