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

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

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

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

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

設(shè)計(jì)亮點(diǎn)

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

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

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

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

  • 極簡(jiǎn)架構(gòu):核心代碼簡(jiǎn)潔,易于理解和定制,避免了不必要的框架抽象。
  • 安全沙箱:集成 E2B 等沙箱環(huán)境,確保代碼執(zhí)行的安全性,降低潛在的安全風(fēng)險(xiǎn)。
  • Hub 集成:無(wú)縫對(duì)接 Hugging Face Hub,方便工具和模型的共享與復(fù)用。
  • 模型兼容性:支持 Hugging Face Hub 上的開(kāi)源模型,以及 OpenAI、Anthropic 等主流 LLM。

代碼示例

smolagents 的上手門(mén)檻非常低,以下是一個(gè)簡(jiǎn)單的代碼示例:

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?")

可以看到,開(kāi)發(fā)者只需要幾行代碼,就能創(chuàng)建一個(gè)可以執(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.")

開(kāi)源模型的潛力

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

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

總結(jié)

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

項(xiàng)目地址:https://github.com/huggingface/smolagents

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

標(biāo)簽
收藏
回復(fù)
舉報(bào)
回復(fù)
相關(guān)推薦
主站蜘蛛池模板: 一区二区在线观看av | 国产91色在线 | 亚洲 | 中文字幕1区 | 国产视频91在线 | www精品美女久久久tv | 成人国产精品久久久 | 欧美无乱码久久久免费午夜一区 | 久久久久国产精品午夜一区 | 99久久国产综合精品麻豆 | av一二三区 | 亚洲视频一区在线观看 | 人人擦人人 | 久久精品一区 | 久久伦理电影 | 国产精品视频区 | 亚洲成人精品国产 | 欧美日韩综合精品 | 国产一区欧美 | 午夜精品三区 | 99热热精品| 欧美在线观看一区 | 久久久久久国产精品免费免费狐狸 | 欧美激情久久久 | 天天爽夜夜操 | 国精产品一品二品国精在线观看 | 日韩一区二区三区视频 | 欧美日韩一区二区电影 | 国产欧美精品一区二区三区 | 亚洲一区在线日韩在线深爱 | 午夜久久久久 | 91精品国产91久久久久游泳池 | 老司机午夜性大片 | 国产日韩欧美一区 | 国产情侣在线看 | 91传媒在线观看 | 毛片的网址 | 欧美日韩国产一区二区三区 | 天天干天天干 | av在线一区二区三区 | 国产精品久久久 | 日韩欧美一区二区三区四区 |