Skip to content

Support tool calling for the Laguna chat templates - #8511

Open
albertvillanova wants to merge 3 commits into
mainfrom
laguna-tool-calling
Open

albertvillanova wants to merge 3 commits into
mainfrom
laguna-tool-calling

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

This PR makes GRPOTrainer with tools work on the Laguna checkpoints (poolside/Laguna-XS.2, poolside/Laguna-M.1, poolside/Laguna-XS-2.1 and poolside/Laguna-S-2.1), whose chat templates TRL did not recognize, so add_response_schema rejected them.

Part of #7943.

Motivation

Laguna checkpoints have about 2.3M downloads, and none ships a response template, so GRPOTrainer with tools fails at init. The four checkpoints ship four distinct chat templates. They write tool calls in the same format as GLM-4-MoE, with or without newlines around the arguments, wrap turns in <assistant> / </assistant>, and pre-fill the generation prompt with <think> or </think>. All four already have {% generation %} markers and are prefix-preserving, so they need no training template.

Changes

  • Store the four Laguna chat templates as laguna.jinja, laguna_v2.jinja, laguna_v3.jinja and laguna_v4.jinja, document them, and add their repos to the drift check.
  • Add laguna_template, which reuses the GLM-4-MoE tool-call parsing, and set it in add_response_schema for the four templates.
  • Test response parsing for each template with and without thinking.
  • Add Laguna to the supported model families.

Note

Low Risk
Adds template assets, parsing rules, and tests without changing existing families’ behavior.

Overview
Adds Laguna (Poolside XS.2, M.1, XS-2.1, S-2.1) to TRL’s recognized chat-template families so GRPOTrainer with tools can initialize on these checkpoints instead of failing in add_response_schema.

Four reference Jinja templates are vendored (laguna.jinja through laguna_v4.jinja), documented, and registered in the Hub drift check. A dedicated laguna_template response parser (GLM-4-MoE-style XML tool calls, thinking anchors) is wired in add_response_schema for all four variants. Tests cover response parsing with and without thinking; docs list Laguna among supported families.

Reviewed by Cursor Bugbot for commit 96efd18. Bugbot is set up for automated code reviews on this repo. Configure here.

@albertvillanova
albertvillanova marked this pull request as ready for review November 20, 2026 17:58
@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Pages changed in this PR:

@qgallouedec qgallouedec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'd prefer adding a tiny Laguna model in this PR, so Laguna can join all the parametrizations (SFT, GRPO with tools, the training template suite, ...) like the other families. Right now it's only covered by the parsing tests, which feels like partial support. transformers has LagunaForCausalLM, and a 2-layer model built from Laguna-XS.2's config (per-layer lists cut to 2) runs a forward with the real tokenizer at 3.2M parameters.

# Conflicts:
#	docs/source/chat_templates.md
#	trl/chat_template_utils.py
#	trl/chat_templates/README.md

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 96efd18. Configure here.

messages, tokenize=True, return_dict=True, enable_thinking=enable_thinking
)
response = text.input_ids[len(prefix.input_ids) :]
assert parse_response(tokenizer, response, prefix=prefix.input_ids, tools=[multiply]) == assistant

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline breaks Laguna content round-trip

Medium Severity

The shared Laguna round-trip test expects content to equal Let me check. for every template, but laguna.jinja and laguna_v2.jinja emit a newline after the text when tool_calls follow. laguna_template closes content at <tool_call> (no leading whitespace) rather than at </assistant>, so that newline stays in content and the assertion fails for those two templates. Parsed GRPO messages would carry the same trailing newline.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 96efd18. Configure here.

This branch has not been deployed

No deployments
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.

2 participants