Tiny Agent A 3B
微型代理-α是基於Qwen2.5-Coder系列模型訓練的輕量級AI代理,專為邊緣設備設計,支持Pythonic函數調用方式。
下載量 207
發布時間 : 2/11/2025
模型概述
該模型採用Python代碼塊與工具交互的方式,支持並行多函數調用和自由形式推理,適用於需要複雜邏輯處理的場景。
模型特點
Pythonic函數調用
支持使用Python代碼塊與工具交互,相比傳統JSON方式更靈活高效
並行多函數調用
可在一次對話中利用多個同步進程解決問題,減少對話輪次
自由形式推理
允許在自然語言中提供推理痕跡,無需強制特定輸出格式
邊緣設備優化
經過量化感知訓練,適合在資源有限的邊緣設備上運行
模型能力
文本生成
Python代碼生成
函數調用
複雜邏輯處理
多任務並行處理
使用案例
日程管理
檢查時間可用性
檢查特定時間段是否可用
返回布爾值表示時間段可用性
自動化任務
複雜邏輯處理
執行需要條件判斷和多步驟處理的任務
生成可執行的Python程序解決方案
🚀 Tiny-Agent-α
Tiny-Agent-α 是 Dria-Agent-a 的擴展,它基於 Qwen2.5-Coder 系列模型進行訓練,可用於邊緣設備。這些模型通過量化感知訓練進行了精細微調,以最大程度減少量化後的性能損失。
Tiny-Agent-α 採用了 Python 函數調用 方式,即大語言模型(LLMs)使用 Python 代碼塊與提供的工具進行交互並輸出操作。這種方法受到了許多先前工作的啟發,包括但不限於 DynaSaur、RLEF、ADAS 和 CAMEL。與傳統的基於 JSON 的函數調用方法相比,這種函數調用方式具有以下優勢:
- 一次性並行多函數調用:該模型可以在一次對話中利用多個同步進程來找到解決方案,而其他函數調用模型可能需要多次對話才能實現。
- 自由形式的推理和操作:模型可以自然地以自然語言提供推理過程,並在 ```python ``` 代碼塊中輸出操作,無需特殊提示或調整。這有助於緩解在 Let Me Speak Freely? 中討論的對大語言模型輸出施加特定格式可能導致的性能損失。
- 即時生成複雜解決方案:模型提供的解決方案本質上是一個 Python 程序,但排除了一些“危險”的內置函數,如
exec
、eval
和compile
(完整列表見下面的快速開始部分)。這使得模型能夠通過條件語句和同步管道(在下一個函數的參數中使用前一個函數的輸出)實現自定義的複雜邏輯,而目前基於 JSON 的函數調用方法(據我們所知)無法做到這一點。
🚀 快速開始
你可以使用 dria_agent
包輕鬆使用 Tiny-Agent-α:
pip install dria_agent
這個包可以處理模型、工具、代碼執行和後端(支持 mlx
、ollama
和 transformers
)。
💻 使用示例
基礎用法
使用 @tool
裝飾器將函數暴露給代理:
from dria_agent import tool
@tool
def check_availability(day: str, start_time: str, end_time: str) -> bool:
"""
Checks if a given time slot is available.
:param day: The date in "YYYY-MM-DD" format.
:param start_time: The start time of the desired slot (HH:MM format, 24-hour).
:param end_time: The end time of the desired slot (HH:MM format, 24-hour).
:return: True if the slot is available, otherwise False.
"""
# Mock implementation
if start_time == "12:00" and end_time == "13:00":
return False
return True
創建一個帶有自定義工具的代理:
from dria_agent import ToolCallingAgent
agent = ToolCallingAgent(
tools=[check_availability]
)
使用 agent.run(query)
結合工具執行任務:
execution = agent.run("Check my calendar for tomorrow noon", print_results=True)
輸出如下:
let me help you check your availability for a 1-hour meditation session
starting at noon tomorrow.
Step-by-step reasoning:
1. We need to check availability for a specific time slot (noon)
2. The duration is 1 hour, so we'll use the same start and end times
3. Since it's tomorrow, we should format the date as "YYYY-MM-DD"
4. Use the check_availability() function with these parameters
Here's the code to check your availability:
```python
tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d")
start_time = "12:00" # Noon in 24-hour format
end_time = "13:00" # One hour after noon
availability = check_availability(tomorrow, start_time, end_time)
The code will:
- Calculate tomorrow's date using datetime and timedelta
- Set the time slot to noon (12:00) for 1 hour duration
- Check if this time slot is available using the check_availability function
The availability variable will contain True if you're available, or False if
not.
如果使用 `dria_agent`,系統提示和工具可以直接使用,無需額外設置。
你也可以直接使用 `transformers` 庫來使用 Tiny-Agent-α-3B:
```python
import json
from typing import Any, Dict, List
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model and tokenizer
model_name = "driaforall/Tiny-Agent-a-3B"
model = AutoModelForCausalLM.from_pretrained(
model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# System prompt for optimal performance
SYSTEM_PROMPT = """
You are an expert AI assistant that specializes in providing Python code to solve the task/problem at hand provided by the user.
You can use Python code freely, including the following available functions:
<|functions_schema|>
{{functions_schema}}
<|end_functions_schema|>
The following dangerous builtins are restricted for security:
- exec
- eval
- execfile
- compile
- importlib
- input
- exit
Think step by step and provide your reasoning, outside of function calls.
You can write Python code and use the available functions. Provide all your Python code in a SINGLE markdown code block.
DO NOT use print() statements AT ALL. Avoid mutating variables whenever possible.
""".strip()
# Example function schema (define the functions available to the model)
FUNCTIONS_SCHEMA = """
def check_availability(day: str, start_time: str, end_time: str) -> bool:
"""
Checks if a given time slot is available.
:param day: The date in "YYYY-MM-DD" format.
:param start_time: The start time of the desired slot (HH:MM format, 24-hour).
:param end_time: The end time of the desired slot (HH:MM format, 24-hour).
:return: True if the slot is available, otherwise False.
"""
pass
"""
# Format system prompt
system_prompt = SYSTEM_PROMPT.replace("{{functions_schema}}", FUNCTIONS_SCHEMA)
# Example user query
USER_QUERY = "Check if I'm available for an hour long meditation at tomorrow noon."
# Format messages for the model
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": USER_QUERY},
]
# Prepare input for the model
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# Generate response
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512
)
# Extract new generated tokens
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
# Decode response
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
📊 評估與性能
我們在 Dria-Pythonic-Agent-Benchmark (DPAB) 上對模型進行了評估。這個基準測試是我們通過合成數據生成、基於模型的驗證、過濾和手動選擇精心策劃的,用於評估大語言模型的 Python 函數調用能力,涵蓋了多個場景和任務。更多信息請參閱 博客。
以下是 DPAB 的評估結果:
當前各種模型的基準測試結果(嚴格模式):
模型名稱 | Pythonic | JSON |
---|---|---|
閉源模型 | ||
Claude 3.5 Sonnet | 87 | 45 |
gpt-4o-2024-11-20 | 60 | 30 |
開源模型 | ||
參數 > 100B | ||
DeepSeek V3 (685B) | 63 | 33 |
MiniMax-01 | 62 | 40 |
Llama-3.1-405B-Instruct | 60 | 38 |
參數 > 30B | ||
Qwen-2.5-Coder-32b-Instruct | 68 | 32 |
Qwen-2.5-72b-instruct | 65 | 39 |
Llama-3.3-70b-Instruct | 59 | 40 |
QwQ-32b-Preview | 47 | 21 |
參數 < 20B | ||
Phi-4 (14B) | 55 | 35 |
Qwen2.5-Coder-7B-Instruct | 44 | 39 |
Qwen-2.5-7B-Instruct | 47 | 34 |
Tiny-Agent-α-3B | 72 | 34 |
Qwen2.5-Coder-3B-Instruct | 26 | 37 |
Tiny-Agent-α-1.5B | 73 | 30 |
📄 引用
@misc{Dria-Agent-a,
url={https://huggingface.co/blog/andthattoo/dria-agent-a},
title={Dria-Agent-a},
author={"andthattoo", "Atakan Tekparmak"}
}
📄 許可證
本項目採用 qwen-research 許可證。
Phi 2 GGUF
其他
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 支持多種語言
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 英語
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 英語
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 英語
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 支持多種語言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 英語
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 英語
O
facebook
6.3M
198
1
基於transformers庫的預訓練模型,適用於多種NLP任務
大型語言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多語言大語言模型系列,包含8B、70B和405B參數規模,支持8種語言和代碼生成,優化了多語言對話場景。
大型語言模型
Transformers 支持多種語言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基礎版是由Google開發的文本到文本轉換Transformer模型,參數規模2.2億,支持多語言NLP任務。
大型語言模型 支持多種語言
T
google-t5
5.4M
702
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98