Qwen-AgentWorld

repository·main·Indexed 21 days ago

https://github.com/qwenlm/qwen-agentworld

A native language world model designed to simulate agentic environments across seven domains: MCP, Search, Terminal, SWE, Android, Web, and OS. It uses long chain-of-thought reasoning to predict environment states for agent training and evaluation. The repository includes the Qwen-AgentWorld-35B-A3B model, deployment guides for SGLang, vLLM, and Transformers, and the AgentWorldBench benchmark for evaluating world models across dimensions like factuality, consistency, and realism.

Tokens
2.5K
Snippets
7
Records
8
Agent score
24%

What's inside Qwen-AgentWorld

  1. Setup AgentWorldBench benchmark

    main

    To use AgentWorldBench for evaluating language world models, you need to download the dataset from Hugging Face and install the openai dependency.

    1. Download the dataset using huggingface-cli to a local directory.
    2. Install the required Python package.
    # Download the benchmark
    huggingface-cli download Qwen/AgentWorldBench --repo-type dataset --local-dir ./AgentWorldBench
    
    # Install dependencies
    pip install openai
  2. Run the AgentWorldBench evaluation pipeline

    main

    Evaluation is performed using the eval/eval.py script via a three-step pipeline: inference, judging, and scoring. The script uses OpenAI-compatible APIs for both the world model and the LLM judge.

    Step 1: World Model Inference

    Generate predictions from your world model.

    • --data-dir: Path to the downloaded AgentWorldBench directory.
    • --model-base-url: The OpenAI-compatible endpoint for your world model.
    • --model-name: The name of the model being evaluated.
    • --output-dir: Where to save the predictions.

    Step 2: LLM Judge Scoring

    Score the predictions using an LLM judge.

    • Requires OPENAI_API_KEY to be set in the environment.
    • --predictions: Path to the predictions.jsonl generated in Step 1.
    • --judge-base-url: The endpoint for the judge LLM.
    • --judge-model: The specific model to use as the judge.
    • --output-dir: Where to save the judged results.

    Step 3: Aggregate Scores

    Calculate and display the final metrics.

    • --predictions: Path to the judged.jsonl generated in Step 2.
    cd eval
    
    # Step 1: Run world model inference
    python eval.py infer \
        --data-dir ../AgentWorldBench \
        --model-base-url http://localhost:8000/v1 \
        --model-name Qwen/Qwen-AgentWorld-35B-A3B \
        --output-dir ./results
    
    # Step 2: Run LLM judge scoring
    export OPENAI_API_KEY="your-api-key"
    python eval.py judge \
        --predictions ./results/predictions.jsonl \
        --judge-base-url https://api.openai.com/v1 \
        --judge-model gpt-5.2-2025-12-11 \
        --output-dir ./results
    
    # Step 3: Aggregate and display scores
    python eval.py score --predictions ./results/judged.jsonl
  3. Deploy Qwen-AgentWorld-35B-A3B using vLLM

    main

    Use vLLM for high-throughput inference. This provides an OpenAI-compatible API at http://localhost:8000/v1.

    Important: You MUST include the --language-model-only flag. The model architecture includes visual component definitions, but the checkpoint only contains language model weights. Without this flag, vLLM will attempt to initialize visual modules and fail.

    vllm serve Qwen/Qwen-AgentWorld-35B-A3B \
        --port 8000 \
        --tensor-parallel-size 4 \
        --max-model-len 262144 \
        --reasoning-parser qwen3 \
        --language-model-only \
        --trust-remote-code
  4. Download Qwen-AgentWorld models and AgentWorldBench

    main

    Qwen-AgentWorld model weights and the AgentWorldBench dataset are available on Hugging Face and ModelScope.

    Hugging Face

    You can download models automatically using the model ID Qwen/Qwen-AgentWorld-35B-A3B via the huggingface library, huggingface download, or git clone.

    ModelScope

    For users in regions where Hugging Face is inaccessible, you can download from ModelScope. To use ModelScope with supported frameworks, set the following environment variables:

    • SGLANG_USE_MODELSCOPE=true
    • VLLM_USE_MODELSCOPE=true
  5. Deploy Qwen-AgentWorld-35B-A3B using SGLang

    main

    Use SGLang to serve the model. This provides an OpenAI-compatible API at http://localhost:8000/v1.

    Note: The --reasoning-parser qwen3 flag is used to handle the model's reasoning output.

    python -m sglang.launch_server \
        --model-path Qwen/Qwen-AgentWorld-35B-A3B \
        --port 8000 \
        --tensor-parallel-size 4 \
        --context-length 262144 \
        --reasoning-parser qwen3
  6. Perform inference with Transformers

    main

    You can use the standard transformers library to run inference. The model is designed to simulate environments (like a Linux terminal) based on specific system prompts and user actions.

    For best results when using the model as an environment simulator, use the domain-specific system prompt templates provided in the prompts/ directory of the repository. Each domain folder contains a system_prompt.txt (for the world model) and a judge_system_prompt.txt (for evaluation).

    from transformers import AutoModelForCausalLM, AutoTokenizer
    
    model_name = "Qwen/Qwen-AgentWorld-35B-A3B"
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    model = AutoModelForCausalLM.from_pretrained(
        model_name,
        torch_dtype="auto",
        device_map="auto",
    )
    
    messages = [
        {
            "role": "system",
            "content": "You are a language world model simulating a Linux terminal environment. "
                       "Given the user's command, predict the terminal output."
        },
        {
            "role": "user",
            "content": "Action: execute_bash\nCommand: ls -la /home/user/project/"
        }
    ]
    
    text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
    inputs = tokenizer([text], return_tensors="pt").to(model.device)
    outputs = model.generate(**inputs, max_new_tokens=2048, temperature=0.6)
    response = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
    print(response)
  7. View AgentWorldBench evaluation results

    main

    The eval.py score command produces a summary of performance across five dimensions: Format, Factuality, Consistency, Realism, and Quality. Results are provided per-domain and as an overall score.

    ======================================================================
    AgentWorldBench Evaluation Results (example output)
    ======================================================================
    
    --- MCP (286/286 valid, 0 failed) ---
             format: 81.46
         factuality: 68.75
        consistency: 72.92
           realism: 71.88
            quality: 67.08
        total_score: 72.42
    ...
    
    ======================================================================
    Overall: 56.39
    ======================================================================
  8. Understand AgentWorldBench data format

    main

    AgentWorldBench data is stored in per-domain JSONL files (e.g., mcp_test.jsonl, search_test.jsonl, terminal_test.jsonl, swe_test.jsonl, android_test.jsonl, web_test.jsonl, os_test.jsonl).

    Each entry in the JSONL file represents a trajectory turn and contains the following key fields:

    • system_str: The specific world model system prompt for this sample. Note: The files in the prompts/ directory of this repository are templates only; always use the system_str from the data sample during evaluation.
    • prompt / response: Lists containing the full trajectory of action prompts and ground-truth environment observations.
    • current_prompt: The specific action prompt for the turn currently being evaluated.
    • turn_idx: The 1-indexed position of the current turn.
    • task: The domain name (e.g., mcp).
    • id: A unique identifier for the sample.
    {
        "task": "mcp",
        "id": 145256090131919,
        "prompt": ["### Turn 1\n**Action:**\n```json\n{...}\n```\n..."],
        "response": ["**Environment Observation:**\n{...}"],
        "current_prompt": "### Turn 1\n**Action:**\n...",
        "system_str": "# Role and Objective\n\nYou are a **Tool World Model** ...",
        "turn_idx": 1,
        "total_turns": 5
    }