---
license: apache-2.0
license_link: https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct/blob/main/LICENSE
language:
- en
base_model:
- Qwen/Qwen2.5-Coder-7B-Instruct
pipeline_tag: text-generation
library_name: transformers
tags:
- code
- chat
- qwen
- qwen-coder
- agent
---

# Dria-Agent-α-7B

## Introduction

***Dria-Agent-α*** are series of large language models trained on top of the [Qwen2.5-Coder](https://huggingface.co/collections/Qwen/qwen25-coder-66eaa22e6f99801bf65b0c2f) series, specifically on top of the [Qwen/Qwen2.5-Coder-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct) and [Qwen/Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) models to be used in agentic applications. These models are the first instalment of agent-focused LLMs (hence the **α** in the naming) we hope to improve with better and more elaborate techniques in subsequent releases.

Dria-Agent-α employs ***Pythonic function calling***, which is LLMs using blocks of Python code to interact with provided tools and output actions. This method was inspired by many previous work, including but not limited to [DynaSaur](https://arxiv.org/pdf/2411.01747), [RLEF](https://arxiv.org/pdf/2410.02089), [ADAS](https://arxiv.org/pdf/2408.08435) and [CAMEL](https://arxiv.org/pdf/2303.17760). This way of function calling has a few advantages over traditional JSON-based function calling methods:

1. **One-shot Parallel Multiple Function Calls:** The model can can utilise many synchronous processes in one chat turn to arrive to a solution, which would require other function calling models multiple turns of conversation.
2. **Free-form Reasoning and Actions:** The model provides reasoning traces freely in natural language and the actions in between \`\`\`python \`\`\` blocks, as it already tends to do without special prompting or tuning. This tries to mitigate the possible performance loss caused by imposing specific formats on LLM outputs discussed in [Let Me Speak Freely?](https://arxiv.org/pdf/2408.02442)
3. **On-the-fly Complex Solution Generation:** The solution provided by the model is essentially a Python program with the exclusion of some "risky" builtins like `exec`, `eval` and `compile` (see full list in **Quickstart** below). This enables the model to implement custom complex logic with conditionals and synchronous pipelines (using the output of one function in the next function's arguments) which would not be possible with the current JSON-based function calling methods (as far as we know).

## Quickstart

````python
import json
from typing import Any, Dict, List
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "driaforall/Dria-Agent-a-7B"
model = AutoModelForCausalLM.from_pretrained(
    model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Please use our provided prompt for best 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 the function calls.
You can write Python code and use the available functions. Provide all your python code in a SINGLE markdown code block like the following:

```python
result = example_function(arg1, "string")
result2 = example_function2(result, arg2)
```

DO NOT use print() statements AT ALL. Avoid mutating variables whenever possible.
""".strip()


get_sample_data = """
def check_availability(day: str, start_time: str, end_time: str) -> bool:
    \"\"\" 
    Check if a time slot is available on a given day.

    Args:
    - day: The day to check in YYYY-MM-DD format
    - start_time: Start time in HH:MM format
    - end_time: End time in HH:MM format

    Returns:
    - True if slot is available, False otherwise
    \"\"\"
    pass

def make_appointment(day: str, start_time: str, end_time: str) -> dict:
    \"\"\" 
    Make an appointment for a given time slot.

    Args:
    - day: The day to make appointment in YYYY-MM-DD format
    - start_time: Start time in HH:MM format
    - end_time: End time in HH:MM format
    - title: The title of the appointment

    Returns:
    - A dictionary with the appointment details and if it's made or not.
        dict keys:
            - day (str): The day the appointment is on, in YYYY-MM-DD format
            - start_time (str): Start time in HH:MM format
            - end_time (str): End time in HH:MM format
            - appointment_made (bool): Whether the appointment is successfully made or not. 
    \"\"\"
    pass

def add_to_reminders(reminder_text: str) -> bool:
    \"\"\" 
    Add a text to reminders.

    Args: 
    - reminder_text: The text to add to reminders

    Returns:
    - Whether the reminder was successfully created or not.
    \"\"\"
    pass
"""

# Helper function to create the system prompt for our model
def format_prompt(tools: str):
    return SYSTEM_PROMPT.format(functions_schema=tools)

system_prompt = SYSTEM_PROMPT.replace("{{functions_schema}}", get_sample_data)

USER_QUERY = """
Can you check if I have tomorrow 10:00-12:00 available and make an appointment for a meeting 
with my thesis supervisor if so? If you made the appointment, please add it to my reminders.
"""

messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": USER_QUERY},
]

text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=2048
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
````

The output should be something like:

````
To accomplish this task, we need to follow these steps:

1. Check if the time slot from 10:00 to 12:00 on tomorrow is available using the `check_availability` function.
2. If the slot is available, proceed to make an appointment using the `make_appointment` function.
3. If the appointment is successfully made, add it to the reminders using the `add_to_reminders` function.

Let's break down the code into these steps:

```python
from datetime import datetime, timedelta

# Get tomorrow's date
tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d")

# Define the time slots
start_time = "10:00"
end_time = "12:00"

# Step 1: Check availability
is_available = check_availability(tomorrow, start_time, end_time)

if is_available:
    # Step 2: Make the appointment
    appointment_details = make_appointment(tomorrow, start_time, end_time, "Meeting with thesis supervisor")
    
    if appointment_details['appointment_made']:
        # Step 3: Add to reminders
        reminder_text = f"Appointment with thesis supervisor scheduled for {tomorrow} from {start_time} to {end_time}."
        add_to_reminders(reminder_text)
else:
    appointment_details = {"day": tomorrow, "start_time": start_time, "end_time": end_time, "appointment_made": False}
```

This code will first determine if the specified time slot is available tomorrow. If it is, it will attempt to make the appointment and then add it to the reminders if successful.
````

## Evaluation & Performance

We evaluate the model on the following benchmarks:

1. Berkeley Function Calling Leaderboard (BFCL)
2. MMLU-Pro
3. **Dria-Pythonic-Agent-Benchmark (DPAB):** The benchmark we curated with a synthetic data generation +model-based validation + filtering and manual selection to evaluate LLMs on their Pythonic function calling ability, spanning multiple scenarios and tasks. More detailed information about the benchmark and the Github repo will be released soon.

Below are the BFCL results: evaluation results for ***Qwen2.5-Coder-3B-Instruct***, ***Dria-Agent-α-3B***, ***Dria-Agent-α-7B***, and ***gpt-4o-2024-11-20***

| Metric                                | Qwen/Qwen2.5-3B-Instruct   | Dria-Agent-a-3B   | Dria-Agent-7B     | gpt-4o-2024-11-20 (Prompt)   |
|---------------------------------------|----------------------------|-------------------|-------------------|---------------------------|
| **Non-Live Simple AST**               | 75.50%                    | 75.08%           | 77.58%           | 79.42%                   |
| **Non-Live Multiple AST**             | 90.00%                    | 93.00%           | 94.00%           | 95.50%                   |
| **Non-Live Parallel AST**             | 80.00%                    | 85.00%           | 93.50%           | 94.00%                   |
| **Non-Live Parallel Multiple AST**    | 78.50%                    | 79.00%           | 89.50%           | 83.50%                   |
| **Non-Live Simple Exec**              | 82.07%                    | 87.57%           | 93.29%           | 100.00%                  |
| **Non-Live Multiple Exec**            | 86.00%                    | 85.14%           | 88.00%           | 94.00%                   |
| **Non-Live Parallel Exec**            | 82.00%                    | 90.00%           | 88.00%           | 86.00%                   |
| **Non-Live Parallel Multiple Exec**   | 80.00%                    | 88.00%           | 72.50%           | 77.50%                   |
| **Live Simple AST**                   | 68.22%                    | 70.16%           | 81.40%           | 83.72%                   |
| **Live Multiple AST**                 | 66.00%                    | 67.14%           | 78.73%           | 79.77%                   |
| **Live Parallel AST**                 | 62.50%                    | 50.00%           | 75.00%           | 87.50%                   |
| **Live Parallel Multiple AST**        | 66.67%                    | 70.83%           | 62.50%           | 70.83%                   |
| **Relevance Detection**               | 88.89%                    | 100.00%          | 100.00%          | 83.33%                   |



and the MMLU-Pro and DPAB results:

| Benchmark Name | Qwen2.5-Coder-7B-Instruct | Dria-Agent-α-7B |
|----------------|---------------------------|-----------------|
| MMLU-Pro | 45.6 ([Self Reported](https://arxiv.org/pdf/2409.12186)) | 42.54 |
| DPAB (Pythonic, Strict) | 44.0 | 70.0 |

**\*Note:** The model tends to use Pythonic function calling for a lot of the test cases in STEM-related fields (math, physics, chemistry, etc.) in the MMLU-Pro benchmark, which isn't captured by the evaluation framework and scripts provided in their [Github repository](https://github.com/TIGER-AI-Lab/MMLU-Pro/tree/main). We haven't modified the script for evaluation, and leave it for the future iterations of this model. However, by performing qualitative analysis on the model responses, we suspect that the model's score will increase instead of suffering a ~3% decrease.

#### Citation

```
@misc{Dria-Agent-a,
      url={https://huggingface.co/blog/andthattoo/dria-agent-a},
      title={Dria-Agent-a},
      author={"andthattoo", "Atakan Tekparmak"}
}
```
