Qwen-AgentWorld — Native Language World Model for Agentic Environment Simulation
"ภาษาคือโลก" / Language is the World
— โมเดลโลกที่สื่อสารเป็นภาษาธรรมชาติ จำลองการเปลี่ยนแปลงของสภาพแวดล้อม เอเจนต์ การใช้เครื่องมือ และผลลัพธ์แบบ end-to-end
สารบัญ / TOC
ภาพรวม / Overview
Qwen-AgentWorld
คือ
native language world model
ที่เทรนจากฐาน
Qwen3.8-27B-TurboFCFusion (GGUF IQ4_NL, 16.5 GB, 65 blocks, 262K context)
เพื่อทำหน้าที่จำลองโลกสำหรับเอเจนต์:
[Observation_t + Action_t + History] --Qwen-AgentWorld--> [Observation_{t+1}, Reward, Done, Info]
ทุกอย่างเป็น
ภาษา
— observation, action, tool call, tool result, reward explanation — โมเดลทำนาย
ภาษาที่สภาพแวดล้อมจะตอบกลับ
ไม่ใช่เวกเตอร์ซ่อน
Use cases
Agentic simulation
— ฝึกหรือประเมินเอเจนต์โดยไม่ต้องเรียก environment จริง (WebShop, ALFWorld, OSWorld, CodeEnv, ToolEnv)
Dream training (Dreamer-style)
— ให้เอเจนต์ rollout ในความฝันของ world model แล้วค่อย deploy จริง
Planning / Search
— MCTS / Best-of-N โดยใช้ world model เป็น simulator
Data synthesis
— สร้าง trajectory สังเคราะห์สำหรับ SFT/RL
Base model file:
D:\AGI\Qwen3.8-27B-TurboFCFusion-735-882-Here-Uncen-NEO-CODER-MAX-MTP-IQ4_NL.gguf
(17,753,101,856 bytes, GGUFv3, qwen35 arch)
สถาปัตยกรรม / Architecture
┌─────────────────────────────────────────────────────────────┐
│ Qwen-AgentWorld (27B) │
│ Qwen3.5 hybrid: Attention (full-interval=4) + Mamba2 SSM │
│ 65 blocks | d=5120 | FFN 17408 | 24H / 4KV | 65 layers │
│ RoPE 10M freq | MTP next-n=1 | 262K context │
├─────────────────────────────────────────────────────────────┤
│ World Model Interface (language-native) │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Obs→Text │→ │ Act→Text │→ │ Qwen │→ │Text→ Env │ │
│ │ Encoder │ │ Encoder │ │ 27B │ │ Decoder │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ Output JSON: {next_obs, reward, done, info, thought} │
├─────────────────────────────────────────────────────────────┤
│ Environments (text-serialized) │
│ ALFWorld | WebShop | CodeEnv | ToolEnv | OSWorld | TextGame│
├─────────────────────────────────────────────────────────────┤
│ Dream Engine | Trajectory Buffer | Reward Model │
└─────────────────────────────────────────────────────────────┘
World Model Prompt Contract
(
qwen_agent_world/world_model.py:42
):
Input:
system
= World Simulator instructions (THAI/EN) + environment spec + history + current obs + action
Output: strict JSON:
{"next_observation": str, "reward": float, "done": bool, "info": str, "thought": str}
Hybrid SSM+Attention
(
qwen35.*
kv): ทุก 4th block ใช้ full attention, ที่เหลือเป็น Mamba2 SSM — เหมาะกับ trajectory ยาว 262K
โครงสร้างโฟลเดอร์
D:\AGI\Qwen-AgentWorld\
├── Qwen3.8-27B-TurboFCFusion-...gguf (symlink → D:\AGI\*.gguf)
├── qwen_agent_world/
│ ├── config.py # WorldModelConfig, EnvConfig
│ ├── world_model.py # QwenAgentWorld core (GGUF+HF dual backend)
│ ├── environments/ # BaseEnv + 6 envs + Registry
│ ├── simulation/ # DreamEngine, Trajectory, Dreamer
│ ├── training/ # Dataset, Trainer, LoRA, RewardModel
│ ├── inference/ # OpenAI-compatible server + client
│ └── utils/ # metrics, logging
├── configs/ # world_model.yaml, training.yaml, environments.yaml
├── scripts/ # train.py, inference.py, evaluate.py, benchmark.py
├── examples/ # quickstart.py, agent_in_dream.py, tool_use_simulation.py
└── Modelfile # Ollama
ติดตั้ง / Installation
# 1. สร้าง venv (Python 3.10+ แนะนำ 3.11/3.12)
python -m venv .venv
.\.venv\Scripts\Activate.ps1
# 2. ติดตั้ง dependencies
pip install -r requirements.txt
# 3. ติดตั้ง llama-cpp-python แบบ GPU (RTX 3090 = cuBLAS)
# เลือก 1 วิธี:
pip install llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python /whl/cu126
# หรือ build จาก source (ต้องมี CUDA 12.6 + VS2022)
CMAKE_ARGS="-DGGML_CUDA=1" pip install llama-cpp-python --no-cache-dir --force-reinstall
# 4. (ทางเลือก) Ollama
ollama create qwen-agentworld -f Modelfile
ollama run qwen-agentworld
requirements.txt
รวม:
transformers
,
torch
,
accelerate
,
peft
,
datasets
,
llama-cpp-python
,
fastapi
,
uvicorn
,
pydantic
,
pyyaml
,
rich
,
numpy
Quickstart
1. Python — World Model โดยตรง
from qwen_agent_world import QwenAgentWorld, WorldModelConfig
wm = QwenAgentWorld(
WorldModelConfig(
gguf_path=r"D:\AGI\Qwen3.8-27B-TurboFCFusion-735-882-Here-Uncen-NEO-CODER-MAX-MTP-IQ4_NL.gguf" ,
n_ctx=32768 , # ใส่ 262144 ถ้า VRAM พอ (ต้อง offload)
n_gpu_layers=-1 , # -1 = offload ทั้งหมดเท่าที่ VRAM พอ
temperature=0.7 ,
use_mtp=True , # เปิด MTP speculative (ถ้า backend รองรับ)
)
)
# Step เดียว
result = wm.step(
observation="คุณอยู่ในห้องครัว มีแอปเปิ้ลบนโต๊ะ" ,
action="หยิบแอปเปิ้ล" ,
history=[],
env_spec="ALFWorld: ห้องครัว, เป้าหมาย=นำแอปเปิ้ลไปตู้เย็น"
)
print (result.next_observation) # "คุณหยิบแอปเปิ้ลสำเร็จ ..."
print (result.reward, result.done)
# Rollout หลายก้าว (dream)
trajectory = wm.rollout(
initial_observation="หน้า WebShop: ค้นหา 'หูฟังไร้สาย'" ,
actions=["ค้นหา 'Sony WH-1000XM5'" , "คลิกผลลัพธ์แรก" , "เพิ่มลงตะกร้า" ],
env_spec="WebShop"
)
ดู
examples/quickstart.py
สำหรับตัวอย่างเต็ม
2. Dream Engine — ฝึกเอเจนต์ในความฝัน
from qwen_agent_world.simulation import DreamEngine
from qwen_agent_world.environments import get_env
engine = DreamEngine(world_model=wm, env_name="alfworld" )
# เก็บ trajectory จริงเล็กน้อยเพื่อ seed
engine.seed_from_real_env(get_env("alfworld" ), episodes=5 )
# ฝันต่อ 100 episodes โดยไม่แตะ env จริง
dreams = engine.dream(episodes=100 , max_steps=30 )
# ใช้ dreams ไป train agent (REINFORCE/PPO/SFT)
ดู
examples/agent_in_dream.py
3. OpenAI-compatible Server
python scripts/inference.py --host 0.0 .0.0 --port 8081
# หรือ
python -m qwen_agent_world.inference.server --gguf "D:\AGI\..." --port 8081
curl http://localhost:8081/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"qwen-agentworld","messages":[{"role":"user","content":"จำลอง WebShop: ..."}]}'
curl http://localhost:8081/v1/world/step -H "Content-Type: application/json" \
-d '{"observation":"...","action":"...","env_spec":"alfworld"}'
World Model API
Method
สัญญา
wm.step(obs, action, history, env_spec)
ทำนายก้าวเดียว →
WorldStepResult
wm.rollout(init_obs, actions, env_spec)
หลายก้าวต่อเนื่อง
wm.simulate(agent, env, max_steps)
ให้ agent เล่นในโลกจำลองจนจบ
wm.batch_step(requests)
batch หลาย request พร้อมกัน
POST /v1/world/step
HTTP API สำหรับ step
POST /v1/world/rollout
HTTP API สำหรับ rollout
WorldStepResult
(
qwen_agent_world/world_model.py:28
):
@dataclass
class WorldStepResult :
next_observation: str
reward: float
done: bool
info: str
thought: str # โมเดลคิดอะไร (reasoning)
raw_output: str # JSON ดิบ
latency_ms: float
Training
เตรียม dataset (trajectory JSONL)
{"env":"alfworld","observations":["You are in kitchen..."],"actions":["go to table"],"next_observations":["You see apple..."],"rewards":[0],"dones":[false]}
LoRA finetune (แนะนำสำหรับ 27B บน 24GB)
python scripts/train.py --config configs/training.yaml
configs/training.yaml
ตั้ง LoRA
r=64, alpha=128, dropout=0.05
เฉพาะ
q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj
+
ssm
layers, 4-bit quantization (QLoRA) ถ้าใช้
bitsandbytes
Reward Model
from qwen_agent_world.training import RewardModel
rm = RewardModel(base_model="Qwen-AgentWorld" )
score = rm.score(observation, action, next_observation) # float
Ollama / llama.cpp
Ollama
(
Modelfile
):
FROM D:\AGI\Qwen3.8 -27 B-TurboFCFusion-735 -882 -Here-Uncen-NEO-CODER-MAX-MTP-IQ4_NL.gguf
PARAMETER num_ctx 32768
PARAMETER temperature 0.7
SYSTEM "" "You are Qwen-AgentWorld, a native language world model..." ""
ollama create qwen-agentworld -f Modelfile
ollama run qwen-agentworld "จำลอง ALFWorld: ..."
llama.cpp
โดยตรง:
llama-server --model "D:\AGI\Qwen3.8-27B-....gguf" --ctx-size 32768 --n-gpu-layers 65 --port 8080
Evaluation
python scripts/evaluate.py --env alfworld --episodes 50 --max-steps 30
python scripts/benchmark.py --suite all
Metrics (
qwen_agent_world/utils/metrics.py
):
Next-obs fidelity
: BLEU / ROUGE / BERTScore vs ground truth
Reward MSE / Accuracy
Done F1
Trajectory consistency
(rollout หลายก้าวแล้วตรวจ coherence)
Agent success rate in dream vs real
อ้างอิงสถาปัตยกรรม GGUF
Key
Value
general.architecture
qwen35
qwen35.block_count
65
qwen35.context_length
262144
qwen35.embedding_length
5120
qwen35.feed_forward_length
17408
qwen35.attention.head_count
24
qwen35.attention.head_count_kv
4 (GQA)
qwen35.rope.freq_base
10,000,000
qwen35.full_attention_interval
4
qwen35.nextn_predict_layers
1 (MTP)
tokenizer.ggml.model
gpt2 (Qwen3)
general.file_type
25 (IQ4_NL)
License & Credits
Base model weights: ตาม license ของผู้ปล่อย GGUF ต้นทาง (Brainwaves/NM/HERETIC fusion)
Code ใน
Qwen-AgentWorld/
: MIT — สร้างใหม่สำหรับโปรเจกต์นี้
Qwen3.5 architecture: Alibaba Cloud Qwen team
สร้างเมื่อ 2026-09-04 บน RTX 3090 — D:\AGI