偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

發(fā)布于 2025-1-10 13:38
瀏覽
0收藏

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

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

設(shè)計亮點

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

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

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

關(guān)鍵特性解讀:

  • 極簡架構(gòu):核心代碼簡潔,易于理解和定制,避免了不必要的框架抽象。
  • 安全沙箱:集成 E2B 等沙箱環(huán)境,確保代碼執(zhí)行的安全性,降低潛在的安全風(fēng)險。
  • Hub 集成:無縫對接 Hugging Face Hub,方便工具和模型的共享與復(fù)用。
  • 模型兼容性:支持 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?")

可以看到,開發(fā)者只需要幾行代碼,就能創(chuàng)建一個可以執(zhí)行網(wǎng)絡(luò)搜索任務(wù)的 Agent。

更復(fù)雜的例子:

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 的實驗結(jié)果表明,在一些復(fù)雜任務(wù)中,基于開源模型構(gòu)建的代碼 Agent,已經(jīng)展現(xiàn)出了不俗的性能,甚至可以和一些閉源模型相媲美。這對開源 Agent 技術(shù)的發(fā)展無疑是一個利好。

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

總結(jié)

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

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

本文轉(zhuǎn)載自 ??AI工程化??,作者: ully

收藏
回復(fù)
舉報
回復(fù)
相關(guān)推薦