tokin makes any agent harness token-native. Train an agent in the harness it ships with, on exactly the tokens it sampled. Point the harness at tokin instead of the inference engine and nothing else changes: it keeps speaking text over chat completions, while the engine only ever sees token ids. tokin keeps each session as a tree of turns, so every rollout a trainer collects is token-in, token-out at every prefix.
Serve a model with sglang, and put tokin in front of it, each in its own terminal:
pip install tokin
python -m sglang.launch_server --model-path Qwen/Qwen3.5-0.8B --port 30000
tokin serve --model-path Qwen/Qwen3.5-0.8B --engine-url http://localhost:30000Open a session for each sample. It prints the base URL the harness takes:
URL=$(tokin open --params '{"return_logprobs": true}')For pi, add that URL as a provider in ~/.pi/agent/models.json, then run
pi as usual:
{
"providers": {
"tokin": {
"baseUrl": "<URL>",
"api": "openai-completions",
"apiKey": "tokin",
"models": [{ "id": "Qwen/Qwen3.5-0.8B" }]
}
}
}pi --provider tokin --model Qwen/Qwen3.5-0.8B "Write a haiku about tokens to haiku.txt."For Codex, which speaks the Responses API, add it as a provider in
~/.codex/config.toml instead; examples/harbor_eval has a full setup:
model_provider = "tokin"
web_search = "disabled"
model_reasoning_summary = "none"
[model_providers.tokin]
name = "tokin"
base_url = "<URL>"
wire_api = "responses"
supports_websockets = falseCollect the session, one JSON line per rollout with its token_ids, loss_mask and
logprobs:
tokin collect "$URL" -o rollouts.jsonlexamples/harbor_eval: evaluate mini-swe-agent, opencode, pi or Codex through tokin on Harbor.examples/pi_mimo_rl: train pi with slime on MiMo-V2.6-RL-oss.