AI Player

by ob_105

Adds an autonomous AI player that uses LM Studio/Open ai to play Factorio. The AI can build, mine, craft, fight, and interact with the world.

Utilities
14 days ago
2.0
409
Logistics Combat Character Enemies Logistic network Manufacturing

g LM Studio expecting different path in api?

15 days ago

I get the error below from the bridge and LM studios:

LM Studio raw response: {"error": "Unexpected endpoint or method. (POST /)"}

14 days ago

Thank you so much! I would have completely missed this

14 days ago

Fixed :D

14 days ago

Still having the same issue unfortunately.

14 days ago
(updated 14 days ago)

hmmm Go to developer Inside of LM Studio Make sure the local server is running Click on whatever AI model you want to use And you should See API usage to the right of the screen
1 Copy the model API identifier And put it into AI-player-model-name Setting in mod settings
2 Copy the local server address And put it into player-LM-studio-URL Setting in mod settings

If that doesn't work or that's already what you are doing I am horribly sorry I have not a clue
I will continue to look into this issue

14 days ago

Not seeing an issue with the prompts, looks more like an issue with the formatting of the message body for system context.

Here is the output from LMstudio's logs:

[2026-01-11 15:34:24][DEBUG] Received request: POST to / with body {
  "model": "qwen/qwen3-vl-4b",
  "messages": [
    {
      "role": "system",
      "content": "You are an AI playing Factorio. You control a character in the game world.\n\nYour goal is to survive, gather resources, build a factory, and automate production.\n\nYou receive information about your surroundings and status, and you must respond with actions to take.\n\nIMPORTANT: Use todo lists to organize your goals! Create a todo list for your factory plans, resource gathering, and major objectives. Break down tasks into manageable steps.\n\nIMPORTANT RULES:\n- You must be within ~5-10 tiles of an entity to MINE it. If it's far away, MOVE closer first.\n- You must be within ~5-10 tiles of a position to PLACE buildings. If it's far, MOVE closer first.\n- Check the \"distance\" field on entities - if distance > 8, move closer before mining/interacting.\n- You know your current position in character.position\n- Players can chat with you using messages like \"!ai build a furnace\". Always acknowledge them with a CHAT action and try to do what they asked.\n- Be proactive! Avoid just waiting - explore, gather, build, craft. Always have something to do.\n- If nothing is nearby, MOVE to explore. If you have materials, CRAFT or PLACE. WAIT only when enemies are near or you're in danger.\n\nAvailable actions:\n- MOVE: Move in a direction (north, south, east, west, northeast, northwest, southeast, southwest)\n  Format: {\"action\": \"move\", \"direction\": \"north\", \"distance\": 5}\n  Use this to get closer to resources or buildings before interacting with them.\n\n- MINE: Mine a nearby entity (trees, rocks, ore deposits). Must be within range!\n  Format: {\"action\": \"mine\", \"target\": \"entity_name\", \"position\": {\"x\": 10, \"y\": 20}}\n  Only use if the entity is nearby (distance < 8). Otherwise MOVE first.\n\n- PLACE: Place an item from inventory. Must be within range!\n  Format: {\"action\": \"place\", \"item\": \"item_name\", \"position\": {\"x\": 10, \"y\": 20}, \"direction\": \"north\"}\n  Only use if the position is close to you. Otherwise MOVE first.\n\n- INSERT: Put items from your inventory into a nearby container or furnace\n  Format: {\"action\": \"insert\", \"target\": \"iron-chest\", \"position\": {\"x\": 5, \"y\": 6}, \"item\": \"iron-plate\", \"count\": 20}\n  For furnaces you can set inventory:\"fuel\" or \"input\"; default is input. Stay within ~5 tiles.\n\n- TAKE: Withdraw items from a nearby container or furnace\n  Format: {\"action\": \"take\", \"target\": \"stone-furnace\", \"position\": {\"x\": 5, \"y\": 6}, \"item\": \"iron-plate\", \"count\": 10, \"inventory\": \"output\"}\n  For furnaces, inventory can be \"output\" (default), \"input\", or \"fuel\".\n\n- SUMMARY: Summarize what you just accomplished in 1-2 sentences; sent on next turn for continuity\n  Format: {\"action\": \"summary\", \"text\": \"I mined 50 copper ore and moved north to the tree line.\"}\n\n- CREATE_TODO: Create a new todo list for planning\n  Format: {\"action\": \"create_todo\", \"title\": \"Factory Setup\", \"items\": [\"Mine iron ore\", \"Build furnaces\", \"Automate belts\"]}\n\n- ADD_TODO: Add an item to a todo list\n  Format: {\"action\": \"add_todo\", \"list\": \"Factory Setup\", \"item\": \"Research steel\"}\n\n- COMPLETE_TODO: Mark a todo item as done\n  Format: {\"action\": \"complete_todo\", \"list\": \"Factory Setup\", \"item_index\": 0}\n\n- VIEW_TODO: View a todo list\n  Format: {\"action\": \"view_todo\", \"list\": \"Factory Setup\"}\n\n- ADD_NOTE: Save important information for future reference\n  Format: {\"action\": \"add_note\", \"text\": \"Found large iron deposit north at position (150, 200)\"}\n\n- VIEW_NOTES: View all saved notes\n  Format: {\"action\": \"view_notes\"}\n\n- CRAFT: Craft an item (if you have the recipe and materials)\n  Format: {\"action\": \"craft\", \"item\": \"item_name\", \"count\": 1}\n\n- PICKUP: Pick up items from the ground\n  Format: {\"action\": \"pickup\", \"position\": {\"x\": 10, \"y\": 20}}\n\n- SHOOT: Shoot at a target\n  Format: {\"action\": \"shoot\", \"target_position\": {\"x\": 10, \"y\": 20}}\n\n- CHAT: Send a message in chat\n  Format: {\"action\": \"chat\", \"message\": \"Hello, world!\"}\n\n- ROTATE: Rotate held item\n  Format: {\"action\": \"rotate\"}\n\n- WAIT: Do nothing this tick\n  Format: {\"action\": \"wait\"}\n\nStrategy tips:\n- If you see a resource far away (distance > 8), first MOVE toward it, then MINE it next turn\n- Calculate direction: if target.x > your.x go \"east\", if target.y < your.y go \"north\", etc\n- Combine directions: \"northeast\", \"southwest\", etc for diagonal movement\n- Plan ahead: move closer, then act on the target\n- When a player chats with you, first send a short friendly CHAT reply, then take the requested actions if possible.\n- ORGANIZE YOUR WORK: Create todo lists at the start for major goals (e.g., \"Early Game\", \"Iron Processing\", \"Factory Expansion\")\n- ADD todo items as you discover what needs to be done\n- COMPLETE_TODO items as you finish them\n- Refer to your todo lists to stay focused on your objectives\n\nRespond with a JSON array of actions to perform. You can return MULTIPLE actions in one response - they will all execute in order.\n\nExamples:\nSingle action: [{\"action\": \"move\", \"direction\": \"north\", \"distance\": 5}]\nMultiple actions: [{\"action\": \"chat\", \"message\": \"Moving to iron ore\"}, {\"action\": \"move\", \"direction\": \"east\", \"distance\": 8}]\nReply then act: [{\"action\": \"chat\", \"message\": \"Sure, I'll build a furnace\"}, {\"action\": \"craft\", \"item\": \"stone-furnace\", \"count\": 1}]\n\nKeep responses concise. Focus on immediate survival and progression needs."
    },
    {
      "role": "user",
      "content": "Current game state:\n{\"character\":{\"position\":{\"x\":-50,\"y\":-20},\"health\":250,\"max_health\":250,\"mining\":false,\"walking\":false,\"direction\":0,\"inventory_slots_used\":438,\"has_gun\":true,\"has_ammo\":true},\"nearby_entities\":[{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-49,\"y\":-31},\"health\":20,\"distance\":10},{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-39,\"y\":-32},\"health\":20,\"distance\":16},{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-68,\"y\":-27},\"health\":20,\"distance\":19},{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-61,\"y\":-26},\"health\":20,\"distance\":12},{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-55,\"y\":-26},\"health\":20,\"distance\":7},{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-63,\"y\":-23},\"health\":20,\"distance\":12},{\"name\":\"fish\",\"type\":\"fish\",\"position\":{\"x\":-65,\"y\":-21},\"health\":20,\"distance\":15}],\"nearby_resources\":[],\"inventory\":[{\"name\":\"transport-belt\",\"count\":50},{\"name\":\"coal\",\"count\":50},{\"name\":\"wood\",\"count\":50},{\"name\":\"stone\",\"count\":50},{\"name\":\"copper-plate\",\"count\":50},{\"name\":\"iron-plate\",\"count\":50},{\"name\":\"iron-gear-wheel\",\"count\":20},{\"name\":\"electronic-circuit\",\"count\":20},{\"name\":\"pipe\",\"count\":20},{\"name\":\"small-electric-pole\",\"count\":20},{\"name\":\"burner-inserter\",\"count\":20},{\"name\":\"inserter\",\"count\":20},{\"name\":\"burner-mining-drill\",\"count\":5},{\"name\":\"stone-furnace\",\"count\":5},{\"name\":\"assembling-machine-1\",\"count\":3}],\"craftable\":[\"wooden-chest\",\"iron-chest\",\"transport-belt\",\"underground-belt\",\"splitter\",\"burner-inserter\",\"long-handed-inserter\",\"stone-brick\",\"burner-mining-drill\",\"stone-furnace\",\"assembling-machine-1\",\"wood-recycling\",\"coal-recycling\",\"stone-furnace-recycling\",\"stone-recycling\",\"iron-gear-wheel-recycling\",\"iron-plate-recycling\",\"pipe-recycling\",\"copper-plate-recycling\",\"iron-gear-wheel\"],\"enemies\":[],\"environment\":{\"surface_name\":\"nauvis\",\"daytime\":0.7119047619048,\"darkness\":0.19047619402409,\"wind_speed\":0.02,\"peaceful_mode\":false,\"ticks_played\":300,\"pollution\":0}}\n\nWhat actions should I take? Respond with JSON array of actions."
    }
  ],
  "temperature": 0.7,
  "max_tokens": 500,
  "stream": false
}
[2026-01-11 15:34:24][ERROR] Unexpected endpoint or method. (POST /). Returning 200 anyway
14 days ago

Looking at it, It doesn't look like you are adding /v1/chat/completions to the uri. At least not in the python script.

14 days ago

What is your LM studio URL set to In factorio?

14 days ago
14 days ago

Got it. Now to get it to do something other than walk north. :)

14 days ago

lol Yeah if you have a very powerful computer I recommend using a smarter AI model

New response