### Setup and Export DOCX
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/docx-js.md
Import necessary components from the 'docx' library and export the document to a buffer for Node.js or a blob for the browser. Ensure 'docx' is installed globally.
```javascript
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun, Media,
Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,
InternalHyperlink, TableOfContents, HeadingLevel, BorderStyle, WidthType, TabStopType,
TabStopPosition, UnderlineType, ShadingType, VerticalAlign, SymbolRun, PageNumber,
FootnoteReferenceRun, Footnote, PageBreak } = require('docx');
// Create & Save
const doc = new Document({ sections: [{ children: [/* content */] }] });
Packer.toBuffer(doc).then(buffer => fs.writeFileSync("doc.docx", buffer)); // Node.js
Packer.toBlob(doc).then(blob => { /* download logic */ }); // Browser
```
--------------------------------
### Install MS-Agent from Source
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/GetStarted/Installation.md
Install MS-Agent by cloning the repository and installing it in editable mode. This method is useful for developers or when needing the latest changes.
```shell
git clone https://github.com/modelscope/ms-agent.git
cd ms-agent
pip install -e .
```
--------------------------------
### Install FinResearch with Python Environment
Source: https://github.com/modelscope/ms-agent/blob/main/projects/fin_research/README.md
Steps to set up the Python environment and install the ms-agent package with research dependencies from PyPI or source code.
```bash
git clone https://github.com/modelscope/ms-agent.git
cd ms-agent
conda create -n fin_research python=3.11
conda activate fin_research
# From PyPI (>=v1.5.0)
pip install 'ms-agent[research]'
# From source code
pip install -r requirements/framework.txt
pip install -r requirements/research.txt
pip install -e .
# Data Interface Dependencies
pip install akshare baostock
```
--------------------------------
### Run MS-Agent WebUI on Custom Port
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
Example of starting the MS-Agent WebUI on a custom port (e.g., 8080).
```bash
ms-agent ui --port 8080
```
--------------------------------
### Install and Run Pre-commit Hooks
Source: https://github.com/modelscope/ms-agent/blob/main/CONTRIBUTING.md
Commands to install and execute pre-commit hooks for linting, along with instructions for committing changes with or without verification.
```shell
# for the first time please run the following command to install pre-commit hooks
pip install pre-commit
pre-commit install
pre-commit run --all-files
# In the rest of the time, you could just run normal git commit to activate lint revised
git add .
git commit -m "add new tool"
# if you want to skip the lint check, you could use the following command
git commit -m "add new tool" --no-verify
```
--------------------------------
### Install MS-Agent using Pip
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/GetStarted/Installation.md
Install the MS-Agent library using pip. This is the recommended method for most users.
```shell
pip install ms-agent
```
--------------------------------
### Install ms-enclave and Build Jupyter Image
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/FinResearch.md
Install the ms-enclave package and build the Docker image for the Jupyter sandbox environment. Ensure Docker and related dependencies are installed.
```bash
pip install ms-enclave docker websocket-client # https://github.com/modelscope/ms-enclave
bash projects/fin_research/tools/build_jupyter_image.sh
```
--------------------------------
### Install Deep Research
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/DeepResearch.md
Instructions for installing the project from source or via PyPI.
```bash
# Install from source
git clone https://github.com/modelscope/ms-agent.git
cd ms-agent
pip install -r requirements/research.txt
pip install -e .
# Install via PyPI (≥v1.1.0)
pip install 'ms-agent[research]'
```
--------------------------------
### Initialize AutoSkills
Source: https://github.com/modelscope/ms-agent/blob/main/ms_agent/skill/README.md
Basic setup for using the AutoSkills component directly.
```python
import asyncio
from ms_agent.skill import AutoSkills
from ms_agent.llm import LLM
from omegaconf import DictConfig
```
--------------------------------
### Install Agentic Insight from Source
Source: https://github.com/modelscope/ms-agent/blob/main/projects/deep_research/README.md
Installs the Agentic Insight framework from source code. Ensure you have git and pip installed.
```bash
git clone https://github.com/modelscope/ms-agent.git
pip install -r requirements/research.txt
pip install -e .
```
--------------------------------
### Setup Python Environment for FinResearch
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/FinResearch.md
Commands to clone the repository, configure the conda environment, and install necessary dependencies for the FinResearch project.
```bash
# Download source code
git clone https://github.com/modelscope/ms-agent.git
cd ms-agent
# Python environment setup
conda create -n fin_research python=3.11
conda activate fin_research
# From PyPI (>=v1.5.0)
pip install 'ms-agent[research]'
# From source code
pip install -r requirements/framework.txt
pip install -r requirements/research.txt
pip install -e .
# Data Interface Dependencies
pip install akshare baostock
```
--------------------------------
### Video Generation Input Examples
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/VideoGeneration.md
Examples of input prompts for generating videos, either via direct text or by referencing a local file.
```text
Generate a short video describing GDP-related economics knowledge, about 3 minutes long.
```
```text
Generate a short video describing large-model technologies. Read /home/user/llm.txt for details.
```
--------------------------------
### Example: PDF Report Generation
Source: https://github.com/modelscope/ms-agent/blob/main/docs/zh/Components/agent-skills.md
A practical example demonstrating how to use AutoSkills to generate a PDF report.
```APIDOC
## Example: Generate PDF Report
### Description
This example shows how to use the `AutoSkills` class to generate a PDF report based on a query.
### Code Example
```python
import asyncio
from ms_agent.skill import AutoSkills
from ms_agent.llm import LLM
async def generate_pdf_report():
# Assuming 'config' is a pre-defined LLM configuration object
# Example: config = DictConfig({'llm': {'service': 'openai', ...}})
llm = LLM.from_config(config)
auto_skills = AutoSkills(
skills='/path/to/skills', # Path to your skills directory
llm=llm,
work_dir='/tmp/reports' # Directory to save generated reports
)
result = await auto_skills.run(
query='Generate a PDF report analyzing Q4 2024 sales data with charts'
)
if result.execution_result and result.execution_result.success:
for skill_id, skill_result in result.execution_result.results.items():
if skill_result.output.output_files:
print(f"Generated files: {skill_result.output.output_files}")
asyncio.run(generate_pdf_report())
```
```
--------------------------------
### Install Code Genesis Dependencies
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/CodeGenesis.md
Clone the repository and install Python and npm dependencies. Ensure Node.js is installed separately.
```bash
git clone https://github.com/modelscope/ms-agent
cd ms-agent
pip install -r requirements/code.txt
pip install -e .
```
```bash
npm --version
```
--------------------------------
### Run MS-Agent WebUI in Production Mode
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
Example of starting the MS-Agent WebUI in production mode and disabling the auto-opening of the browser.
```bash
ms-agent ui --production --no-browser
```
--------------------------------
### Install ms-agent Dependencies
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/multimodal-support.md
Ensure you have the necessary dependencies installed using pip.
```bash
pip install openai
```
--------------------------------
### Agent Configuration Example (agent.yaml)
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Example YAML configuration for the agent's skills module. This defines paths, retrieval arguments, retry attempts, and sandbox settings.
```yaml
skills:
# Required: Path to skills directory or ModelScope repo ID
path: /path/to/skills
# Optional: Whether to enable retriever (auto-detect based on skill count if omitted)
enable_retrieve:
# Optional: Retriever arguments
retrieve_args:
top_k: 3
min_score: 0.8
# Optional: Maximum candidate skills to consider (default: 10)
max_candidate_skills: 10
# Optional: Maximum retry attempts (default: 3)
max_retries: 3
# Optional: Working directory for outputs
work_dir: /path/to/workspace
# Optional: Use Docker sandbox for execution (default: True)
use_sandbox: false
# Optional: Auto-execute skills (default: True)
auto_execute: true
```
--------------------------------
### Install MS-Agent from PyPI
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
Install the basic functionalities of ms-agent using pip. For advanced research features, install with the 'research' extra.
```shell
# For the basic functionalities
pip install ms-agent
# For the deep research functionalities
pip install 'ms-agent[research]'
```
--------------------------------
### Project Directory Structure
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/Tools.md
Example layout for organizing custom tool files relative to the agent configuration.
```text
agent.yaml
tools
|--custom_tool.py
```
--------------------------------
### Redlining workflow example
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/SKILL.md
Placeholder for the redlining workflow example.
```python
```
--------------------------------
### Configure Environment Variables
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/DeepResearch.md
Setup steps for configuring search engine API keys and model endpoints in the .env file.
```bash
# Edit the `.env` file to include the API key for the desired search engine
cp .env.example .env
# Use Exa search configuration as follows (register at https://exa.ai, free credits upon registration):
EXA_API_KEY=your_exa_api_key
# Use SerpApi search configuration as follows (register at https://serpapi.com, free credits monthly):
SERPAPI_API_KEY=your_serpapi_api_key
# Additional configuration is required for the extended version (ResearchWorkflowBeta).
# Extended version (ResearchWorkflowBeta) employs a more stable model (e.g., gemini-2.5-flash) during the query rewriting phase.
# OpenAI API key (OPENAI_API_KEY) and base URL (OPENAI_BASE_URL) must be set to use the compatible endpoint.
```
--------------------------------
### Sync Delegation Example (SOP)
Source: https://github.com/modelscope/ms-agent/blob/main/ms-agent-skills/references/agent-delegate.md
Example of synchronous delegation, suitable for shorter tasks where immediate results are needed. Specifies the query, available tools, and maximum execution rounds.
```python
delegate_task(query="...", tools="web_search", max_rounds=15)
```
--------------------------------
### Launch FinResearch Application
Source: https://github.com/modelscope/ms-agent/blob/main/projects/fin_research/README.md
Starts the Gradio service via CLI or Python script.
```bash
# Launch the Gradio service via command line (you can start without additional arguments, specifying only --app_type fin_research)
ms-agent app --app_type fin_research --server_name 0.0.0.0 --server_port 7860 --share
# Alternatively, launch the Gradio service by running a Python script
cd ms-agent/app
python fin_research.py
```
--------------------------------
### META.yaml Format Example
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Example of a META.yaml file used for defining agent or skill metadata. This includes name, description, version, author, and tags.
```yaml
name: "PDF Generator"
description: "Generates professional PDF documents from markdown or data"
version: "1.0.0"
author: "Your Name"
tags:
- document
- pdf
- report
```
--------------------------------
### Execution Commands
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/VideoGeneration.md
Example commands to run ms-agent with overridden configurations for different query types.
```bash
# For the English version, replace the query content with:
# "Convert /home/user/workspace/ms-agent/projects/singularity_cinema/test_files/J.部署.md
# into a short video in a blue-themed style, making sure to use the important images from the document.
# The short video must be in English."
ms-agent run --project singularity_cinema \
--query "把/{path_to_ms-agent}/projects/singularity_cinema/test_files/J.部署.md转为短视频,蓝色风格,注意使用其中重要的图片" \
--trust_remote_code true \
--openai_base_url https://api.anthropic.com/v1/ \
--llm.model claude-sonnet-4-5 \
--openai_api_key {your_api_key_of_anthropic} \
--mllm_openai_base_url https://generativelanguage.googleapis.com/v1beta/openai/ \
--mllm_openai_api_key {your_api_key_of_gemini} \
--mllm_model gemini-3-pro-preview \
--image_generator.api_key {your_api_key_of_gemini} \
--image_generator.type google \
--image_generator.model gemini-3-pro-image-preview
```
```bash
ms-agent run --project singularity_cinema \
--query "Please create a short video introducing the Silk Road, with a consistent visual style." \
--trust_remote_code true \
--openai_base_url https://api.anthropic.com/v1/ \
--llm.model claude-sonnet-4-5 \
--openai_api_key {your_api_key_of_anthropic} \
--mllm_openai_base_url https://generativelanguage.googleapis.com/v1beta/openai/ \
--mllm_openai_api_key {your_api_key_of_gemini} \
--mllm_model gemini-3-pro-preview \
--image_generator.api_key {your_api_key_of_gemini} \
--image_generator.type google \
--image_generator.model gemini-3-pro-image-preview
```
--------------------------------
### Install LibreOffice dependency
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/SKILL.md
Required for PDF conversion.
```bash
sudo apt-get install libreoffice
```
--------------------------------
### Install docx dependency
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/SKILL.md
Required for creating new documents.
```bash
npm install -g docx
```
--------------------------------
### Configure LLM API Keys
Source: https://github.com/modelscope/ms-agent/blob/main/projects/singularity_cinema/README_EN.md
Runtime parameters for configuring the LLM backend, using Gemini as an example.
```shell
--llm.openai_base_url https://generativelanguage.googleapis.com/v1beta/openai/ \
--llm.model gemini-3-pro \
--llm.openai_api_key {your_api_key_of_openai_base_url} \
```
--------------------------------
### Example: Redo Animation of Segment 1
Source: https://github.com/modelscope/ms-agent/blob/main/projects/singularity_cinema/README_EN.md
Demonstrates how to regenerate specific parts of the pipeline by deleting intermediate files and rerunning the process. This example focuses on redoing the animation for Segment 1.
```text
- remotion_code/Segment1.tsx (segment 1 animation code)
- remotion_render/scene_1/Scene1.mov (rendered output from that code)
- final_video.mp4 (final composition depends on the render result, so it must be recomposed)
```
--------------------------------
### Configure Text-to-Image Model Keys
Source: https://github.com/modelscope/ms-agent/blob/main/projects/singularity_cinema/README_EN.md
Runtime parameters for configuring the image generation backend, using ModelScope's Qwen model as an example.
```shell
--image_generator.api_key {your_modelscope_api_key} \
--image_generator.type modelscope \
--image_generator.model Qwen/Qwen-Image-2512 \
```
--------------------------------
### Usage Example: Multi-Skill Pipeline
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Illustrates creating a presentation by chaining multiple skills using AutoSkills.
```APIDOC
## Example 2: Multi-Skill Pipeline
### Description
This example demonstrates how to create a presentation by orchestrating multiple skills, such as data analysis, chart generation, and presentation creation, using `AutoSkills`.
### Code
```python
import asyncio
from ms_agent.skill import AutoSkills
async def create_presentation():
# Assume llm is defined elsewhere
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/tmp/presentation'
)
# This query might trigger multiple skills working together:
# 1. data-analysis skill to process data
# 2. chart-generator skill to create visualizations
# 3. pptx skill to create the presentation
result = await auto_skills.run(
query='Create a presentation about AI market trends with data visualizations'
)
print(f"Execution order: {result.execution_order}")
for skill_id in result.execution_order:
if isinstance(skill_id, str):
context = auto_skills.get_skill_context(skill_id)
if context and context.plan:
print(f"{skill_id}: {context.plan.plan_summary}")
asyncio.run(create_presentation())
```
```
--------------------------------
### Start MS-Agent WebUI
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
Command to launch the MS-Agent WebUI. The browser will automatically open at http://localhost:7860.
```bash
ms-agent ui
```
--------------------------------
### Usage Example: Custom Input Execution
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Shows how to execute a DAG with custom input parameters using AutoSkills.
```APIDOC
## Example 3: Custom Input Execution
### Description
This example demonstrates how to execute a skill DAG with custom input, such as specifying input files and environment variables, using `AutoSkills`.
### Code
```python
import asyncio
from ms_agent.skill import AutoSkills
from ms_agent.skill.container import ExecutionInput
async def execute_with_custom_input():
# Assume llm is defined elsewhere
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/tmp/custom'
)
dag_result = await auto_skills.get_skill_dag(
query='Convert my document to PDF'
)
custom_input = ExecutionInput(
input_files={'document.md': '/path/to/my/document.md'},
env_vars={'OUTPUT_FORMAT': 'A4', 'MARGINS': '1in'}
)
exec_result = await auto_skills.execute_dag(
dag_result=dag_result,
execution_input=custom_input,
query='Convert my document to PDF'
)
print(f"Success: {exec_result.success}")
asyncio.run(execute_with_custom_input())
```
```
--------------------------------
### Usage Example: PDF Report Generation
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Demonstrates how to use AutoSkills to generate a PDF report by processing sales data.
```APIDOC
## Example 1: PDF Report Generation
### Description
This example shows how to use the `AutoSkills` class to generate a PDF report based on sales data.
### Code
```python
import asyncio
from ms_agent.skill import AutoSkills
from ms_agent.llm import LLM
async def generate_pdf_report():
# Assume llm and config are defined elsewhere
llm = LLM.from_config(config)
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/tmp/reports'
)
result = await auto_skills.run(
query='Generate a PDF report analyzing Q4 2024 sales data with charts'
)
if result.execution_result and result.execution_result.success:
for skill_id, skill_result in result.execution_result.results.items():
if skill_result.output.output_files:
print(f"Generated files: {skill_result.output.output_files}")
asyncio.run(generate_pdf_report())
```
```
--------------------------------
### OOXML Text Formatting Examples
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/ooxml.md
Demonstrates XML structures for applying bold, italic, underline, and highlight formatting to text runs.
```xml
Bold
Italic
Underlined
Highlighted
```
--------------------------------
### Async Delegation Example (SOP)
Source: https://github.com/modelscope/ms-agent/blob/main/ms-agent-skills/references/agent-delegate.md
Example of asynchronous delegation, suitable for long-running tasks. Initiates the task and specifies tools and maximum rounds. Subsequent calls to check and get results are implied.
```python
submit_agent_task(query="...", tools="web_search,file_system,todo_list", max_rounds=20)
```
--------------------------------
### Example: Multi-Skill Pipeline for Presentation Creation
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Illustrates creating a presentation by running a complex query that may involve multiple skills. It prints the execution order and skill plan summaries.
```python
async def create_presentation():
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/tmp/presentation'
)
# This query might trigger multiple skills working together:
# 1. data-analysis skill to process data
# 2. chart-generator skill to create visualizations
# 3. pptx skill to create the presentation
result = await auto_skills.run(
query='Create a presentation about AI market trends with data visualizations'
)
print(f"Execution order: {result.execution_order}")
for skill_id in result.execution_order:
if isinstance(skill_id, str):
context = auto_skills.get_skill_context(skill_id)
if context and context.plan:
print(f"{skill_id}: {context.plan.plan_summary}")
asyncio.run(create_presentation())
```
--------------------------------
### Initialize Docker daemon
Source: https://github.com/modelscope/ms-agent/blob/main/ms_agent/skill/README.md
Basic instructions for setting up the Docker daemon for sandbox execution.
```text
# Install docker daemon
# Run the daemon service
```
--------------------------------
### Initialize Web Search Engine Client
Source: https://github.com/modelscope/ms-agent/blob/main/docs/zh/Projects/deep-research.md
Set up a web search engine tool for the agent. Provide the path to your configuration file; if not specified, it defaults to 'conf.yaml' in the current directory.
```python
search_engine = get_web_search_tool(config_file='conf.yaml')
```
--------------------------------
### Initialize Web Search Tool
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/deep-research.md
Instantiate a web search tool client. The configuration file path should be specified; it defaults to 'conf.yaml' if not provided.
```python
# Get web-search engine client
# Please specify your config file path, the default is `conf.yaml` in the current directory.
search_engine = get_web_search_tool(config_file='conf.yaml')
```
--------------------------------
### Clone ms-agent Repository
Source: https://github.com/modelscope/ms-agent/blob/main/projects/code_genesis/README.md
Clone the ms-agent repository to your local machine. This is the initial step to get started with the Code Genesis project.
```shell
git clone https://github.com/modelscope/ms-agent
cd ms-agent
```
--------------------------------
### Example: Generate PDF Report using AutoSkills
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Demonstrates generating a PDF report by initializing AutoSkills and running a query. It checks for successful execution and prints generated file names.
```python
import asyncio
from ms_agent.skill import AutoSkills
from ms_agent.llm import LLM
async def generate_pdf_report():
llm = LLM.from_config(config)
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/tmp/reports'
)
result = await auto_skills.run(
query='Generate a PDF report analyzing Q4 2024 sales data with charts'
)
if result.execution_result and result.execution_result.success:
for skill_id, skill_result in result.execution_result.results.items():
if skill_result.output.output_files:
print(f"Generated files: {skill_result.output.output_files}")
asyncio.run(generate_pdf_report())
```
--------------------------------
### Submit Research Task JSON Response
Source: https://github.com/modelscope/ms-agent/blob/main/ms-agent-skills/references/deep-research.md
Example JSON response when submitting a research task, indicating the task has started and providing a task ID.
```json
{
"task_id": "a1b2c3d4",
"status": "running",
"output_dir": "/path/to/output/deep_research_20260318_143000",
"message": "Research task a1b2c3d4 started. Use check_research_progress..."
}
```
--------------------------------
### Example: Execute DAG with Custom Input
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Shows how to execute a DAG with custom input, including input files and environment variables. This is useful for providing specific data or configurations to skills.
```python
from ms_agent.skill.container import ExecutionInput
async def execute_with_custom_input():
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/tmp/custom'
)
dag_result = await auto_skills.get_skill_dag(
query='Convert my document to PDF'
)
custom_input = ExecutionInput(
input_files={'document.md': '/path/to/my/document.md'},
env_vars={'OUTPUT_FORMAT': 'A4', 'MARGINS': '1in'}
)
exec_result = await auto_skills.execute_dag(
dag_result=dag_result,
execution_input=custom_input,
query='Convert my document to PDF'
)
print(f"Success: {exec_result.success}")
asyncio.run(execute_with_custom_input())
```
--------------------------------
### Get Research Report JSON Response
Source: https://github.com/modelscope/ms-agent/blob/main/ms-agent-skills/references/deep-research.md
Example JSON response when retrieving a completed research report, including status, report path, and content.
```json
{
"task_id": "a1b2c3d4",
"status": "completed",
"report_path": "/path/to/final_report.md",
"report_content": "# Research Report\n\n...",
"truncated": false
}
```
--------------------------------
### Build Documentation
Source: https://github.com/modelscope/ms-agent/blob/main/docs/README.md
Run this command in the root directory of ms-agent to build the documentation.
```shell
# in root directory of ms-agent:
make docs
```
--------------------------------
### Install MS-Agent using pip
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Install the MS-Agent package using pip. Ensure you have Python 3.9+ installed.
```bash
pip install 'ms-agent>=1.4.0'
```
--------------------------------
### AutoSkills Initialization and Execution
Source: https://github.com/modelscope/ms-agent/blob/main/docs/zh/Components/agent-skills.md
Demonstrates how to initialize AutoSkills with LLM configuration and execute a query.
```APIDOC
## POST /modelscope/ms-agent/autoskills/run
### Description
Executes a given query using the AutoSkills framework, which involves skill retrieval, analysis, and execution.
### Method
POST
### Endpoint
/modelscope/ms-agent/autoskills/run
### Parameters
#### Request Body
- **query** (string) - Required - The user's query to be processed by the agent.
- **skills** (string | List[string] | List[SkillSchema]) - Required - Specifies the source of skills. Can be local directory paths, ModelScope skill IDs, or SkillSchema objects.
- **llm** (LLM) - Required - The Language Model configuration to be used for skill analysis and execution.
- **work_dir** (string) - Optional - The working directory for skill execution outputs.
- **use_sandbox** (boolean) - Optional - Whether to use a Docker sandbox for execution. Defaults to True.
- **auto_execute** (boolean) - Optional - Whether to automatically execute the skills. Defaults to True.
### Request Example
```json
{
"query": "Generate a mock PDF report about AI trends",
"skills": "/path/to/skills",
"llm": {
"service": "openai",
"model": "gpt-4",
"openai_api_key": "your-api-key",
"openai_base_url": "https://api.openai.com/v1"
},
"work_dir": "/path/to/workspace",
"use_sandbox": false
}
```
### Response
#### Success Response (200)
- **execution_result** (object) - The result of the skill execution.
- **success** (boolean) - Indicates if the execution was successful.
- **results** (object) - A dictionary containing results for each executed skill.
- **skill_id** (object) - Result for a specific skill.
- **output** (object) - The output of the skill execution.
- **output_files** (List[string]) - List of files generated by the skill.
#### Response Example
```json
{
"execution_result": {
"success": true,
"results": {
"skill_1_id": {
"output": {
"output_files": ["report.pdf"]
}
}
}
}
}
```
```
--------------------------------
### Initialize and Run LLMAgent
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Initialize an LLMAgent with a configuration object and run a task. The configuration specifies LLM details and skill settings.
```python
import asyncio
from omegaconf import DictConfig
from ms_agent.agent import LLMAgent
config = DictConfig({
'llm': {
'service': 'openai',
'model': 'gpt-4',
'openai_api_key': 'your-api-key',
'openai_base_url': 'https://api.openai.com/v1'
},
'skills': {
'path': '/path/to/skills',
'auto_execute': True,
'work_dir': '/path/to/workspace',
'use_sandbox': False,
}
})
agent = LLMAgent(config, tag='skill-agent')
async def main():
result = await agent.run('Generate a mock PDF report about AI trends')
print(result)
asyncio.run(main())
```
--------------------------------
### Install Agentic Insight from PyPI
Source: https://github.com/modelscope/ms-agent/blob/main/projects/deep_research/README.md
Installs the Agentic Insight framework from PyPI. This command installs the research extra, which includes necessary dependencies for research tasks.
```bash
pip install 'ms-agent[research]'
```
--------------------------------
### Run FinResearch Quick Start
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/FinResearch.md
Execute the FinResearch workflow for testing by running the CLI command from the ms-agent project root. This command includes a sample query for analyzing CATL stock.
```bash
# Run from the ms-agent project root
PYTHONPATH=. python ms_agent/cli/cli.py run \
--config projects/fin_research \
--query "Analyze CATL (300750.SZ): changes in profitability over the last four quarters and comparison with major competitors in the new energy sector; factoring in industrial policy and lithium price fluctuations, forecast the next two quarters."
--trust_remote_code true
```
--------------------------------
### Verify ms-agent Installation
Source: https://github.com/modelscope/ms-agent/blob/main/ms-agent-skills/SKILL.md
Run this script to check if ms-agent is installed on your system.
```bash
python scripts/check_ms_agent.py
```
--------------------------------
### Initialize and Execute MS-Agent
Source: https://github.com/modelscope/ms-agent/blob/main/ms_agent/skill/README.md
Configures the LLM service and executes a query using the AutoSkills component.
```python
llm_config = DictConfig({
'llm': {
'service': 'openai',
'model': 'gpt-4',
'openai_api_key': 'your-api-key',
'openai_base_url': 'https://api.openai.com/v1'
}
})
llm = LLM.from_config(llm_config)
# Initialize AutoSkills
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/path/to/workspace',
use_sandbox=False,
)
async def main():
# Execute skills
result = await auto_skills.run(
query='Generate a mock PDF report about AI trends'
)
print(f">>final result: {result.execution_result}")
asyncio.run(main())
```
--------------------------------
### Clone and Install Singularity Cinema
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Projects/VideoGeneration.md
Commands to clone the repository and install the necessary Python dependencies.
```bash
git clone https://github.com/modelscope/ms-agent.git
cd ms-agent
```
```bash
pip install .
cd projects/singularity_cinema
pip install -r requirements.txt
```
--------------------------------
### Configure Environment Variables for Search Engines
Source: https://github.com/modelscope/ms-agent/blob/main/projects/deep_research/README.md
Sets up environment variables for search engine API keys. Copy the example file and edit it with your specific API keys for Exa or SerpApi. This is necessary for enabling broader web search capabilities.
```bash
# From projects/deep_research/
cp .env.example .env
# Then, edit `.env` to include the API key for the search engine you choose:
# If using Exa (register at https://exa.ai, free quota available):
EXA_API_KEY=your_exa_api_key
# If using SerpApi (register at https://serpapi.com, free quota available):
SERPAPI_API_KEY=your_serpapi_api_key
# If you are using DeepResearch variant (ResearchWorkflowBeta), **search-query rewriting** is pinned to a stable model (e.g., **gemini-2.5-flash**) for reliability.
# An OpenAI-compatible base URL (`OPENAI_BASE_URL`) and API key (`OPENAI_API_KEY`) are required. To switch models, replace the pinned name in `ResearchWorkflowBeta.generate_search_queries` with any model served by your configured endpoint.
OPENAI_API_KEY=your_api_key
OPENAI_BASE_URL=https://your-openai-compatible-endpoint/v1
```
--------------------------------
### Install Older MS-Agent Versions
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
For versions v0.8.0 or earlier, install using 'modelscope-agent'. This command is for compatibility with older project names.
```shell
pip install modelscope-agent<=0.8.0
```
--------------------------------
### Initialize and Run AutoSkills
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/AgentSkills.md
Initialize AutoSkills with an LLM instance and configuration, then run a query. This method directly uses the AutoSkills class for skill execution.
```python
import asyncio
from ms_agent.skill import AutoSkills
from ms_agent.llm import LLM
from omegaconf import DictConfig
llm_config = DictConfig({
'llm': {
'service': 'openai',
'model': 'gpt-4',
'openai_api_key': 'your-api-key',
'openai_base_url': 'https://api.openai.com/v1'
}
})
llm = LLM.from_config(llm_config)
auto_skills = AutoSkills(
skills='/path/to/skills',
llm=llm,
work_dir='/path/to/workspace',
use_sandbox=False,
)
async def main():
result = await auto_skills.run(
query='Generate a mock PDF report about AI trends'
)
print(f"Result: {result.execution_result}")
asyncio.run(main())
```
--------------------------------
### Start MS-Agent WebUI with PowerShell on Windows
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
Use this PowerShell command on Windows if the console shows garbled text when starting the MS-Agent WebUI.
```powershell
webui/scripts/start-webui.ps1
```
--------------------------------
### Install Sandbox Dependencies for FinResearch
Source: https://github.com/modelscope/ms-agent/blob/main/projects/fin_research/README.md
Installs the necessary Python packages for sandboxed code execution using Docker, including ms-enclave, docker, and websocket-client.
```bash
pip install ms-enclave docker websocket-client
```
--------------------------------
### Enable Knowledge Search with Custom Config and Paths
Source: https://github.com/modelscope/ms-agent/blob/main/docs/zh/Components/config.md
Run MS-Agent with a specific configuration file and enable knowledge search using local document paths. LLM settings are inherited unless explicitly overridden in the config.
```bash
# 指定配置文件
ms-agent run --config /path/to/agent.yaml --query "你的问题" --knowledge_search_paths "/path/to/docs"
```
--------------------------------
### Install mem0ai for Memory Functionality
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
Install the mem0ai package to enable memory features in MS-Agent. Also, ensure ModelScope and DashScope API keys are set.
```bash
pip install mem0ai
export MODELSCOPE_API_KEY={your_modelscope_api_key}
export DASHSCOPE_API_KEY={your_dashscope_api_key}
```
--------------------------------
### Install ms-agent with Research Dependencies
Source: https://github.com/modelscope/ms-agent/blob/main/projects/doc_research/README.md
Install the ms-agent package with the research extra dependencies. Ensure you are using Python 3.11 and have created a dedicated conda environment.
```bash
conda create -n doc_research python=3.11
conda activate doc_research
# Version requirement: ms-agent>=1.1.0
pip install 'ms-agent[research]'
```
--------------------------------
### Build Documentation
Source: https://github.com/modelscope/ms-agent/blob/main/docs/README.md
Instructions on how to build the documentation for the MS-Agent project.
```APIDOC
## Build Documentation
To build the documentation, navigate to the root directory of the ms-agent project and run the following command:
```shell
make docs
```
```
--------------------------------
### Configure Multimodal Model with LLMAgent
Source: https://github.com/modelscope/ms-agent/blob/main/docs/en/Components/multimodal-support.md
Dynamically modify configuration to use a multimodal model like 'qwen3.5-plus' and set the API key and base URL.
```python
from ms_agent.config import Config
from ms_agent import LLMAgent
import os
# 使用现有配置文件(如 ms_agent/agent/agent.yaml)
config = Config.from_task('ms_agent/agent/agent.yaml')
# 覆盖配置为多模态模型
config.llm.model = 'qwen3.5-plus'
config.llm.service = 'dashscope'
config.llm.dashscope_api_key = os.environ.get('DASHSCOPE_API_KEY', '')
config.llm.modelscope_base_url = 'https://dashscope.aliyuncs.com/compatible-mode/v1'
# 创建 LLMAgent
agent = LLMAgent(config=config)
```
--------------------------------
### Launch Full FinResearch Workflow
Source: https://github.com/modelscope/ms-agent/blob/main/README.md
This command initiates the complete FinResearch workflow for testing. Ensure environment variables for OpenAI API key and base URL are configured. For full functionality, EXA_API_KEY or SERPAPI_API_KEY are also required.
```bash
ms-agent --config projects/fin_research --query "Generate a financial report on Apple Inc."
```
--------------------------------
### Install defusedxml dependency
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/SKILL.md
Required for secure XML parsing.
```bash
pip install defusedxml
```
--------------------------------
### Install pandoc dependency
Source: https://github.com/modelscope/ms-agent/blob/main/examples/skills/claude_skills/docx/SKILL.md
Required for text extraction functionality.
```bash
sudo apt-get install pandoc
```