cocacola-lab / MineLand

Simulating Large-Scale Multi-Agent Interactions with Limited Multimodal Senses and Physical Needs
MIT License
46 stars 5 forks source link

catched after eval TypeError: Cannot read properties of undefined (reading 'blocksByName') #17

Closed Raven-July closed 1 month ago

Raven-July commented 1 month ago

I used gpt-4o-mini as the llm. The bot failed to code and was trapped in an endless loop.

part of the output:

[Server] [16:57:29] [Server thread/INFO]: Starting to mine oak logs. [Mineflayer] catched after eval TypeError: Cannot read properties of undefined (reading 'blocksByName') [Mineflayer] at mineOakLogs (eval at runCodeByOrder (E:\Python_Projects\MineLand\mineland\sim\mineflayer\bot_manager.js:353:19), :603:28) [Mineflayer] at eval (eval at runCodeByOrder (E:\Python_Projects\MineLand\mineland\sim\mineflayer\bot_manager.js:353:19), :617:7) [Mineflayer] at eval (eval at runCodeByOrder (E:\Python_Projects\MineLand\mineland\sim\mineflayer\bot_manager.js:353:19), :618:3) [Mineflayer] at BotManager.runCodeByOrder (E:\Python_Projects\MineLand\mineland\sim\mineflayer\bot_manager.js:353:19) [Mineflayer] at E:\Python_Projects\MineLand\mineland\sim\mineflayer\index.js:113:25 [Mineflayer] at Layer.handle [as handle_request] (E:\Python_Projects\MineLand\mineland\sim\mineflayer\node_modules\express\lib\router\layer.js:95:5) [Mineflayer] at next (E:\Python_Projects\MineLand\mineland\sim\mineflayer\node_modules\express\lib\router\route.js:149:13) [Mineflayer] at Route.dispatch (E:\Python_Projects\MineLand\mineland\sim\mineflayer\node_modules\express\lib\router\route.js:119:3) [Mineflayer] at Layer.handle [as handle_request] (E:\Python_Projects\MineLand\mineland\sim\mineflayer\node_modules\express\lib\router\layer.js:95:5) [Mineflayer] at E:\Python_Projects\MineLand\mineland\sim\mineflayer\node_modules\express\lib\router\index.js:284:15 ==========self check========== next step after self check: action description: Code Error

Raven-July commented 1 month ago

here is the last code by the bot:

async function gatherOakLogs(bot) { bot.chat('Moving closer to the oak logs to gather more.'); await bot.pathfinder.goto(new GoalNear(64, 64, -125, 3)); const oakLogs = bot.findBlocks({ matching: bot.mcData.blocksByName.oak_log.id, maxDistance: 48, count: 10\n }); if (oakLogs.length > 0) { await mineBlock(bot, 'oak_log', 10); bot.chat('Successfully mined 10 oak logs.'); } else { bot.chat('No oak logs found nearby.'); } } await gatherOakLogs(bot);"}

Raven-July commented 1 month ago

here's another example from the bot's log:

