Chat AI Player - Autonomous Character Controller
Creates and controls AI character entities in Factorio 2.0. AI characters can patrol and collect resources, build ghosts, auto-craft items, follow the player in combat mode, and execute one-shot commands — all without external dependencies.
Installation
Option 1: Manual install (from zip)
- Download
chat-ai-player_0.1.0.zip - Extract to
%APPDATA%\Factorio\mods\ - Enable the mod in Factorio's mod manager
- Restart Factorio
Option 2: Development install (junction)
New-Item -ItemType Junction `
-Path "$env:APPDATA\Factorio\mods\chat-ai-player" `
-Target "C:\path\to\chat-ai-player"
After code changes, use /reload in-game to hot-reload (no restart needed).
Requirements
- Factorio >= 2.0.0
- No external mod dependencies (pure base mod)
Quick Start
- Launch Factorio with the mod enabled
- Open chat and type
!ai 创建AI(Chinese) or!ai spawn(English) to spawn an AI character - Try these commands:
English Commands
| Command | What it does |
|---|---|
!ai spawn |
Spawn a new AI character |
!ai mine |
Collect all nearby resources |
!ai mine iron |
Collect iron ore only |
!ai mine iron copper |
Collect iron and copper |
!ai build patrol |
Auto-build ghosts in the area |
!ai auto craft |
Auto-craft materials from ghosts |
!ai follow |
Follow player, auto-attack enemies |
!ai stop |
Stop all AI behavior |
!ai status |
Show AI status |
!ai craft transport-belt 10 |
Craft 10 belts immediately |
!ai goto 50,50 |
Move to coordinates (50,50) |
Chinese Commands
| Command | What it does |
|---|---|
!ai 创建AI |
Spawn a new AI character |
!ai 采矿铁 |
Start patrol-collecting iron ore |
!ai 采矿铁铜煤 |
Collect iron, copper, coal |
!ai 巡逻建造 |
Auto-build ghosts in the area |
!ai 自动手搓 |
Auto-craft materials from ghosts |
!ai 战斗跟随 |
Follow player, auto-attack enemies |
!ai 停止 |
Stop all AI behavior |
!ai 查询AI |
Show AI status |
!ai 手搓传送带10 |
Craft 10 belts immediately |
!ai 移动到50,50 |
Move to coordinates (50,50) |
Console Commands
| Command | Description |
|---|---|
/ai |
Toggle GUI panel |
/ai <command> |
Same as !ai <command> |
/ai-spawn |
Spawn AI character at player |
/reload |
Hot-reload mod code |
Shortcuts
Ctrl+Alt+P— Toggle GUI panelCtrl+Shift+P— Confirm AI character selection
Behavior Modes
| Mode | Description |
|---|---|
| patrol_collect | Cycle: scan resource patch → move → mine → return to depot → deposit |
| build_patrol | Scan ghosts + deconstruction marks → fetch materials → move → build/deconstruct |
| auto_craft | Scan ghosts → calculate material gaps → fetch ingredients → craft → store |
| combat_follow | Follow player → detect enemies → auto-shoot → refill ammo from chests |
LLM Integration (Optional)
When keyword matching doesn't recognize a command, the mod can fall back to an LLM for natural language understanding. To enable:
- Install and run Ollama (or any OpenAI-compatible API)
- Configure in Factorio: Settings → Mod settings → Startup → Chat AI Player
- Set LLM endpoint, model name, and API key
Mod writes request file → external Python bridge reads it → calls LLM API
→ sends response via RCON → mod parses and executes
In keyword-only mode (no LLM), the mod works standalone with Chinese and English keyword matching.
Logging
Runtime logs are written to script-output/chat_ai_player.log. To access from the project directory:
New-Item -ItemType Junction `
-Path "C:\path\to\log\ai-player-output" `
-Target "$env:APPDATA\Factorio\script-output"
Files
chat-ai-player/
├── info.json # Mod metadata
├── control.lua # Event listeners, RCON, command dispatch
├── data.lua # Custom input registration (shortcuts)
├── settings.lua # LLM config, command prefix, thresholds
├── scripts/
│ ├── character_manager.lua # AI char lifecycle: spawn, associate, respawn
│ ├── actions.lua # Atomic actions: walk, mine, scan, shoot, inventory
│ ├── behavior_engine.lua # State machines for all 4 behavior modes
│ ├── commands.lua # Intent enum, keyword rules, priority
│ ├── interpreter.lua # Command validation, param completion, resource names
│ ├── pathfinding.lua # A* pathfinding with collision avoidance
│ ├── crafting.lua # Recipe tree decomposition, material gap analysis
│ ├── llm_client.lua # Request file writer, response parser
│ ├── resource_map.lua # Chinese↔English name map
│ ├── gui.lua # In-game GUI panel
│ └── logger.lua # Rotating file logger
License
MIT