Tools Overview
Agents interact with the game using tools, which represent a narrow API into the game. Tools are functions that agents can call to perform actions and retrieve information.
What are Tools?
Tools are functions that:
Perform a game action (e.g., placing an entity, crafting an item)
Return a typed object (e.g.,
Entity,Inventory,Recipe)Can be stored as named variables in the Python namespace for later use
Tools live in fle/env/tools/, and are either:
Admin tools: Non-agent accessible, used for environment management
Agent tools: Used by agents to interact with the game
Tool Architecture
┌─────────────────┐
│ Agent │
│ (Synthesizes │
│ Python Code) │
└────────┬────────┘
│
┌────────▼────────────────────┐
│ Learning Environment │
│ ┌────────────────────┐ │
│ │ Interpreter │ │
│ └─────────┬──────────┘ │
│ │ │
│ ┌─────────▼──────────┐ │
│ │ client.py │◄───┼─── Exceptions
│ │ (Python Interface)│ │
│ └─────────┬──────────┘ │
│ │ │
│ │ Objects │
└────────────┼─────────────────┘
│
│ Remote TCP Call
│
┌────────────▼─────────────────┐
│ Factorio Server │
│ ┌─────────────────────┐ │
│ │ server.lua │ │
│ │ (Game Logic) │ │
│ └─────────┬───────────┘ │
│ │ │
│ ┌─────────▼───────────┐ │
│ │ Factorio Engine │ │
│ │ (Game Simulation) │ │
│ └─────────────────────┘ │
└──────────────────────────────┘
Anatomy of a Tool
A tool requires 3 files:
agent.md: The agent documentation for the tool, including usage patterns, best practices, and failure modes
client.py: The client-side implementation - a Python class that can be invoked by the agent
server.lua: The server-side implementation - handles most of the logic and heavy lifting
Tool Categories
Tools can be grouped into several categories:
Inventory Management
inspect_inventory: Check contents of player or entity inventoriesinsert_item: Place items from player inventory into entitiesextract_item: Remove items from entity inventories
Entity Manipulation
place_entity: Place entities in the worldplace_entity_next_to: Place entities relative to otherspickup_entity: Remove entities from the worldrotate_entity: Change entity orientationget_entity: Retrieve entity objects at positionsget_entities: Find multiple entities in an area
Resource Operations
nearest: Locate closest resources/entitiesget_resource_patch: Analyze resource depositsharvest_resource: Gather resources from the world
Connections
connect_entities: Create connections between entitiesget_connection_amount: Calculate required connection items
Crafting & Research
craft_item: Create items from componentsget_prototype_recipe: Retrieve crafting requirementsset_entity_recipe: Configure machine crafting recipesset_research: Initiate technology researchget_research_progress: Monitor research status
Movement & Utility
move_to: Move player to positionnearest_buildable: Find valid building locationssleep: Pause executionlaunch_rocket: Control rocket silo launches
Output
print: Output debug information to stdout
Using Tools
Tools are called like normal Python functions within agent code:
# Find nearest iron ore
iron_position = nearest(Resource.IronOre)
# Place a mining drill
drill = place_entity(
entity=Prototype.MiningDrill,
position=iron_position,
direction=Direction.NORTH
)
# Check the drill's status
print(f"Drill status: {drill.status}")
# Store result for later use
my_first_drill = drill
Return Values
Tools return typed objects that can be:
Inspected: Access attributes like
drill.statusorinventory.itemsStored: Save as variables for future reference
Printed: Display information to stdout for observation
Common Return Types
Entity: Represents a game entity (drill, chest, inserter, etc.)Inventory: Contains items and quantitiesRecipe: Describes crafting requirementsPosition: X, Y coordinatesResourcePatch: Information about resource deposits
Error Handling
Tools raise typed exceptions with detailed context when:
Invalid parameters are provided
Required resources are unavailable
Game constraints are violated (e.g., invalid placement)
Entities don’t exist or have been destroyed
Example error:
InvalidEntityPlacementException: Cannot place burner-mining-drill at
Position(x=10, y=20) - location is occupied by iron-chest
Next Steps
See Core Tools Reference for detailed documentation on each tool
Learn how to Creating Custom Tools for specialized functionality
Review the Environment Overview to understand the full context