---
title: "Voyager：结合大语言模型的创新虚拟智能体 [译]"
url: "https://paooo.com/ai-study/7002/"
author: "宝玉的分享"
published_at: "2024-01-22T12:31:49+08:00"
updated_at: "2026-07-22T13:28:15+08:00"
categories: "强化 AI 学习"
tags: "AI智能体, AI编程, 大模型微调, 开源大模型"
source: "Prompt 语宙 (https://paooo.com)"
ai_tools_directory: "语宙 AI 导航 (https://ai.paooo.com)"
---

# Voyager：结合大语言模型的创新虚拟智能体 [译]

> 来源：[Prompt 语宙 (paooo.com)](https://paooo.com/ai-study/7002/) · 作者：宝玉的分享 · 发布时间：2024-01-22

## AI 30 秒核心看点 (TL;DR)

- Voyager 用“课程规划+代码生成+自我批评”闭环，让智能体在 Minecraft 中持续进化。
- 核心亮点是技能管理器：把成功经验沉淀为可复用技能，减少重复试错。
- 实操上可直接用 Mineflayer 编写任务代码，适合做开放世界自动化与智能体研究。

```
defvoyager(

  environment,# 这是一个环境，它将代码作为执行动作的空间

  curriculum_agent,# 课程代理，它的职责是规划接下来的学习任务

  action_agent,# 行动代理，主要负责编写代码

  critic_agent,# 批评代理，负责自我检查与反馈

  skill_manager,# 技能管理器，用于增加新技能和回顾已有技能

):

agent_state = environment.reset()# 初始化代理状态

whileTrue:# 持续进行任务直到达成目标

# 获取代理的探索进展，包括已完成和失败的任务

  exploration_progress =(

      curriculum_agent.get_exploration_progress(

          curriculum_agent.get_completed_tasks(),

          curriculum_agent.get_failed_tasks(),

)

)

# 代理根据当前状态和进展情况提出下一个任务

  task = curriculum_agent.propose_next_task(

      agent_state, exploration_progress

)

# 初始化变量

  code =None

  environment_feedback =None

  execution_errors =None

  critique =None

  success =False

# 对每个任务最多进行 4 次尝试，如果不成功则继续下一个任务

for i inrange(4):

# 根据任务和环境反馈获取技能

      skills = skill_manager.retrieve_skills(

          task, environment_feedback

)

# 生成代码，包括新任务、旧代码、环境反馈、执行错误和批判性意见

      code = action_agent.generate_code(

          task,

          code,

          environment_feedback,

          execution_errors,

          critique,

          skills,

)

# 执行代码并获取新的状态、环境反馈和执行错误

(

          agent_state,

          environment_feedback,

          execution_errors,

)= environment.step(code)

# 检查任务是否成功，并得到批评代理的反馈

      success, critique = critic_agent.check_task_success(

          task, agent_state

)

if success:# 如果成功，跳出循环

break

if success:# 如果任务成功，添加新技能并记录已完成任务

      skill_manager.add_skill(code)

      curriculum_agent.add_completed_task(task)

else:# 如果任务失败，记录失败任务

      curriculum_agent.add_failed_task(task)

你是一个编写 Mineflayer javascript 代码的助手，能够帮我完成指定的任意 Minecraft 任务。

下面是一些利用 MineflayerAPI 编写的实用程序示例。

/*

探索直到找到铁矿石。由于铁矿石一般位于地下，因此使用 Vec3(0,-1,0) 来定位。

awaitexploreUntil(bot,newVec3(0,-1,0),60,()=>{

const iron_ore = bot.findBlock({

matching: mcData.blocksByName["iron_ore"].id,

maxDistance:32,

});

return iron_ore;

});

探索直到找到一头猪。由于猪通常在地面出没，所以使用 Vec3(1,0,1) 进行搜索。

let pig =awaitexploreUntil(bot,newVec3(1,0,1),60,()=>{

const pig = bot.nearestEntity((entity)=>{

return(

            entity.name==="pig"&&

            entity.position.distanceTo(bot.entity.position){

return block.name=== name;

},

maxDistance:32,

count: count,

});

// 在距离不超过 32 的范围内，采集数量为 count 的资源：

const targets =[];

for(let i =0; i 

            entity.name=== mobName &&

entity.position.distanceTo(bot.entity.position){

const stone = bot.findBlock({

matching: mcData.blocksByName["stone"].id,

maxDistance:32

});

if(stone){

returntrue;

}

});

// 使用木镐开采 8 个石头方块

    bot.chat("Found a stone block. Mining 8 cobblestone blocks.");

awaitmineBlock(bot,"stone",8);

    bot.chat("成功挖到了 8 块圆石。");

// 记录挖到 8 块圆石的情况

    bot.save("cobblestone_mined");

} 否则 {

    bot.chat("没能成功做出木头镐，挖不了圆石。");

}

}

asyncfunctioncraftWoodenPlanks(bot){

// 木头日志数组

const logNames =[

"oak_log",

"birch_log",

"spruce_log",

"jungle_log",

"acacia_log",

"dark_oak_log",

"mangrove_log",

];

// 木板名称数组

const plankNames =[

"oak_planks",

"birch_planks",

"spruce_planks",

"jungle_planks",

"acacia_planks",

"dark_oak_planks",

"mangrove_planks",

];

// 检查库存中是否有木头

const logInInventory = logNames.find(

(logName)=> bot.inventory.count(mcData.itemsByName[logName].id)>0

);

// 如果没有木头，先去挖

if(!logInInventory){

    bot.chat("库存中没有木头日志。正在采集木头日志...");

awaitmineWoodLog(bot);

}

// 获取木头对应的木板名称

const logIndex = logNames.indexOf(logInInventory);

const plankName = plankNames[logIndex];

// 开始制作木板

  bot.chat(`制作 4 个 ${plankName}...`);

awaitcraftItem(bot, plankName,1);

  bot.chat(`已制作 4 个 ${plankName}。`);

}

asyncfunctionmineTenCobbledDeepslateBelowY0(bot){

// 首先，装备铁镐

const ironPickaxe = bot.inventory.findInventoryItem(mcData.itemsByName["iron_pickaxe"].id);

await bot.equip(ironPickaxe,"hand");

// 寻找 Y=0 以下的圆石深板岩方块

const cobbledDeepslateBlocks =awaitexploreUntil(bot,newVec3(1,-1,1),60,()=>{

const cobbledDeepslate = bot.findBlock({

matching: mcData.blocksByName["cobbled_deepslate"].id,

maxDistance:32,

position:pos=> pos.y{

const foundWaterBlock = bot.findBlock({

matching: mcData.blocksByName.water.id,

maxDistance:32

});

return foundWaterBlock;

});

if(!waterBlock){

    bot.chat("No path to the water block. Trying to find another water block...");

}

}

// Move to a block adjacent to the water block

const adjacentBlock = waterBlock.position.offset(0,1,0);

asyncfindSuitablePosition(bot){

  偏移量为 [newVec3(1,0,0),newVec3(-1,0,0),newVec3(0,0,1),newVec3(0,0,-1)];

  对于偏移量中的每一个 {

    定位为 bot.entity.position.offset(offset.x, offset.y, offset.z);

    块为 bot.blockAt(定位);

    如果 块.name==="air"{

      返回 定位;

}

}

  返回 null;

}

asyncsmeltFiveRawIron(bot){

// 检查背包中是否有熔炉

  熔炉物品为 bot.inventory.findInventoryItem(mcData.itemsByName.furnace.id);

// 如果没有，使用现有的圆石来制作熔炉

如果(!熔炉物品){

    等待 craftFurnace(bot);

}

// 找到一个适合放置熔炉的位置

  熔炉位置为等待 findSuitablePosition(bot);

如果(!熔炉位置){

    bot.chat("找不到适合放置熔炉的位置。");

    返回;

}

// 在合适的位置放置熔炉

  等待 placeItem(bot,"furnace", 熔炉位置);

// 使用可用的煤作为燃料，熔炼 5 块生铁

  等待 smeltItem(bot,"raw_iron","coal",5);

  bot.chat("已熔炼 5 块生铁。");

}

技能库示例 4：fillBucketWithWater。

asyncfillBucketWithWater(bot){

// 寻找附近的水块

await bot.pathfinder.goto(new GoalBlock(adjacentBlock.x, adjacentBlock.y, adjacentBlock.z));

// 观察水块

await bot.lookAt(waterBlock.position);

// 装备钓鱼竿

await bot.equip(fishingRod, "hand");

// 在水中钓鱼 5 次

for (let i = 0; i 

## 常见问题解答 (FAQ)

### Voyager 这个虚拟智能体的核心机制是什么？
Voyager 由课程代理、行动代理、批评代理和技能管理器组成：先规划任务，再生成代码执行，随后自检反馈，最后把成功经验沉淀为技能。它的关键是持续学习与迭代，而不是一次性完成任务。

### Voyager 为什么适合 Minecraft 任务自动化？
因为 Minecraft 是开放世界环境，任务多样且可通过代码直接操作。Voyager 结合 Mineflayer API，能把探索、挖矿、找生物等目标转成可执行脚本，并在失败后自动修正，适合复杂任务链。

### 这篇文章对 AI 编程有什么参考价值？
它展示了大模型不只是写代码，还能在环境反馈中自我纠错、规划下一步并积累技能。这种“生成—执行—反馈—再生成”的闭环，对 AI 智能体、自动化脚本和游戏代理开发都很有参考价值。

---
探索 2,800+ 全球实用 AI 工具与官方直达入口：[语宙 AI 导航 (https://ai.paooo.com/)](https://ai.paooo.com/)
