Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4e56fd7
feat(llm): integrate MiniMax M3 unified parsing
mattwittwer Oct 24, 2026
d71877b
refactor(frontend): remove MiniMax M3 reasoning gate override
mattwittwer Oct 29, 2026
b47de28
refactor(frontend): restore shared structural-tag reasoning interface
mattwittwer Oct 29, 2026
f9a6b85
test(llm): simplify MiniMax M3 structural-tag integration coverage
mattwittwer Oct 29, 2026
be7cda5
Merge main into mwittwer/dis-3197-minimax-m3-unified
mattwittwer Oct 30, 2026
aa3f744
build(deps): bump dynamo-parsers-v2 to 0.9.0
mattwittwer Oct 30, 2026
713e274
fix(llm): align MiniMax M3 disabled reasoning and streaming tests
mattwittwer Oct 30, 2026
7da8448
Merge main into mwittwer/dis-3197-minimax-m3-unified
mattwittwer Oct 30, 2026
a577161
Merge branch 'main' into mwittwer/dis-3197-minimax-m3-unified
mattwittwer Oct 30, 2026
e1809f3
fix(llm): decide MiniMax M3 explicit guided output from its first bytes
mattwittwer Oct 30, 2026
1713ae3
fix(llm): gate MiniMax M3 unified reasoning on the rendered prompt
mattwittwer Oct 30, 2026
eae13a4
Merge branch 'main' into mwittwer/dis-3197-minimax-m3-unified
mattwittwer Oct 30, 2026
45ab7f0
Merge branch 'main' into mwittwer/dis-3197-minimax-m3-unified
mattwittwer Nov 2, 2026
e954bf8
Merge remote-tracking branch 'origin/main' into mwittwer/dis-3197-min…
mattwittwer Nov 3, 2026
e90e696
Merge branch 'main' into mwittwer/dis-3197-minimax-m3-unified
furionw Nov 3, 2026
d0e56ab
fix(llm): enable MiniMax M3 unified parsing by default
furionw Nov 3, 2026
ecafb39
chore: merge main and preserve MiniMax M3 routing
furionw Nov 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dynamo-parsers = { version = "=10.2.2" }
# Published on crates.io. To see all available versions:
# web: https://crates.io/crates/dynamo-parsers-v2/versions
# sparse index: curl https://index.crates.io/dy/na/dynamo-parsers-v2 (one JSON line per release; read the "vers" field)
dynamo-parsers-v2 = { version = "=0.8.9" }
dynamo-parsers-v2 = { version = "=0.9.0" }
Comment thread
mattwittwer marked this conversation as resolved.
Resolved
dynamo-backend-common = { path = "lib/backend-common", version = "1.7.0" }
dynamo-sidecar-common = { path = "lib/sidecar/common", version = "1.7.0" }

Expand Down
4 changes: 2 additions & 2 deletions lib/bindings/kvbm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/bindings/python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 108 additions & 46 deletions lib/llm/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5779,17 +5779,38 @@ impl OpenAIPreprocessor {
env_is_falsey(env_llm::DYN_ENABLE_GUIDED_TOOL_STREAMING),
);

// Guided output may be bare JSON or `reasoning</think>JSON`. Supported
// parsers inspect the stream shape before deciding whether to parse it.
let is_guided_tool_choice = matches!(
request.inner.tool_choice,
Some(ChatCompletionToolChoiceOption::Required)
| Some(ChatCompletionToolChoiceOption::Named(_))
);
let is_structured_response = Self::has_structured_response_format(request);
let reasoning_parser = self.runtime_config.reasoning_parser.as_deref();
let is_minimax_m3_explicit_guided_output =
Self::is_minimax_m3_family(reasoning_parser, self.tool_call_parser.as_deref())
&& crate::preprocessor::tool_choice::has_explicit_guided_decoding(request);
let is_guided_output =
is_guided_tool_choice || is_structured_response || is_minimax_m3_explicit_guided_output;

if let ToolProcessingRoute::Unified(family) = &tool_processing_route {
let tool_definitions =
crate::preprocessor::tool_choice::effective_tool_definitions(request)?;
let tool_definitions = (!tool_definitions.is_empty()).then_some(tool_definitions);
let reasoning_disabled = Self::request_disables_reasoning_with_family(
request,
self.tool_call_parser.as_deref(),
self.runtime_config.reasoning_parser.as_deref(),
None,
Some(family),
);
// MiniMax M3: the same gate as `reasoning_disabled_by_request` below. A
// thinking-disabled request turns the parser off only when the rendered
// prompt closed reasoning with `</mm:think>` or a grammar owns the output;
// a chat template that does not render `thinking_mode` leaves the prompt
// open and the model may still write `<mm:think>...</mm:think>`.
let reasoning_disabled =
Self::request_disables_reasoning_with_family(
request,
self.tool_call_parser.as_deref(),
self.runtime_config.reasoning_parser.as_deref(),
None,
Some(family),
) && (prompt_prefill.reasoning_closed_by_prompt != Some(false) || is_guided_output);
// TODO: Resolve model-specific prefill and guidance through the parser adapter's
// UnifiedRequestPolicy and parser capabilities; migrate equivalent batch/stream
// branches together while preserving legacy/v2 behavior.
Expand Down Expand Up @@ -5844,6 +5865,11 @@ impl OpenAIPreprocessor {
unified_parser::UnifiedRequestPolicy {
reasoning_disabled,
structured_response: Self::has_structured_response_format(request),
// Same rule as `seed_reasoning_parser` on the v1 route: a
// top-level `guided_*` grammar may own the output from
// token 0 despite the prompt-opened `<mm:think>`.
explicit_guidance: *family == "minimax_m3"
&& tool_choice::has_explicit_guided_decoding(request),
},
));
return Ok(Self::apply_unified_response_policies(
Expand All @@ -5854,20 +5880,6 @@ impl OpenAIPreprocessor {
));
}

