Skip to content

Repository files navigation

๐Ÿฐ Minecraft ADK Guild

AI agents working together like a medieval guild to conquer Minecraft tasks ๐Ÿค–โš”๏ธ

Google ADK Multi-Agent Minecraft Python

Watch AI agents collaborate to gather resources, craft items, and place blocks autonomously

๐ŸŽฌ Demo

Watch the video

๐Ÿ“š Table of Contents

๐ŸŽฏ Key Features

  • 3 Specialized Agents working in perfect coordination through Google ADK
  • <3s response time for simple tasks, scales with complexity
  • Smart dependency resolution for multi-step crafting workflows
  • Pattern matching for flexible resource discovery (e.g., any wood type)
  • AI-driven decisions using real Minecraft world data provided through specialized tools

๐ŸŽฏ The Challenge

Minecraft players face complex multi-step tasks daily:

  • ๐Ÿชต "I need sticks" โ†’ But first need planks โ†’ But first need logs โ†’ Must find trees
  • โ›๏ธ "Craft a pickaxe" โ†’ Need sticks + planks + correct pattern โ†’ Multiple dependencies
  • ๐Ÿ—๏ธ "Build a house" โ†’ Gather materials โ†’ Clear land โ†’ Plan layout โ†’ Execute

Traditional bots fail because they can't plan, adapt, or coordinate complex workflows.

๐Ÿ’ก Our Solution: AI Agent Guild

We've created specialized AI agents that work together like a medieval guild:

  • ๐ŸŽญ Coordinator Agent: The guild master who understands requests and delegates tasks
  • ๐ŸŒฒ Gatherer Agent: The resource specialist who finds and collects materials
  • ๐Ÿ”จ Crafter Agent: The artisan who transforms materials into tools and items

Using Google ADK's AgentTool pattern, these agents collaborate through shared state to accomplish complex goals that would be impossible for a single agent.

๐Ÿš€ See It In Action

# Simple commands trigger complex multi-agent workflows
python main.py "craft a wooden pickaxe"

# Example output:
๐Ÿ’ญ [CoordinatorAgent] Thinking: I need to craft a wooden pickaxe...
๐Ÿ”ง [CoordinatorAgent] Calling tool: get_inventory
โœ“ [CoordinatorAgent] Tool get_inventory completed in 217ms
โ†’ [CoordinatorAgent] Delegating to GathererAgent
๐ŸŒฒ [GathererAgent] Searching for oak_log within 32 blocks...
โœ“ [GathererAgent] Found 15 oak logs, gathering 3...
โ†’ [CoordinatorAgent] Delegating to CrafterAgent  
๐Ÿ”จ [CrafterAgent] Crafting oak_planks from oak_log...
โœ“ [CrafterAgent] Successfully crafted 12 oak_planks
๐Ÿ”จ [CrafterAgent] Crafting stick from oak_planks...
โœ“ [CrafterAgent] Successfully crafted 8 sticks
๐Ÿ”จ [CrafterAgent] Crafting wooden_pickaxe...
โœ“ [CrafterAgent] Successfully crafted 1 wooden_pickaxe

โœ… Successfully crafted a wooden pickaxe! It's now in your inventory.

๐ŸŽฎ Interactive Mode - Persistent AI Memory

python main.py --interactive

Minecraft Agent> gather 10 oak logs
โœ“ Gathered 10 oak logs near position (123, 64, -456)

Minecraft Agent> craft planks  
โœ“ Crafted 40 oak planks from 10 oak logs

Minecraft Agent> craft sticks
โœ“ Crafted 32 sticks from 8 oak planks

Minecraft Agent> what's in my inventory?
Your inventory contains: 32 oak planks, 32 sticks

๐Ÿ—๏ธ Architecture

Architecture Diagram

๐Ÿ’ก ADK Integration Highlights

  • AgentTool Pattern: Sub-agents (Gatherer, Crafter) are exposed as tools to the Coordinator
  • Structured Outputs: Each agent returns results via output_key to session state
  • Minecraft Data Access: Real game data (blocks, items, recipes) provided through MinecraftDataService (ref: minecraft-data)
  • Tool Wrapping: Mineflayer bot functions wrapped as ADK-compatible async tools
  • Session Persistence: State maintained across all interactions in a session

