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
智启未来,您的人工智能解决方案智库
简体中文