Skip to main content

Overview

DuelCombatAI is a specialized tick-based combat controller that takes over an AI agent’s behavior during arena duels. It uses the EmbeddedHyperscapeService to execute game actions and makes priority-based combat decisions: heal, attack, or switch style.
DuelCombatAI operates at the same 600ms tick rate as the game’s combat system, ensuring synchronized attack timing.

Architecture

Lifecycle

Key Design Decision (commit 51453dae): The combat system’s auto-attack loop (processPlayerCombatTickprocessAutoAttackOnTick) drives the actual attack cadence once combat is established. The AI only needs to re-engage when:
  • Combat has dropped
  • Target has changed
Calling executeAttack on every cooldown cycle creates a redundant second driver that competes for the same cooldown slot, silently dropping attacks (especially for slow weapons like 2h swords).

Combat Phases

DuelCombatAI operates in four distinct phases:

Decision Priority

Each tick, the AI evaluates actions in this order:
  1. Heal - If HP below threshold, eat food
  2. Buff - If opening phase, use buff potions
  3. Strategy - Apply LLM-planned tactics (if enabled)
  4. Attack - Re-engage if combat dropped or target changed

Configuration

Default Configuration


LLM Strategy Planning

When useLlmTactics: true, the AI uses LLM to generate combat strategies:

Strategy Object

Planning Triggers

Strategy replanning occurs when:
  • First tick (initial strategy)
  • HP changes by more than 20%
  • Opponent drops below 25% HP
  • Entering desperate phase
Replanning Cooldown: 8 seconds minimum between LLM calls

LLM Prompt

Background Planning

Critical: Strategy planning runs in the background and NEVER blocks the tick loop:
LLM Timeout: 3 seconds maximum wait for LLM response before giving up

Trash Talk System

AI agents taunt opponents during combat using health-triggered and ambient messages.

Health Threshold Taunts

Triggered when HP crosses these milestones:
Own HP Low (agent taking damage):
  • “Not even close!”
  • “I’ve had worse”
  • “Is that all?”
  • “Still standing”
Opponent HP Low (agent winning):
  • “GG soon”
  • “You’re done!”
  • “Sit down”
  • “One more hit…”

Ambient Taunts

Random taunts every 5-12 ticks with no specific trigger:
  • “Let’s go!”
  • “Fight me!”
  • “Too slow”
  • “Bring it”
  • “Nice try lol”

Opening Taunts

Fired immediately when the duel starts:
  • “You’re going down”
  • “Let’s dance”
  • “Ready to lose?”
  • “This won’t take long”

LLM-Generated Trash Talk

When an AgentRuntime is provided, trash talk uses the agent’s character bio and communication style:
LLM Settings:
  • Model: TEXT_SMALL
  • Max tokens: 30
  • Temperature: 0.9 (high creativity)
  • Timeout: 3 seconds
Cooldown: 8 seconds between trash talk messages (configurable via TRASH_TALK_COOLDOWN_MS)

Fallback Behavior

If LLM fails or times out, the system uses scripted fallback taunts to ensure trash talk always works.

Attack Timing Fix (commit 51453dae)

Problem

Previously, DuelCombatAI manually tracked attack speed and called executeAttack on every cooldown cycle:
This created a redundant second attack driver that competed with the combat system’s built-in auto-attack loop, causing:
  • Silent attack drops for slow weapons (2h swords, halberds)
  • Desynchronization between AI and combat system
  • Missed attacks due to cooldown conflicts

Solution

The AI now only re-engages when combat has dropped or the target changed:
The combat system’s auto-attack loop handles all subsequent attacks at the correct weapon speed.

TWO_HAND_SWORD Default Style (commit 51453dae)

Added missing default attack style for two-handed swords in WeaponStyleConfig.ts:
Previously, two-handed swords had no configured styles, causing the combat system to fall back to “accurate” without showing available options.

Statistics Tracking

DuelCombatAI tracks combat statistics for analysis:

Environment Variables


Food Detection

DuelCombatAI automatically detects food items in inventory:
The AI selects the highest-healing food available when HP drops below threshold.

Potion Detection

Buff potions are detected by name patterns:
Potions are used during the opening phase (first 2 ticks) for combat buffs.

Performance Characteristics

  • Tick Rate: 600ms (synchronized with game combat system)
  • LLM Timeout: 3 seconds maximum
  • Planning Cooldown: 8 seconds between strategy replans
  • Trash Talk Cooldown: 8 seconds between messages
  • Background Processing: All LLM calls are fire-and-forget, never block ticks

Integration Example


Debugging

Enable debug logging to see combat AI decisions:
Statistics are logged on stop:

AI Agents Overview

ElizaOS integration and plugin architecture

Combat System

Core combat mechanics and tick-based system

Actions Reference

All available agent actions including combat

Configuration

Environment variables for combat AI