Skip to content

tito: support agent-layer-inserted assistant messages in append segmentation#9

Open
DavidBellamy wants to merge 44 commits intomainfrom
fix/tito-assistant-append-role
Open

tito: support agent-layer-inserted assistant messages in append segmentation#9
DavidBellamy wants to merge 44 commits intomainfrom
fix/tito-assistant-append-role

Conversation

@DavidBellamy
Copy link
Copy Markdown
Collaborator

Summary

Error this fixes

File "miles/utils/chat_template_utils/tito_tokenizer.py", line 121, in _split_appended_segments
    raise ValueError(f"unsupported appended role for TITO segmentation: {role}")
ValueError: unsupported appended role for TITO segmentation: assistant

Reproduced 100% on RL360 job 1571608 (pd-hicache-l3-ep4, tblite + terminus-2).

Change

  • _split_appended_segments now accepts assistant alongside user/system.
  • New _tokenize_assistant_segment uses [_DUMMY_SYSTEM, _DUMMY_USER] as the synthetic base context so chat templates render assistant-turn boundary tokens correctly.
  • tokenize_additional_non_assistant gets the elif role == "assistant" branch. Function name retained for backward compatibility; docstring broadened.
  • Caller still needs --tito-allowed-append-roles to include assistant (already configured in RL360's agent cookbook).

Why this goes here, not only upstream

Production RL training on M2 is blocked on this. Upstream review cycle is unpredictable; LLM360/miles:deploy lets us unblock this week. Once radixark#1024 merges, octopus naturally reconciles.

Deploy path

  1. This merges → maintain-deploy workflow picks it up from "open PRs on LLM360/miles against its own main"
  2. deploy branch gets rebuilt tonight (or sooner if manually dispatched)
  3. nightly-image-rebuild.yml at 10:00 UTC builds agentic-rl-nightly-<YYYYMMDD> with new MILES_SHA
  4. RL360 PR bumps RL360_IMAGE_TAG + MILES_SHA in docker/versions.env

JD-ETH and others added 30 commits April 5, 2026 13:51
…pdating (radixark#890)

Co-authored-by: Yueming Yuan <yym022502@gmail.com>
Co-authored-by: Yueming Yuan <yueming@Mac.attlocal.net>
…adixark#654)

Co-authored-by: GuanxingLu <gxlu02@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… CLI args in swe-agent-v2 (radixark#954)

Co-authored-by: Shi Dong <shi.dong@radixark.ai>
…#952)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Yueming Yuan <yym022502@gmail.com>
…adixark#926)

Co-authored-by: guapisolo <guapisolo@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rmers >=5.0 (radixark#927)

Co-authored-by: guapisolo <guapisolo@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…#948)

Co-authored-by: guapisolo <guapisolo@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: maocheng23 <35615230+maocheng23@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…log dtype (radixark#975)

Co-authored-by: yueming-yuan <yym022502@gmail.com>
maocheng23 and others added 14 commits April 15, 2026 11:51
…adixark#974)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…on (radixark#949)

Co-authored-by: Yanbin Jiang <jybsuper@gmail.com>
)

Co-authored-by: maocheng23 <35615230+maocheng23@users.noreply.github.com>
Co-authored-by: Ethan (Yusheng) Su <yushengsu.thu@gmail.com>
Co-authored-by: Zhichen Zeng <zczeng@uw.edu>
…ntation

TITO is designed around the invariant that assistant turns are produced by
the inference engine and arrive as pretokenized IDs, so `_split_appended_
segments` and `tokenize_additional_non_assistant` only handled tool/user/
system roles. That invariant does not hold for agent frameworks that
insert their own non-generated assistant messages between tool calls
(e.g., terminus-2 self-reflection / planning turns).

When such a turn is appended to a session, the session server currently
500s with:
    ValueError: unsupported appended role for TITO segmentation: assistant

Add assistant as a supported append role alongside user/system. Inserted
assistant turns are tokenized with [_DUMMY_SYSTEM, _DUMMY_USER] as the
synthetic base context so chat-template renders produce correct
assistant-turn boundary tokens (most templates require an assistant turn
to follow a user/tool turn, not a system turn directly).

The function name `tokenize_additional_non_assistant` is kept for backward
compatibility; its docstring is updated to reflect the broadened semantics
("tokenize appended messages that were not generated by the inference
engine," which includes agent-layer assistant insertions).

Callers still need to pass `--tito-allowed-append-roles` with `assistant`
included for the outer `assert_messages_append_only_with_allowed_role`
check to accept these turns. That CLI choice is already configurable per
the existing `allowed_append_roles` argument on TITOTokenizer.__init__.
@DavidBellamy DavidBellamy force-pushed the fix/tito-assistant-append-role branch from 0b02324 to 1f58c11 Compare April 21, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.