ModelScope-Agent: Building Your Customizable Agent System with Open-source Large Language Models

Chenliang Li, He Chen, Ming Yan, Weizhou Shen, Haiyang Xu, Zhikai Wu, Zhicheng Zhang, Wenmeng Zhou, Yingda Chen, Chen Cheng, Hongzhu Shi, Ji Zhang, Fei Huang, Jingren Zhou

Abstract

Large language models (LLMs) have recently demonstrated remarkable capabilities to comprehend human intentions, engage in reasoning, and design planning-like behavior. To further unleash the power of LLMs to accomplish complex tasks, there is a growing trend to build agent frameworks that equip LLMs with tool-use abilities to connect with massive external APIs. In this work, we introduce ModelScope-Agent, a general and customizable agent framework for real-world applications based on open-source LLMs as controllers. It provides a user-friendly system library with a customizable engine design to support model training on multiple open-source LLMs while enabling seamless integration with both model APIs and common APIs. We propose a comprehensive framework spanning tool-use data collection, retrieval, registration, memory control, customized training, and evaluation. Finally, we showcase ModelScopeGPT, an intelligent assistant connecting open-source LLMs with over 1,000 public AI models and localized community knowledge.

Introduction: Breaking the LLM Isolation

While frontier models like GPT-4 exhibit incredible reasoning, they are often isolated from the real world, limited to their training data and unable to perform physical or digital actions without external tools. Existing agent frameworks, such as Auto-GPT or LangChain, are frequently optimized for closed-source APIs. For developers seeking to build private, cost-effective, or highly customizable agents using open-source models (like LLaMA or ChatGLM), the path is fraught with challenges. Open-source models often struggle with the precision required for "tool-use"—specifically, following complex instructions to format API calls correctly and managing multi-turn dialogues involving planning, acting, and observing.

System Architecture

ModelScope-Agent adopts a modular "LLM-as-Brain" architecture designed to bridge the gap between reasoning and execution. The system consists of three primary components:

  1. Controller (The Brain): An open-source LLM fine-tuned to plan tasks and select appropriate tools based on user intent.
  2. Tool-use Module: A comprehensive library supporting "Model APIs" (e.g., image generation, translation) and "Common APIs" (e.g., weather, search). It utilizes a Tool Retrieval mechanism based on vector search to select the top-3 most relevant tools, preventing prompt congestion.
  3. Memory Control: This module manages conversation history and employs Retrieval-Augmented Generation (RAG) to incorporate localized knowledge or specific user context into the agent's reasoning process.
The ModelScope-Agent framework overview, illustrating the training framework, execution pipeline, and system modules.

Training Strategy: Weighted LM

A core innovation of this framework is the Weighted LM training strategy. Standard fine-tuning treats all tokens equally, but for an agent, functional accuracy is paramount. The authors assign a weight of 0 to the user prompt (to avoid learning to predict the user), a weight of 1 to standard text, and a weight of 2 to critical API components (such as API names and parameters). This weighting forces the model to prioritize precision in the functional calls that drive external tools.

The MSAgent-Bench Dataset

To train effective agents, the authors introduced MSAgent-Bench, a massive dataset designed to bridge the gap between conversation and action.

  • Scale and Diversity: It contains 598,000 dialogues, significantly larger than previous benchmarks. It includes multi-turn API calls, API-oriented QA (explaining tool usage), and "API-Agnostic" instructions (general chit-chat).
  • Multilingual Support: The dataset supports both English and Chinese.
  • Negative Data: By including API-Agnostic instructions, the framework prevents the model from "over-fitting" to tool use, ensuring it doesn't force an API call when a simple text answer is more appropriate.
Composition of the MSAgent-Bench dataset, showcasing the variety of Model APIs, Common APIs, and instruction types used for training.

Key Results and Insights

The evaluation utilized a new metric, Argument F1, which penalizes models for incorrect API parameters even if the correct tool is selected.

  • Open-Source Superiority: A specialized 7B parameter model (MSAgent-7B) achieved an Action Exact Match (EM) score of 87.23, vastly outperforming LLaMA (58.60) and even 2-shot ChatGPT (34.82) on the benchmark. This suggests that data quality and specialized training can allow smaller open-source models to exceed the performance of closed-source giants in specific agentic tasks.
  • Zero-Shot Generalization: The framework supports a "Register and Use" flow. Because the model learns the underlying logic of API calling, it can often use a brand-new API correctly simply by being provided its schema in the prompt.
  • Real-World Validation: The framework powers ModelScopeGPT, which connects to over 1,000 AI models. Within its first month, it handled over 170,000 requests from 40,000 unique users, demonstrating production-grade stability.

Conclusion and Future Work

ModelScope-Agent demonstrates that open-source LLMs can serve as highly effective controllers for complex agent systems. While the current version focuses on a "plan-then-act" flow, future iterations will explore more iterative architectures like ReAct and the integration of dedicated code interpreters for complex data processing. The team also plans to expand the framework to support specialized sub-agents for niche tasks like motion and storytelling, further pushing the boundaries of customizable AI agents.

Summary updated

BibTeX
@inproceedings{li2023modelscope,
  author = {Chenliang Li and He Chen and Ming Yan and Weizhou Shen and Haiyang Xu and Zhikai Wu and Zhicheng Zhang and Wenmeng Zhou and Yingda Chen and Chen Cheng and Hongzhu Shi and Ji Zhang and Fei Huang and Jingren Zhou},
  title = {{ModelScope-Agent: Building Your Customizable Agent System with Open-source Large Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=FxIqO8OidK},
}
Figure