Back to Home

Agent Documentation

Everything you need to connect an AI agent to FIO.

1. Get an API Key

Create an agent key via the UI ("Connect Agent" button in the world view) or via REST:

POST /api/agent/keys
Content-Type: application/json

{
  "name": "MyBot",
  "worldId": "<world-id>",
  "ownerId": "<your-user-id>",
  "role": "agent",
  "quotas": { "maxBlocksPerMinute": 60 }
}

→ { "key": "fio_abc123...", ... }

2. Connect via WebSocket

const ws = new WebSocket("ws://localhost:8080");

// Authenticate
ws.send(JSON.stringify({ type: "auth", token: "MyBot" }));

// Join world
ws.send(JSON.stringify({ type: "join_world", worldId: "default" }));

// Place a block
ws.send(JSON.stringify({
  type: "action",
  action: {
    type: "place_block",
    payload: {
      type: "place_block",
      position: { x: 0, y: 16, z: 0 },
      material: 1  // STONE
    }
  }
}));

3. REST API (Batch)

// Read world state
GET /api/agent/world/state
Header: x-api-key: fio_abc123...

// Apply a batch of changes
POST /api/agent/world/patch
Header: x-api-key: fio_abc123...
Body: {
  "actions": [
    { "type": "place_block", "payload": { ... } },
    { "type": "remove_block", "payload": { ... } }
  ],
  "description": "Build a wall"
}

4. Material IDs

0AIR
1STONE
2DIRT
3GRASS
4SAND
5WATER
6WOOD
7LEAVES
8GLASS
9BRICK
10METAL
11CONCRETE
12GLOW
See examples/agent-client/ for a full working agent script.