==========action========== Action Agent {'Explain': "In the RGB picture, I can see the top of an oak tree, indicating that there are oak logs available for mining. The relationship between this vision input and the task is direct, as the task is to mine oak logs. The code info indicates a TypeError due to an undefined reference to 'blocksByName', which suggests that the bot's data context is not properly initialized. The critic info implies that the previous code did not complete the short-term plan due to this error.", 'Plan': "1) Ensure that mcData is properly initialized before accessing blocksByName. 2) Start mining oak logs by finding nearby oak logs using bot.findBlocks. 3) Use mineBlock(bot, 'oak_log', 1) to mine each log one by one until 10 logs are collected. 4) Update the total mined count and send chat messages to indicate progress. 5) Finish the function by sending a final message with the total collected logs.",

'Code': "

async function mineOakLogs(bot) { bot.chat('Starting to mine oak logs.'); let totalMined = 0;\n while (totalMined < 10) { const oakLogs = bot.findBlocks({ matching: bot.mcData.blocksByName.oak_log.id, maxDistance: 48,\n count: 10\n }); if (oakLogs.length === 0) { bot.chat('No more oak logs nearby to mine.'); break; } await mineBlock(bot, 'oak_log', 1); totalMined++; bot.chat('Mined an oak log. Total mined: ' + totalMined); } bot.chat('Finished mining oak logs. Total collected: ' + totalMined); } await mineOakLogs(bot); "}

==========self check========== next step after self check: brain description: Code Failed

Raven-July commented 1 month ago

here is my code:

import mineland from mineland.alex import Alex

AGENTS_COUNT = 2 AGENTS_CONFIG = [ {"name": "Alice"}, {"name": "Bob"} ]

mland = mineland.make( task_id="playground", agents_count=AGENTS_COUNT, agents_config=AGENTS_CONFIG, )

initialize agents

agents = [] Alice = Alex(personality='Aggressive', # Alex configuration llm_model_name='gpt-4o-mini', vlm_model_name='gpt-4o-mini', bot_name='Alice', temperature=0.1) Bob = Alex(personality='None', # Alex configuration llm_model_name='gpt-4o-mini', vlm_model_name='gpt-4o-mini', bot_name='Bob', temperature=0.1) agents.append(Alice) agents.append(Bob)

obs = mland.reset()

agents_count = len(obs) agents_name = [obs[i]['name'] for i in range(agents_count)]

for i in range(5000): if i > 0 and i % 10 == 0: print("task_info: ", task_info) actions = [] if i == 0:

skip the first step which includes respawn events and other initializations

    actions = mineland.Action.no_op(agents_count)
else:
    # run agents
    for idx, agent in enumerate(agents):
        action = agent.run(obs[idx], code_info[idx], done, task_info, verbose=True)
        actions.append(action)

obs, code_info, event, done, task_info = mland.step(action=actions)
Raven-July commented 1 month ago

I did another test and compared the code written by the bot:

At first,the code look like this: async function gatherBirchLogs(bot) { bot.chat('Searching for birch logs...'); const birchLogs = bot.findBlocks({ matching: bot.mcData.blocksByName.birch_log.id, maxDistance: 48, count: 10 }); if (birchLogs.length > 0) { await mineBlock(bot, 'birch_log', 10); bot.chat('Successfully mined 10 birch logs.'); } else { bot.chat('No birch logs found nearby.'); } } await gatherBirchLogs(bot);

After the failure,bot realized and made an improvement "The bot is currently attempting to gather birch logs but encountered a TypeError due to an undefined reference to 'blocksByName'. This indicates that the bot's data for blocks is not properly initialized or accessible." new code:

async function gatherBirchLogs(bot) { bot.chat('Searching for birch logs...'); const mcData = require('minecraft-data')(bot.version); const birchLogs = bot.findBlocks({ matching: mcData.blocksByName.birch_log.id, maxDistance: 48, count: 10 }); if (birchLogs.length > 0) { await mineBlock(bot, 'birch_log', 10); bot.chat('Successfully mined 10 birch logs.'); } else { bot.chat('No birch logs found nearby.'); } } await gatherBirchLogs(bot);"}

It seems that the lack of " const mcData = require('minecraft-data')(bot.version);" caused the "undefined (reading 'blocksByName') " fault. But what really confused me was that the bot keep forgetting to add "const mcData = require('minecraft-data')(bot.version);" As a result, I encountered "undefined (reading 'blocksByName') " fault over and over again in a high frequency.

YXHXianYu commented 1 month ago

Refer to Mineflayer API Docs. The bot object doesn't have a field named mcData. So, bot.mcData is incorrect code. bot.mcData should be undefined.

Usually, we use const mcData = require("minecraft-data")(bot.version) to get mcData and use it directly.

The problem here is caused by the limited capabilities of gpt-4o-mini. gpt-4o-mini(or gpt3.5) cannot correct code efficiently. We suggest using gpt4 or gpt4o instead.

Raven-July commented 1 month ago

Thanks for the advice! I 'll take it.