Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Custom Models

Add your own AI model configurations to Tinytown.

Model Configuration

Models are defined in tinytown.toml:

[agent_clis.claude]
name = "claude"
command = "claude --print"

[agent_clis.my-custom-model]
name = "my-custom-model"
command = "/path/to/my/agent --config ./agent.yaml"
workdir = "/path/to/working/dir"

[agent_clis.my-custom-model.env]
API_KEY = "secret"
MODEL_VERSION = "v2"

Model Properties

PropertyRequiredDescription
nameYesIdentifier for --model flag
commandYesShell command to run the agent
workdirNoWorking directory for the command
envNoEnvironment variables

Example: Local LLM

[agent_clis.local-llama]
name = "local-llama"
command = "llama-cli --model llama-3-70b --prompt-file task.txt"
workdir = "~/.local/share/llama"

[agent_clis.local-llama.env]
CUDA_VISIBLE_DEVICES = "0"

Usage:

tt spawn worker-1 --model local-llama

Example: Custom Script

Create a wrapper script:

#!/bin/bash
# ~/bin/my-agent.sh

# Read task from stdin or argument
TASK="$1"

# Your custom agent logic
python3 ~/agents/my_agent.py --task "$TASK"

Configure:

[agent_clis.my-agent]
name = "my-agent"
command = "~/bin/my-agent.sh"

Example: Docker Container

[agent_clis.docker-agent]
name = "docker-agent"
command = "docker run --rm -v $(pwd):/workspace my-agent:latest"

Programmatic Model Registration

In Rust code:

#![allow(unused)]
fn main() {
use tinytown::agent::AgentModel;

// Create custom model
let model = AgentModel::new("my-model", "my-command --flag")
    .with_workdir("/path/to/workdir")
    .with_env("API_KEY", "secret");

// Models are used when spawning
town.spawn_agent("worker", "my-model").await?;
}

Best Practices

  1. Use absolute paths — Relative paths may break
  2. Handle stdin/stdout — Agents should read tasks from messages
  3. Set timeouts — Don’t let agents run forever
  4. Log output — Direct to logs/ directory
  5. Test locally first — Before adding to config

Troubleshooting

Command Not Found

# Check the command works directly
/path/to/my/agent --help

Environment Variables Not Set

# Debug by adding echo
"command": "env && /path/to/agent"

Working Directory Issues

Use absolute paths:

workdir = "/Users/you/agents"

Not:

workdir = "./agents"  # May not resolve correctly