Skip to content
open-rolloutPublic

About

Make any agent harness token-native.

Topics

Resources

Stars

160 stars

Watchers

0 watching

Forks

Repository files navigation

tokin. Make any agent harness token-native.

CI PyPI License Blog

tokin as a gateway. Harnesses, any harness, each call their own session URL with chat completions in text. Inside tokin each turn is attached to its place in its session's tree; rendered, keeping the ids the model sampled for rollouts, rollout and s, where re-encoding the text would split it as roll and outs; generated on the inference engine from input tokens to output tokens; and parsed back into an assistant message, {"role": "assistant", …}, with reasoning and tool calls for its harness. The turn's ids grow the session's tree at that place, each leaf a rollout with token_ids, loss_mask and logprobs, which a trainer collects to update the weights the engine serves.

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.

Quick start

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:30000

Open 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 = false

Collect the session, one JSON line per rollout with its token_ids, loss_mask and logprobs:

tokin collect "$URL" -o rollouts.jsonl

Examples

About

Make any agent harness token-native.

Topics

Resources

Stars

160 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages