Welcome to the xLAM model family! Large Action Models (LAMs) are advanced large language models designed to enhance decision-making and translate user intentions into executable actions that interact with the world. LAMs autonomously plan and execute tasks to achieve specific goals, serving as the brains of AI agents. They have the potential to automate workflow processes across various domains, making them invaluable for a wide range of applications.
The model release is exclusively for research purposes. A new and enhanced version of xLAM will soon be available exclusively to customers on our Platform.
We provide a series of xLAMs in different sizes to cater to various applications, including those optimized for function-calling and general agent applications:
For our Function-calling series (more details are included at here), we also provide their quantized GGUF files for efficient deployment and execution. GGUF is a file format designed to efficiently store and load large language models, making GGUF ideal for running AI models on local devices with limited resources, enabling offline functionality and enhanced privacy.
This repository is about the general tool use series. For more specialized function calling models, please take a look into our fc series here.
The instructions will guide you through the setup, usage, and integration of our model series with HuggingFace.
Framework Versions
Transformers 4.41.0
Pytorch 2.3.0+cu121
Datasets 2.19.1
Tokenizers 0.19.1
Usage
Basic Usage with Huggingface
To use the model from Huggingface, please first install the transformers library:
pip install transformers>=4.41.0
Please note that, our model works best with our provided prompt format.
It allows us to extract JSON output that is similar to the function-calling mode of ChatGPT.
We use the following example to illustrate how to use our model for 1) single-turn use case, and 2) multi-turn use case
1. Single-turn use case
python
1import json
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer
45torch.random.manual_seed(0)67model_name ="Salesforce/xLAM-7b-r"8model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True)9tokenizer = AutoTokenizer.from_pretrained(model_name)1011# Please use our provided instruction prompt for best performance12task_instruction ="""
13Based on the previous context and API request history, generate an API request or a response as an AI assistant.""".strip()1415format_instruction ="""
16The output should be of the JSON format, which specifies a list of generated function calls. The example format is as follows, please make sure the parameter type is correct. If no function call is needed, please make
17tool_calls an empty list "[]".
18```
19{"thought": "the thought process, or an empty string", "tool_calls": [{"name": "api_name1", "arguments": {"argument1": "value1", "argument2": "value2"}}]}
20```
21""".strip()2223# Define the input query and available tools24query ="What's the weather like in New York in fahrenheit?"2526get_weather_api ={27"name":"get_weather",28"description":"Get the current weather for a location",29"parameters":{30"type":"object",31"properties":{32"location":{33"type":"string",34"description":"The city and state, e.g. San Francisco, New York"35},36"unit":{37"type":"string",38"enum":["celsius","fahrenheit"],39"description":"The unit of temperature to return"40}41},42"required":["location"]43}44}4546search_api ={47"name":"search",48"description":"Search for information on the internet",49"parameters":{50"type":"object",51"properties":{52"query":{53"type":"string",54"description":"The search query, e.g. 'latest news on AI'"55}56},57"required":["query"]58}59}6061openai_format_tools =[get_weather_api, search_api]6263# Helper function to convert openai format tools to our more concise xLAM format64defconvert_to_xlam_tool(tools):65''''''66ifisinstance(tools,dict):67return{68"name": tools["name"],69"description": tools["description"],70"parameters":{k: v for k, v in tools["parameters"].get("properties",{}).items()}71}72elifisinstance(tools,list):73return[convert_to_xlam_tool(tool)for tool in tools]74else:75return tools
7677defbuild_conversation_history_prompt(conversation_history:str):78 parsed_history =[]79for step_data in conversation_history:80 parsed_history.append({81"step_id": step_data["step_id"],82"thought": step_data["thought"],83"tool_calls": step_data["tool_calls"],84"next_observation": step_data["next_observation"],85"user_input": step_data['user_input']86})8788 history_string = json.dumps(parsed_history)89return f"
90[BEGIN OF HISTORY STEPS]91{history_string}92[END OF HISTORY STEPS]93"
949596# Helper function to build the input prompt for our model97defbuild_prompt(task_instruction:str, format_instruction:str, tools:list, query:str):98 prompt =f"[BEGIN OF TASK INSTRUCTION]\n{task_instruction}\n[END OF TASK INSTRUCTION]\n\n"99 prompt +=f"[BEGIN OF AVAILABLE TOOLS]\n{json.dumps(xlam_format_tools)}\n[END OF AVAILABLE TOOLS]\n\n"100 prompt +=f"[BEGIN OF FORMAT INSTRUCTION]\n{format_instruction}\n[END OF FORMAT INSTRUCTION]\n\n"101 prompt +=f"[BEGIN OF QUERY]\n{query}\n[END OF QUERY]\n\n"102return prompt
103104105# Build the input and start the inference106xlam_format_tools = convert_to_xlam_tool(openai_format_tools)107108conversation_history =[]109content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query, conversation_history)110111messages=[112{'role':'user','content': content}113]114115inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)116117# tokenizer.eos_token_id is the id of <|EOT|> token118outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)119agent_action = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
Then you should be able to see the following output string in JSON format:
{"thought": "I need to get the current weather for New York in fahrenheit.", "tool_calls": [{"name": "get_weather", "arguments": {"location": "New York", "unit": "fahrenheit"}}]}
2. Multi-turn use case
We also support multi-turn interaction with our model series. Here is the example of next round of interaction from the above example:
python
1defparse_agent_action(agent_action:str):2"""
3 Given an agent's action, parse it to add to conversation history
4 """5try: parsed_agent_action_json = json.loads(agent_action)6except:return"",[]78if"thought"notin parsed_agent_action_json.keys(): thought =""9else: thought = parsed_agent_action_json["thought"]1011if"tool_calls"notin parsed_agent_action_json.keys(): tool_calls =[]12else: tool_calls = parsed_agent_action_json["tool_calls"]1314return thought, tool_calls
1516defupdate_conversation_history(conversation_history:list, agent_action:str, environment_response:str, user_input:str):17"""
18 Update the conversation history list based on the new agent_action, environment_response, and/or user_input
19 """20 thought, tool_calls = parse_agent_action(agent_action)21 new_step_data ={22"step_id":len(conversation_history)+1,23"thought": thought,24"tool_calls": tool_calls,25"step_id":len(conversation_history),26"next_observation": environment_response,27"user_input": user_input,28}2930 conversation_history.append(new_step_data)3132defget_environment_response(agent_action:str):33"""
34 Get the environment response for the agent_action
35 """36# TODO: add custom implementation here37 error_message, response_message ="",""38return{"error": error_message,"response": response_message}3940# ------------- before here are the steps to get agent_response from the example above ----------4142# 1. get the next state after agent's response:43# The next 2 lines are examples of getting environment response and user_input.44# It is depended on particular usage, we can have either one or both of those.45environment_response = get_environment_response(agent_action)46user_input ="Now, search on the Internet for cute puppies"4748# 2. after we got environment_response and (or) user_input, we want to add to our conversation history49update_conversation_history(conversation_history, agent_action, environment_response, user_input)5051# 3. we now can build the prompt52content = build_prompt(task_instruction, format_instruction, xlam_format_tools, query, conversation_history)5354# 4. Now, we just retrieve the inputs for the LLM55messages=[56{'role':'user','content': content}57]58inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)5960# 5. Generate the outputs & decode61# tokenizer.eos_token_id is the id of <|EOT|> token62outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)63agent_action = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
This would be the corresponding output:
{"thought": "I need to get the current weather for New York in fahrenheit.", "tool_calls": [{"name": "get_weather", "arguments": {"location": "New York", "unit": "fahrenheit"}}]}
We highly recommend to use our provided prompt format and helper functions to yield the best function-calling performance of our model.
Example multi-turn prompt and output
Prompt:
json
1[BEGIN OF TASK INSTRUCTION]2Based on the previous context and API request history, generate an API request or a response as an AI assistant.
3[END OF TASK INSTRUCTION]45[BEGIN OF AVAILABLE TOOLS]6[7{8"name":"get_fire_info",9"description":"Query the latest wildfire information",10"parameters":{11"location":{12"type":"string",13"description":"Location of the wildfire, for example: 'California'",14"required":true,15"format":"free"16},17"radius":{18"type":"number",19"description":"The radius (in miles) around the location where the wildfire is occurring, for example: 10",20"required":false,21"format":"free"22}23}24},25{26"name":"get_hurricane_info",27"description":"Query the latest hurricane information",28"parameters":{29"name":{30"type":"string",31"description":"Name of the hurricane, for example: 'Irma'",32"required":true,33"format":"free"34}35}36},37{38"name":"get_earthquake_info",39"description":"Query the latest earthquake information",40"parameters":{41"magnitude":{42"type":"number",43"description":"The minimum magnitude of the earthquake that needs to be queried.",44"required":false,45"format":"free"46},47"location":{48"type":"string",49"description":"Location of the earthquake, for example: 'California'",50"required":false,51"format":"free"52}53}54}55]56[END OF AVAILABLE TOOLS]5758[BEGIN OF FORMAT INSTRUCTION]59Your output should be in the JSON format, which specifies a list of function calls. The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make tool_calls an empty list '[]'.
60```{"thought":"the thought process, or an empty string","tool_calls":[{"name":"api_name1","arguments":{"argument1":"value1","argument2":"value2"}}]}```
61[END OF FORMAT INSTRUCTION]6263[BEGIN OF QUERY]64User: Can you give me the latest information on the wildfires occurring in California?
65[END OF QUERY]6667[BEGIN OF HISTORY STEPS]68[69{70"thought":"Sure, what is the radius (in miles) around the location of the wildfire?",71"tool_calls":[],72"step_id":1,73"next_observation":"",74"user_input":"User: Let me think... 50 miles."75},76{77"thought":"",78"tool_calls":[79{80"name":"get_fire_info",81"arguments":{82"location":"California",83"radius":5084}85}86],87"step_id":2,88"next_observation":[89{90"location":"Los Angeles",91"acres_burned":1500,92"status":"contained"93},94{95"location":"San Diego",96"acres_burned":12000,97"status":"active"98}99]100},101{102"thought":"Based on the latest information, there are wildfires in Los Angeles and San Diego. The wildfire in Los Angeles has burned 1,500 acres and is contained, while the wildfire in San Diego has burned 12,000 acres and is still active.",103"tool_calls":[],104"step_id":3,105"next_observation":"",106"user_input":"User: Can you tell me about the latest earthquake?"107}108]109110[END OF HISTORY STEPS]
Note: Bold and Underline results denote the best result and the second best result for Success Rate, respectively.
Berkeley Function-Calling Leaderboard (BFCL)
xlam-bfcl
Table 1: Performance comparison on BFCL-v2 leaderboard (cutoff date 09/03/2024). The rank is based on the overall accuracy, which is a weighted average of different evaluation categories. "FC" stands for function-calling mode in contrast to using a customized "prompt" to extract the function calls.
Webshop and ToolQuery
xlam-webshop_toolquery
Table 2: Testing results on Webshop and ToolQuery. Bold and Underline results denote the best result and the second best result for Success Rate, respectively.
Unified ToolQuery
xlam-unified_toolquery
Table 3: Testing results on ToolQuery-Unified. Bold and Underline results denote the best result and the second best result for Success Rate, respectively. Values in brackets indicate corresponding performance on ToolQuery
ToolBench
xlam-toolbench
Table 4: Pass Rate on ToolBench on three distinct scenarios. Bold and Underline results denote the best result and the second best result for each setting, respectively. The results for xLAM-8x22b-r are unavailable due to the ToolBench server being down between 07/28/2024 and our evaluation cutoff date 09/03/2024.
License
The model is distributed under the CC-BY-NC-4.0 license.
Ethical Considerations
This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people’s lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
Citation
If you find this repo helpful, please consider to cite our papers:
bibtex
1@article{zhang2024xlam,
2 title={xLAM: A Family of Large Action Models to Empower AI Agent Systems},
3 author={Zhang, Jianguo and Lan, Tian and Zhu, Ming and Liu, Zuxin and Hoang, Thai and Kokane, Shirley and Yao, Weiran and Tan, Juntao and Prabhakar, Akshara and Chen, Haolin and others},
4 journal={arXiv preprint arXiv:2409.03215},
5 year={2024}
6}
bibtex
1@article{liu2024apigen,
2 title={Apigen: Automated pipeline for generating verifiable and diverse function-calling datasets},
3 author={Liu, Zuxin and Hoang, Thai and Zhang, Jianguo and Zhu, Ming and Lan, Tian and Kokane, Shirley and Tan, Juntao and Yao, Weiran and Liu, Zhiwei and Feng, Yihao and others},
4 journal={arXiv preprint arXiv:2406.18518},
5 year={2024}
6}
bixtex
1@article{zhang2025actionstudio,
2 title={ActionStudio: A Lightweight Framework for Data and Training of Action Models},
3 author={Zhang, Jianguo and Hoang, Thai and Zhu, Ming and Liu, Zuxin and Wang, Shiyu and Awalgaonkar, Tulika and Prabhakar, Akshara and Chen, Haolin and Yao, Weiran and Liu, Zhiwei and others},
4 journal={arXiv preprint arXiv:2503.22673},
5 year={2025}
6}
bibtex
1@article{zhang2024agentohana,
2 title={AgentOhana: Design Unified Data and Training Pipeline for Effective Agent Learning},
3 author={Zhang, Jianguo and Lan, Tian and Murthy, Rithesh and Liu, Zhiwei and Yao, Weiran and Tan, Juntao and Hoang, Thai and Yang, Liangwei and Feng, Yihao and Liu, Zuxin and others},
4 journal={arXiv preprint arXiv:2402.15506},
5 year={2024}
6}