[ContinuousToken] Agent Loop Integration
What does this PR do?
This PR wires Continuous Token into the existing AgentLoop execution paths. When CT is enabled and the rollout is text-only, AgentLoop builds the initial prompt with the CT builder, appends generated assistant tokens directly, and merges tool/user/system messages through CT while keeping response_mask and rollout logprobs aligned.
Multimodal processor paths continue to use the legacy behavior.
Checklist Before Starting
- [x] Search for similar PRs. Paste at least one query link here: ...
- [x] Format the PR title as
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,veomni,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,cfg,reward,fully_async,one_step_off- If this PR involves multiple modules, separate them with
,like[megatron, fsdp, doc] {type}is infeat,fix,refactor,chore,test- If this PR breaks any API (CLI arguments, config, function signature, etc.), add
[BREAKING]to the beginning of the title. - Example:
[BREAKING][fsdp, megatron] feat: dynamic batching
Test
Test will be in PR 03
API and Usage Example
Demonstrate how the API changes if any, and provide usage example(s) if possible.
# Add code snippet or script demonstrating how to use this
Design & Code Changes
Main Changes
- Creates a CT builder in
AgentLoopBasefrommulti_turn.continuous_tokenconfig. - Adds helper methods for CT initial prompt creation, assistant-token merge, non-assistant message merge, prompt-length capping, and response metadata alignment.
- Integrates CT into
SingleTurnAgentLoopfor text-only prompts. - Integrates CT into
ToolAgentLoopfor tool-call rollouts:- Keeps assistant generated tokens in the runtime token stream.
- Appends tool responses using CT rather than isolated per-turn template rendering.
- Preserves assistant
tool_callsand tooltool_call_id/namemetadata in message history.
- Adds additional model-specific tool parsers needed (GLM, Seed, MiniMax, Kimi). (This is open to discussion. Inference backend like SGLang has already supported returning both token id and OpenAI compatible message that contained the parsed tool call. Maybe we don't have to implement and use tool parser in Verl if we can get parsed tool calls from inference backend directly?)
Changed Files
-
verl/experimental/agent_loop/agent_loop.py- Instantiates
continuous_token_builderwhen CT is enabled and no multimodal processor is active. - Adds
build_ct_initial_prompt,merge_ct_non_assistant_msg, andmerge_ct_assistant_token. - Adds
_align_continuous_token_response_metadataso inserted boundary tokens get mask/logprob0, assistant tokens get mask1, and removed prefix tokens are reflected in metadata. - Reuses
_cap_text_prompt_lengthfor CT and legacy text prompts.
- Instantiates
-
verl/experimental/agent_loop/single_turn_agent_loop.py- Uses CT for text-only single-turn prompts.
- Appends generated assistant tokens with CT and then splits the merged stream back into prompt/response for
AgentLoopOutput. - Keeps masks and logprobs aligned with the CT-merged response.
-
verl/experimental/agent_loop/tool_agent_loop.py- Uses CT for the initial prompt and assistant/tool-message merges.
- Appends assistant messages with structured
tool_callsto the message history after parsing model output. - Adds tool-call IDs and tool names to generated tool messages.
- Uses parser-provided
stop_token_ids. - Keeps legacy special formatting paths for
gpt-oss,gemma4, and multimodal tool responses.
-
verl/experimental/agent_loop/tool_parser.py- Adds
GLMToolParser. - Adds
SeedToolParser. - Adds
MiniMaxToolParser. - Adds
KimiToolParser, includinglast_tool_call_ids. - Adds stop-token behavior for GLM/Kimi-style tool-call boundaries.
- Adds
Notes
CT remains opt-in. The integration is conservative: if CT is enabled but a multimodal processor is present, the code logs a warning and falls back to the legacy multimodal path.
This PR also contains the diff from PR01. After PR01 is merged, this branch will be rebased and will only show the diff broughput about by this PR.
Checklist Before Submitting
[!IMPORTANT] Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
- [ ] Read the Contribute Guide.
- [ ] Apply pre-commit checks:
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always - [ ] Add / Update the documentation.
- [ ] Add unit or end-to-end test(s) to the CI workflow to cover all the code. If not feasible, explain why: ...
- [ ] Once your PR is ready for CI, send a message in the
ci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).) - [ ] If your PR is related to the
recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.