๐Ÿง  Agent Intelligence Layers

  1. ๐ŸŽฏ Coordinator Agent (Strategic Layer)

    • Natural language understanding
    • Multi-step planning and dependency resolution
    • Sub-agent orchestration
    • Result interpretation and user communication
  2. ๐ŸŒฒ Gatherer Agent (Resource Layer)

    • Pattern-based block finding (*_log finds all wood types)
    • Pathfinding and navigation
    • Efficient resource collection
    • Inventory management
  3. ๐Ÿ”จ Crafter Agent (Creation Layer)

    • Recipe knowledge and validation
    • Material requirement checking
    • Multi-step crafting workflows
    • Success/failure reporting

๐ŸŒ‰ Bridge Innovation

Our Pythonโ†”JavaScript Bridge enables:

  • Real-time bidirectional communication
  • Event streaming from game to agents
  • Command queuing and prioritization
  • Automatic reconnection and error recovery

โœจ Advanced Features

๐Ÿค– Multi-Agent Coordination

  • AgentTool Pattern: Sub-agents are tools that return structured results
  • Shared State: Agents communicate through persistent session state
  • Smart Delegation: Coordinator knows which agent to use for each task
  • Result Verification: Never assumes success - always checks actual outcomes

๐ŸŽฏ Intelligent Task Planning

  • Dependency Resolution: Automatically figures out prerequisite tasks
  • Pattern Matching: find_blocks("*_log") finds any type of wood
  • Context Awareness: Understands "nearby", "there", relative directions
  • Failure Recovery: Graceful handling with helpful suggestions