// Guided output may be bare JSON or `reasoning</think>JSON`. Supported
// parsers inspect the stream shape before deciding whether to parse it.
let is_guided_tool_choice = matches!(
request.inner.tool_choice,
Some(ChatCompletionToolChoiceOption::Required)
| Some(ChatCompletionToolChoiceOption::Named(_))
);
let is_structured_response = Self::has_structured_response_format(request);
let reasoning_parser = self.runtime_config.reasoning_parser.as_deref();
let is_minimax_m3_explicit_guided_output =
Self::is_minimax_m3_family(reasoning_parser, self.tool_call_parser.as_deref())
&& crate::preprocessor::tool_choice::has_explicit_guided_decoding(request);
let is_guided_output =
is_guided_tool_choice || is_structured_response || is_minimax_m3_explicit_guided_output;
// Force parsers opt in by capability; prompt-seeded parsers opt in per request.
// Structural-tag tool formats do not use this guided-JSON detection path.
let inspect_force_reasoning_guided_output = is_guided_output
Expand Down Expand Up @@ -17365,6 +17377,14 @@ responses_tools: None,
}
}

fn minimax_m3_uses_unified_parser() -> bool {
crate::protocols::openai::chat_completions::unified_parser::selected_family(
Some("minimax_m3"),
Some("minimax_m3"),
)
.is_some()
}

/// `(content, reasoning_content, finish_reason set)` for the first choice
/// of each chunk that carries one.
fn minimax_m3_chunk_placement(
Expand Down Expand Up @@ -17718,8 +17738,8 @@ responses_tools: None,
) {
return;
}
// Text the parser held to EOF rides the terminal chunk, never a chunk
// after `finish_reason`.
// Adaptive output has no prompt-opened thought. V2 streams its visible
// text immediately; v1 holds it until the terminal chunk.
let regex = minimax_m3_merge_body(
serde_json::json!({"guided_regex": "Paris|London"}),
&serde_json::json!({"chat_template_kwargs": {"thinking_mode": "adaptive"}}),
Expand All @@ -17731,11 +17751,19 @@ responses_tools: None,
);
assert_eq!(
placed,
vec![
(String::new(), String::new(), false),
(String::new(), String::new(), false),
("Paris".to_string(), String::new(), true),
],
if minimax_m3_uses_unified_parser() {
vec![
("Par".to_string(), String::new(), false),
("is".to_string(), String::new(), false),
(String::new(), String::new(), true),
]
} else {
vec![
(String::new(), String::new(), false),
(String::new(), String::new(), false),
("Paris".to_string(), String::new(), true),
]
},
"guided_regex + adaptive: placement per chunk"
);

Expand Down Expand Up @@ -17886,8 +17914,8 @@ responses_tools: None,
"rows whose (content, reasoning_content) was wrong without a finish_reason"
);

