
Llama-3.1-8B-xLAM-Agent
Built with Llama. This is meta-llama/Llama-3.1-8B-Instruct fine-tuned (QLoRA, then merged to 16-bit)
on the first 16,000 samples of
Salesforce/xlam-function-calling-60k
to improve function calling. The base model is not agentic by itself, but this model can be used inside agentic workflows.
Training summary
- Data: first 16,000 rows of xLAM-60k, original order, no shuffling, no truncation (longest sample: 2,999 tokens)
- Method: QLoRA (r=32, alpha=64, all attention and MLP projections), 1 epoch, effective batch size 16, learning rate 1e-4
- Loss: computed on the assistant answer only
- Hardware: single Tesla T4 (Kaggle)
Benchmarking

I benchmarked my fine-tuned Llama-3.1-8B-xLAM-Agent against the original Llama-3.1-8B-Instruct model on 5,000 test samples from the Salesforce xLAM Function Calling dataset. The strict exact match accuracy improved from 10.40% to 86.54%, while valid JSON output increased from 76.18% to 99.74%. Function-set accuracy also improved from 30.20% to 99.18%, and argument-level F1 increased from 41.73% to 93.10%, demonstrating a significant improvement in structured function calling after fine-tuning.
Output format
Tools are passed through the Llama 3.1 chat template. The model replies with a single JSON array of calls,
each in the form {"name": ..., "parameters": {...}}. Several calls go in the same array.
Usage
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
repo = "Rumiii/Llama-3.1-8B-xLAM-Agent"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype=torch.float16, device_map="auto")
SYSTEM_PROMPT = (
"You are a helpful assistant with access to functions. Use them only when needed. "
"Respond ONLY with a JSON array of function calls, where each call is "
'{"name": <function name>, "parameters": {<argument name>: <value>}}. '
"If several calls are needed, put all of them in the same array."
)
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string", "description": "City name"}},
"required": ["city"],
},
},
}]
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "What is the weather in Hyderabad and in Paris?"},
]
inputs = tok.apply_chat_template(
messages, tools=tools, add_generation_prompt=True,
return_tensors="pt", return_dict=True,
).to(model.device)
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
print(tok.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
Limitations
Trained on synthetic data, so outputs can contain wrong arguments. Validate every call before executing it, especially for anything with side effects.
Licenses and attribution
Use is subject to the Llama 3.1 Community License. The xLAM dataset is released under CC-BY-4.0 (Liu et al., 2024, APIGen, arXiv:2406.18518).