๐Ÿ”ง Production-Ready Infrastructure

  • Structured Logging: JSON logs for analysis, colored console for development
  • Configuration Management: Environment-based config with validation
  • Error Boundaries: Comprehensive error handling at every layer
  • Type Safety: Pydantic models for internal data validation
  • Cloud Deployment: Successfully deployed to GCP (see feature/gcp-deployment branch)
    • Agents deployed on Google Agent Engine โœ…
    • Minecraft server on Compute Engine โœ…
    • Bot connectivity issues prevented merging (Users could connect to the server but the bot couldn't)

๐ŸŒ Multiple Interfaces

  • CLI Mode: One-off commands for scripts
  • Interactive Mode: Persistent session with command history
  • Web UI: Test agents without Minecraft server (via adk web)
  • API Mode: RESTful endpoints for external integration

๐Ÿ“ Project Structure

minecraft-adk-guild/
โ”œโ”€โ”€ minecraft_coordinator/   # Guild master agent
โ”‚   โ”œโ”€โ”€ agent.py            # AgentTool orchestration
โ”‚   โ”œโ”€โ”€ prompt.py           # Coordination instructions
โ”‚   โ””โ”€โ”€ callbacks.py        # Logging callbacks
โ”œโ”€โ”€ minecraft_gatherer/      # Resource specialist agent
โ”‚   โ”œโ”€โ”€ agent.py            # Collection logic
โ”‚   โ””โ”€โ”€ prompt.py           # Gathering instructions
โ”œโ”€โ”€ minecraft_crafter/       # Crafting specialist agent
โ”‚   โ”œโ”€โ”€ agent.py            # Recipe execution
โ”‚   โ””โ”€โ”€ prompt.py           # Crafting instructions
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ bridge/             # Pythonโ†”JavaScript communication
โ”‚   โ”œโ”€โ”€ minecraft/          # Mineflayer bot implementation
โ”‚   โ”œโ”€โ”€ tools/              # ADK tool wrappers
โ”‚   โ””โ”€โ”€ minecraft_data_service.py  # Game data lookups
โ”œโ”€โ”€ main.py                 # Entry point for CLI/interactive mode
โ””โ”€โ”€ docs/                   # Documentation and diagrams

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • Minecraft Java Edition 1.21+ (only needed if you want to join the same game yourself)
  • Google AI API Key (Get one here)

Quick Start

# Clone the repository
git clone https://github.com/yourusername/minecraft-adk-guild.git
cd minecraft-adk-guild

# Install dependencies
npm install
pip install -e .

# Configure environment
cp .env.example .env
# Edit .env with your API key

๐Ÿงช Try Agent Logic Without Minecraft Server

# Test agent reasoning with ADK Web UI
adk web

# Open http://localhost:8000
# Select "minecraft_coordinator" from dropdown
# Try commands like "craft a pickaxe" to see agent coordination

ADK Web UI showing agent coordination

Note: The ADK Web UI cannot fully connect the bot to an actual Minecraft server, but it demonstrates agent interactions, tool calls, and decision-making processes as shown in the image above. For full bot functionality, use python main.py --interactive.

๐ŸŽฎ With Minecraft Server

# Start your Minecraft server (1.21+)
# Then run:
python main.py "check inventory"

๐Ÿณ Docker Installation

# Build and run with Docker Compose
docker-compose up -d

# Execute commands
docker-compose exec bot python main.py "gather wood"

๐ŸŽฎ Usage Examples

Basic Commands

# Inventory management
python main.py "check inventory"
python main.py "toss 10 dirt"

# Resource gathering
python main.py "gather wood"        # Finds any type of logs
python main.py "gather 5 oak logs"  # Specific type
python main.py "mine stone"         # Searches underground

# Crafting operations
python main.py "craft sticks"       # Handles dependencies
python main.py "craft wooden sword" # Multi-step crafting

# World interaction
python main.py "move to 100 64 -200"
python main.py "remove the stairs nearby"  # Contextual understanding

Advanced Workflows

# Complex multi-step task
python main.py "prepare for mining"
# Agents will:
# 1. Check if you have a pickaxe
# 2. If not, gather wood
# 3. Craft planks and sticks  
# 4. Craft wooden pickaxe
# 5. Report ready status

๐Ÿ”ฌ Technical Deep Dive

Google ADK Patterns Used

  1. AgentTool Pattern

    tools = [
        AgentTool(agent=gatherer_agent),
        AgentTool(agent=crafter_agent),
    ]
  2. Structured Output with State

    gatherer = LlmAgent(
        name="GathererAgent",
        output_key="gathering_result",  # Results go to state
        instruction=GATHERER_PROMPT,
    )
  3. Session Persistence

    session_service = InMemorySessionService()
    # State persists across all commands in session

Performance & Technical Metrics

  • โšก Response Time: <3s for simple tasks, scales with complexity
  • ๐ŸŽฏ Pathfinding: Handles 100+ block distances efficiently
  • ๐Ÿ“Š State Management: O(1) state access with ADK session state
  • ๐Ÿ”„ Concurrent Operations: WebSocket + async for parallel tasks
  • ๐Ÿง  Context Window: Efficient prompt design keeps tokens <2K per request
  • ๐Ÿ“ˆ Scalability: Add new agents without modifying existing ones
  • ๐ŸŒ Real Game Data: 3000+ Minecraft items/blocks/recipes available to agents thanks to minecraft-data

๐Ÿ”„ Deep Dive: Interactive Agent Loop Architecture

Interactive Agent Loop

The interactive mode implements a sophisticated command processing pipeline that maintains persistent state across all interactions:

How It Works

  1. User Input Stage: Commands enter through a non-blocking input thread, allowing the system to process previous commands while accepting new ones.

  2. Command Queue: All commands are added to an async queue (asyncio.Queue), ensuring proper ordering and preventing race conditions.

  3. Background Processor: A dedicated coroutine continuously monitors the queue, pulling commands as they arrive and processing them sequentially.

  4. Agent Execution: The Coordinator Agent receives each command with full session context, enabling it to reference previous actions and maintain conversation continuity.

  5. State Persistence: Every tool execution automatically updates the ADK session state, creating a growing knowledge base throughout the session.

  6. Response Display: Results stream back to the user in real-time, with agent thoughts and tool calls visible for transparency.

Key Benefits

  • Non-blocking: Users can type new commands while previous ones process
  • Ordered Execution: Commands always execute in the order received
  • State Continuity: "craft planks" followed by "craft sticks" works seamlessly
  • Error Recovery: Failed commands don't crash the session
  • Resource Efficiency: Single bot connection serves entire session

๐Ÿ› ๏ธ Extending the Guild

Add new specialist agents easily:

# Create a new specialist
builder_agent = LlmAgent(
    name="BuilderAgent",
    instruction="You are a construction specialist...",
    output_key="building_result",
    tools=building_tools,
)

# Add to coordinator's toolkit
tools.append(AgentTool(agent=builder_agent))

๐Ÿค Contributing

Development Setup

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
black . && ruff check .

# Test with ADK Web UI
adk web

๐Ÿ“ˆ Future Vision

  • ๐Ÿฐ Building Agent: Construct structures from blueprints
  • ๐Ÿ›ก๏ธ Combat Agent: Defend against mobs
  • ๐ŸŒพ Farming Agent: Automate crop cultivation
  • ๐Ÿ” Explorer Agent: Map new territories
  • ๐Ÿค Social Agent: Interact with other players

๐Ÿ“„ License

This project is licensed under the MIT License - see LICENSE for details.

๐Ÿ™ Acknowledgments

  • Google ADK team for the powerful multi-agent framework
  • Mineflayer community for the excellent Minecraft bot library
  • Minecraft for being an amazing sandbox for AI experimentation

About

Creating a bot in Minecraft using Google's ADK and Mineflayer

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages