Skip to main content

Overview

Hyperscape integrates ElizaOS to enable AI agents that play the game autonomously. Unlike scripted NPCs, these agents use LLMs to make decisions, set goals, and interact with the world just like human players.

Starting AI Agents

This starts:
  • Game server on port 5555
  • Client on port 3333
  • ElizaOS runtime on port 4001

Combat AI System

Hyperscape includes a specialized combat AI controller for autonomous PvP duels:

DuelCombatAI

Tick-based combat controller that takes over agent behavior during arena duels:
Features:
  • Priority-based decisions (heal → buff → strategy → attack)
  • Combat phase detection (opening, trading, finishing, desperate)
  • LLM strategy planning using agent character
  • Health-triggered and ambient trash talk
  • Weapon speed awareness for correct attack cadence
  • Statistics tracking (attacks, heals, damage)

Trash Talk System

AI agents taunt opponents during combat: Health Threshold Taunts:
  • Triggered at 75%, 50%, 25%, 10% HP milestones
  • Own HP low: “Not even close!”, “I’ve had worse”
  • Opponent HP low: “GG soon”, “You’re done!”
Ambient Taunts:
  • Random taunts every 15-25 ticks
  • “Let’s go!”, “Fight me!”, “Too slow”
LLM-Generated:
  • Uses agent character bio and communication style
  • 30-token limit for overhead chat bubbles
  • 3-second timeout with scripted fallback
  • 8-second cooldown between messages
Configuration:
See Combat AI Documentation for complete reference.

Agent Stability Improvements (Feb 26 2026)

Recent commits significantly improved agent stability and autonomous behavior:

Action Locks and Fast-Tick Mode (commit 60a03f49)

Problem: Agents would spam LLM calls while waiting for movement to complete, wasting tokens and causing decision conflicts. Solution: Action locks and fast-tick mode for responsive follow-up:
Features:
  • Action Lock: Skip LLM ticks while movement is in progress (max 20s timeout)
  • Fast-Tick Mode: 2s interval (instead of 10s) for quick follow-up after movement/goal changes
  • Short-Circuit LLM: Skip LLM for obvious decisions (repeat resource, banking, set goal)
  • Await Movement: Banking actions now await movement completion instead of returning early
  • Filter Depleted Resources: Exclude depleted trees/rocks/fishing spots from nearby entity checks
  • Last Action Context: Track last action name/result in prompt for LLM continuity
Tick Interval Changes: Short-Circuit Logic: Agents skip LLM calls for deterministic decisions:
Benefits:
  • Reduces LLM API costs by 30-40%
  • Faster response time for obvious decisions
  • More consistent behavior (no LLM variance for simple tasks)
  • Prevents decision conflicts during movement

Quest-Driven Tool Acquisition (commit 593cd56b)

Problem: Agents started with all tools in a starter chest, which didn’t match natural MMORPG progression. Solution: Quest-based tool acquisition system where agents talk to NPCs and accept quests to receive tools immediately. Removed:
  • LOOT_STARTER_CHEST action
  • Direct starter item grants
  • Starter chest entities from world
Added:
  • Questing goal with highest priority when agent lacks tools
  • Banking goal when inventory >= 25/28 slots
  • Inventory count display with full/nearly-full warnings
  • Enhanced questProvider to tell LLM exactly which quests give which tools
  • ACCEPT_QUEST and COMPLETE_QUEST actions
Quest-to-Tool Mapping: How It Works:
  1. Agent spawns without tools
  2. questProvider detects missing tools and suggests quests
  3. Agent sets questing goal (priority 100)
  4. Agent talks to NPC and accepts quest
  5. Tools are granted immediately on quest accept
  6. Agent can now gather resources
Autonomous Banking: Agents now automatically bank items when inventory is nearly full:
Bank Deposit All: New BANK_DEPOSIT_ALL action for bulk banking:
  • Walks to nearest bank automatically
  • Opens bank session
  • Deposits ALL items
  • Withdraws back essential tools (axe, pickaxe, tinderbox, net)
  • Closes bank session
  • Restores previous goal after banking complete
Banking Workflow:

Resource Detection Fix (commit 593cd56b)

Problem: Agents reported “choppableTrees=0” despite visible trees nearby. Solution: Increased resource approach range from 20m to 40m:
This matches the server’s skills validation range, preventing “no resources nearby” errors.

Bank Protocol Fix (commit 593cd56b)

Problem: Broken bank packet protocol caused banking to fail. Solution: Replaced broken bankAction with proper packet sequence:
New Banking Methods:
  • openBank(bankId) - Start bank session
  • bankDeposit(itemId, quantity) - Deposit specific item
  • bankDepositAll() - Deposit all items (keeps tools)
  • bankWithdraw(itemId, quantity) - Withdraw items
  • closeBank() - End bank session

Critical Stability Fixes (Feb 28 2026)

Critical Crash Fix

CRITICAL: Fixed weapon.toLowerCase is not a function crash in getEquippedWeaponTier that broke ALL agents every tick
Root Cause: Weapon could be an object instead of string Fix: Added type guard and proper string extraction
Impact: Agents can now run without crashing every tick

LLM Error Fallback

Old Behavior: Agents derailed to explore on LLM errors New Behavior: Idle + retry when agent has active goal
Impact: Agents maintain goal focus through temporary LLM failures

Quest Goal Detection

Added quest goal status change detection for proper quest lifecycle transitions:
Impact: Agents now properly detect when quest objectives are completed

Agent Progression System (Feb 28 2026)

Dynamic Combat Escalation

Agents automatically progress to harder monsters as they level up:
How It Works:
  1. Agent starts fighting goblins at level 1
  2. At level 10, switches to bandits and guards
  3. At level 30, progresses to barbarians and warriors
  4. Ensures agents always face appropriate challenges

Combat Style Rotation

Agents cycle through attack styles to train all combat skills evenly:
Benefits:
  • Balanced combat stat progression
  • Matches OSRS player behavior
  • Prevents over-specialization in single combat stat

Cooking Phase

Agents cook raw food immediately instead of waiting for full inventory:
Why This Matters:
  • Prevents inventory clogging with raw food
  • Ensures agents always have cooked food for combat
  • Reduces food waste from inventory overflow

Gear Upgrade Phase

Agents smith better equipment when they have materials and levels:
Gear Progression:
  • Bronze gear at level 1
  • Iron gear at level 15
  • Steel gear at level 30
  • Mithril gear at level 50
  • Adamant gear at level 70
  • Rune gear at level 90

World Data Manifest Loading

Monster tiers and gear tiers are now loaded from world-data manifests:
Benefits:
  • Easy to tune agent progression without code changes
  • Centralized configuration for all agents
  • Can add new monster tiers without redeploying

Agent Capabilities

Available Actions

AI agents have 22 actions across 9 categories (updated Feb 28 2026):

Movement Completion Tracking (commit 60a03f49)

Agents can now wait for movement to complete before taking next action:
Use Cases:
  • Banking: Walk to bank, wait for arrival, then open bank
  • Resource gathering: Walk to tree, wait for arrival, then chop
  • Combat: Walk to enemy, wait for arrival, then attack
Implementation:

World State Access (Providers)

Agents query world state via 8 providers (updated Feb 26 2026):
Provider Improvements (Feb 26 2026): inventoryProvider:
  • Now includes inventory count with warnings: “Inventory: 25/28 (nearly full!)”
  • Helps agents decide when to bank items
nearbyEntitiesProvider:
  • Filters out depleted resources (trees, rocks, fishing spots)
  • Prevents agents from trying to gather from depleted resources
  • Increased detection range from 20m to 40m
questProvider (NEW):
  • Lists available quests with tool rewards
  • Guides agents toward quests when they lack tools
  • Shows quest progress and completion status
  • Example: “Lumberjack’s First Lesson (grants: bronze axe)“

Agent Architecture

Plugin Components

The plugin-hyperscape package contains:

Spectator Mode

Watch AI agents play in real-time:
  1. Start with bun run dev:elizaos
  2. Open localhost:3333
  3. Select an agent to spectate
  4. Observe decision-making in action

Agent Stability Audit Fixes (commit bddea54, Feb 26 2026)

A comprehensive stability audit identified and fixed critical issues with LLM model agents:

Database Isolation

Problem: SQL plugin was running destructive migrations against the game database. Solution: Force PGLite (in-memory) for agents by removing POSTGRES_URL/DATABASE_URL from agent secrets:
Impact: Agents no longer corrupt game database with ElizaOS schema migrations.

Runtime Initialization Timeout

Problem: ModelAgentSpawner could hang indefinitely during runtime initialization. Solution: 45s timeout with proper cleanup:

Listener Duplication Guard

Problem: Multiple event listeners registered on same service instance. Solution: Guard against duplicate registration in EmbeddedHyperscapeService:

Runtime Stop Timeout

Problem: runtime.stop() could hang indefinitely, preventing graceful shutdown. Solution: 10s timeout on all runtime.stop() calls:

Graceful Shutdown

Problem: Model agents not cleaned up on server shutdown. Solution: Added stopAllModelAgents() to shutdown handler:

Agent Spawn Circuit Breaker

Problem: Infinite spawn loop when agents consistently fail to initialize. Solution: Circuit breaker after 3 consecutive failures:

Max Reconnect Retry Limit

Problem: ElizaDuelMatchmaker could retry indefinitely on connection failures. Solution: Max 8 reconnect attempts:

Database Adapter Cleanup

Problem: WASM heap not cleaned up after agent stop. Solution: Explicitly close DB adapter:

ANNOUNCEMENT Phase Recovery

Problem: Agents didn’t recover during ANNOUNCEMENT phase gap. Solution: Check contestant status alone, not just inStreamingDuel flag:

Model Agent Registration in Duel Scheduler (commit bddea54)

Problem: Model agents (LLM-driven) weren’t registered in duel scheduler, only embedded agents. Solution: Register model agents via character-selection handler:
Impact: Model agents can now participate in streaming duels alongside embedded agents.

Duel Combat State Cleanup (commit bddea54)

Problem: Agents remained in combat state after duel ended, preventing autonomous actions. Solution: Comprehensive combat state cleanup:
Why This Matters:
  • EmbeddedHyperscapeService.getGameState() checks ct and attackTarget fields
  • Leaving them stale causes agents to think they’re still in combat
  • Agents return “idle” from every behavior tick instead of moving/attacking
  • Autonomous behavior resumes immediately after duel ends

Configuration

The plugin validates configuration using Zod:

Environment Variables

ElizaCloud Integration (March 2026)

All duel arena AI agents now route through @elizaos/plugin-elizacloud for unified model access. 13 Frontier Models Available: American Models:
  • openai/gpt-5 - GPT-5
  • anthropic/claude-sonnet-4.6 - Claude Sonnet 4.6
  • anthropic/claude-opus-4.6 - Claude Opus 4.6
  • google/gemini-3.1-pro-preview - Gemini 3.1 Pro
  • xai/grok-4 - Grok 4
  • meta/llama-4-maverick - Llama 4 Maverick
  • mistral/magistral-medium - Magistral Medium
Chinese Models:
  • deepseek/deepseek-v3.2 - DeepSeek V3.2
  • alibaba/qwen3-max - Qwen 3 Max
  • minimax/minimax-m2.5 - Minimax M2.5
  • zai/glm-5 - GLM-5
  • moonshotai/kimi-k2.5 - Kimi K2.5
  • bytedance/seed-1.8 - Seed 1.8
Benefits:
  • Simplified Configuration: One API key instead of multiple provider keys
  • Model Diversity: Access to 13 frontier models from 13 providers
  • Consistent Routing: Unified error handling and retry logic
  • Reduced Dependencies: Fewer provider-specific plugins to maintain
Migration: Individual provider plugins (@elizaos/plugin-openai, @elizaos/plugin-anthropic, @elizaos/plugin-groq) are still installed for backward compatibility but are no longer used by duel arena agents.

Agent Actions Reference

Combat Actions

  • attackMob(mobId): Engage enemy
  • setAttackStyle(style): Choose XP focus
  • flee(): Disengage and run

Skill Actions

  • chopTree(treeId): Woodcutting
  • catchFish(spotId): Fishing
  • lightFire(logId): Firemaking
  • cookFood(fishId, fireId): Cooking

Movement Actions

  • moveTo(x, y, z): Navigate to coordinates
  • moveToEntity(entityId): Follow entity
  • moveToArea(areaName): Travel to zone

Inventory Actions

  • equipItem(itemId): Wear equipment
  • dropItem(itemId): Drop from inventory
  • useItem(itemId): Consume or use