// The held text arrives once, in one chunk after the last backend
// chunk, with no `finish_reason` because the backend sent none.
// Text arrives once, without inventing a finish_reason. V1 flushes at
// EOF, while v2 has already delivered both adaptive answer fragments.
let regex = minimax_m3_merge_body(
serde_json::json!({"guided_regex": "Paris|London"}),
&serde_json::json!({"chat_template_kwargs": {"thinking_mode": "adaptive"}}),
Expand All @@ -17899,11 +17927,18 @@ responses_tools: None,
);
assert_eq!(
placed,
vec![
(String::new(), String::new(), false),
(String::new(), String::new(), false),
("Paris".to_string(), String::new(), false),
],
if minimax_m3_uses_unified_parser() {
vec![
("Par".to_string(), String::new(), false),
("is".to_string(), String::new(), false),
]
} else {
vec![
(String::new(), String::new(), false),
(String::new(), String::new(), false),
("Paris".to_string(), String::new(), false),
]
},
"guided_regex + adaptive without a finish_reason: placement per chunk"
);
}
Expand Down Expand Up @@ -17987,12 +18022,30 @@ responses_tools: None,
.filter_map(|item| item.data.clone())
.collect::<Vec<_>>(),
);
assert!(
placed
.iter()
.all(|(content, reasoning, _)| content.is_empty() && reasoning.is_empty()),
"{desc}: held text must be dropped: {placed:?}"
);
if minimax_m3_uses_unified_parser() {
assert!(
placed
.iter()
.all(|(_, reasoning, finished)| reasoning.is_empty() && !finished),
"{desc}: no reasoning or successful finish before the error: {placed:?}"
);
assert_eq!(
placed
.iter()
.map(|(content, _, _)| content.as_str())
.collect::<String>(),
model_output,
"{desc}: adaptive text is delivered before the backend error"
);
} else {
assert!(
placed
.iter()
.all(|(content, reasoning, _)| content.is_empty()
&& reasoning.is_empty()),
"{desc}: held text must be dropped: {placed:?}"
);
}
}
}
}
Expand Down Expand Up @@ -18038,12 +18091,13 @@ responses_tools: None,
usage.inner.choices.is_empty() && usage.inner.usage.is_some(),
"the usage chunk must come last: {chunks:?}"
);
let flushed = before_usage.last().expect("the flushed chunk");
let flushed = before_usage.last().expect("the last content chunk");
assert_eq!(flushed.inner.choices.len(), 1);
assert!(
matches!(
&flushed.inner.choices[0].delta.content,
Some(ChatCompletionMessageContent::Text(text)) if text == "Paris"
Some(ChatCompletionMessageContent::Text(text))
if text == if minimax_m3_uses_unified_parser() { "is" } else { "Paris" }
),
"the held text must be flushed: {flushed:?}"
);
Expand Down Expand Up @@ -18496,8 +18550,9 @@ responses_tools: None,
// A template that renders `thinking_mode` closes reasoning with
// `</mm:think>` for a thinking-disabled request, so the parser stays
// off as before and the answer streams as it arrives. Where the
// prompt left thinking open, the parser holds marker-free text until
// the end of the turn shows it was not reasoning.
// prompt left thinking open, the v1 parser holds marker-free text
// until the end of the turn shows it was not reasoning; v2 streams
// it as it arrives.
let streams_as_it_arrives = vec![
("Hello".to_string(), String::new(), false),
(" there".to_string(), String::new(), false),
Expand All @@ -18516,7 +18571,14 @@ responses_tools: None,
MiniMaxM3Template::RendersThinkingMode,
&streams_as_it_arrives,
),
(MiniMaxM3Template::IgnoresThinkingMode, &held_until_the_end),
(
MiniMaxM3Template::IgnoresThinkingMode,
if minimax_m3_uses_unified_parser() {
&streams_as_it_arrives
} else {
&held_until_the_end
},
),
] {
let trip = minimax_m3_round_trip_on(
template,
Expand Down
63 changes: 63 additions & 0 deletions lib/llm/src/preprocessor/tool_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,69 @@ mod tests {
);
}

#[test]
fn minimax_m3_native_tags_and_relaxed_schema_fallback() {
if crate::test_utils::run_isolated(
concat!(
module_path!(),
"::minimax_m3_native_tags_and_relaxed_schema_fallback"
),
&[(
dynamo_runtime::config::environment_names::llm::DYN_PARSER_VERSION,
"2",
)],
) {
return;
}
let preprocessor = preprocessor("minimax_m3", StructuralTagMode::On);
for strict in [None, Some(true), Some(false)] {
for named in [false, true] {
let mut definitions = tools();
definitions[0]["function"]["parameters"]["additionalProperties"] = json!(false);
definitions[0]["function"]["parameters"]["properties"]["location"]["enum"] =
json!(["Paris", "Tokyo"]);
if let Some(strict) = strict {
definitions[0]["function"]["strict"] = json!(strict);
}
let choice = if named {
json!({"type": "function", "function": {"name": "get_weather"}})
} else {
json!("required")
};
let request = request(json!({"tools": definitions, "tool_choice": choice}));
let mut common = preprocessed_request();
let constraint = preprocessor
.apply_tool_choice_guided_decoding(&request, &mut common, false)
.unwrap();
let grammar = common.sampling_options.guided_decoding.unwrap();
if strict == Some(false) {
assert_eq!(
constraint,
if named {
GuidedToolConstraint::GuidedJsonNamed {
tool_name: "get_weather".into(),
}
} else {
GuidedToolConstraint::GuidedJsonRequired
}
);
assert!(grammar.json.is_some());
assert!(grammar.structural_tag.is_none());
} else {
assert_eq!(constraint, GuidedToolConstraint::StructuralTag);
assert!(
grammar
.structural_tag
.unwrap()
.to_string()
.contains("minimax_m3_xml")
);
assert!(grammar.json.is_none());
}
}
}
}

#[test]
fn kimi_k3_builder_error_uses_native_fallback() {
let request = request(json!({
Expand Down
3 changes: 3 additions & 0 deletions lib/llm/src/protocols/openai/chat_completions/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ impl DeltaAggregator {
super::unified_parser::UnifiedRequestPolicy {
reasoning_disabled: parsing_options.reasoning_disabled,
structured_response: parsing_options.structured_response,
// The complete text shows its own channels; `detect_prefill`
// reads them back without a first-bytes probe.
explicit_guidance: false,
},
) {
Ok(parsed) => {
Expand Down
Loading
Loading