Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions abstractcore/architectures/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ def format_messages(messages: List[Dict[str, str]], architecture: str) -> str:
return "\n".join([f"{msg['role']}: {msg['content']}" for msg in messages])

formatted_parts = []
bos = arch_format.get("bos_token")
if isinstance(bos, str) and bos:
formatted_parts.append(bos)

for msg in messages:
role = msg["role"]
Expand Down
34 changes: 33 additions & 1 deletion abstractcore/architectures/response_postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ class IncrementalThinkingTagStripper:
matching `strip_thinking_tags()` behavior (#TRUNCATION labeled).
"""

def __init__(self, *, start_tag: str, end_tag: str, assume_visible_start: bool = False) -> None:
def __init__(
self, *, start_tag: str, end_tag: str, assume_visible_start: bool = False, strip_stray_close: bool = False
) -> None:
if not isinstance(start_tag, str) or not start_tag:
raise ValueError("start_tag must be a non-empty string")
if not isinstance(end_tag, str) or not end_tag:
Expand All @@ -233,6 +235,19 @@ def __init__(self, *, start_tag: str, end_tag: str, assume_visible_start: bool =

self._buffer = ""
self._state: str = "visible" if assume_visible_start else "searching" # searching|visible|thinking
# Thinking was switched off, yet some models (LFM3-1.7B) still reason in the
# answer and then write a closing tag they were never given an opening for.
# The text before it has already streamed as content and cannot be taken back;
# the stray tag itself is markup and never part of the answer. Only ONE closing
# tag is the format's (the end of the reasoning, the boundary the non-streamed
# path splits on); a later `</think>` is the answer's own text. (Neither the text
# nor the token id tells a first mention in prose apart: LFM3's `</think>` is an
# added token, produced for the literal string too.)
# Only for a model whose registry entry declares the leak
# (`thinking_off_leaks_close_tag`: LFM3-1.7B, LFM3-VL); any other model's answer
# keeps every character.
self._stray_close_possible = bool(assume_visible_start and strip_stray_close)
self.stray_close_tags = 0
self._current_reasoning_parts: list[str] = []
self._reasoning_blocks: list[str] = []
# Reasoning identified since the last `take_reasoning_delta()`: streamed
Expand Down Expand Up @@ -365,8 +380,22 @@ def process(self, text: str) -> str:

if self._state == "visible":
start_idx = self._buffer.find(self._start_tag)
if self._stray_close_possible:
end_idx = self._buffer.find(self._end_tag)
if end_idx != -1 and (start_idx == -1 or end_idx < start_idx):
self._add_visible(out_parts, self._buffer[:end_idx])
self._buffer = self._buffer[end_idx + len(self._end_tag) :]
self.stray_close_tags += 1
self._stray_close_possible = False
_logger.warning(
"#THINKING-LEAK: the model closed a thinking block with thinking off; "
"the text before the stray closing tag was streamed as content"
)
continue
if start_idx == -1:
keep = self._suffix_prefix_len(self._buffer, self._start_tag)
if self._stray_close_possible:
keep = max(keep, self._suffix_prefix_len(self._buffer, self._end_tag))
if keep:
self._add_visible(out_parts, self._buffer[:-keep])
self._buffer = self._buffer[-keep:]
Expand All @@ -381,6 +410,7 @@ def process(self, text: str) -> str:
self._buffer = self._buffer[start_idx + len(self._start_tag) :]
self._state = "thinking"
self._seen_block = True
self._stray_close_possible = False
self._current_reasoning_parts = []
continue

Expand Down Expand Up @@ -501,6 +531,7 @@ def maybe_create_incremental_thinking_tag_stripper(
architecture_format: Optional[Mapping[str, Any]] = None,
model_capabilities: Optional[Mapping[str, Any]] = None,
assume_visible_start: bool = False,
strip_stray_close: bool = False,
) -> Optional[IncrementalThinkingTagStripper]:
"""Return an incremental thinking-tag stripper when configured via assets.

Expand All @@ -520,6 +551,7 @@ def maybe_create_incremental_thinking_tag_stripper(
start_tag=start_tag,
end_tag=end_tag,
assume_visible_start=assume_visible_start,
strip_stray_close=strip_stray_close,
)
except Exception:
return None
Expand Down
14 changes: 9 additions & 5 deletions abstractcore/assets/architecture_formats.json
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,16 @@
]
},
"lfm3": {
"description": "Liquid AI LFM3 text tri-hybrid: im_start/end messages and Qwen3-Coder XML tools (official LFM3-1.7B chat template, 2026-10-30).",
"description": "Liquid AI LFM3 family: <|startoftext|> then im_start/end messages, Qwen3-Coder XML tools, tool results as a `tool` turn wrapping <tool_response> (official LFM3-1.7B chat template, checked 2026-11-30). Thinking control is declared per model: the members differ (enable_thinking on 1.7B/VL, on by default; on Omni, off by default; none on Audio, whose generation prompt opens no thinking block). llama_cpp_context: flash attention on and a window-sized sliding-attention cache; the short-convolution state already stops llama.cpp from cutting a cached prefix, so a full-size sliding cache buys nothing (measured at n_ctx 32,768 on llama-cpp-python 0.3.38: sliding cache 320 MiB -> 7.5 MiB, Metal compute buffer 1,178 MiB -> 299 MiB). mlx_vlm_model_types: the config.json model_type mlx-lm ships no module for and mlx-vlm loads from the version given, verified on real weights (MLX provider; a model_type not declared anywhere keeps mlx-lm's own error).",
"message_format": "im_start_end",
"bos_token": "<|startoftext|>",
"mlx_vlm_model_types": {
"lfm3": "0.7.12"
},
"llama_cpp_context": {
"flash_attn": true,
"swa_full": false
},
"system_prefix": "<|im_start|>system\n",
"system_suffix": "<|im_end|>\n",
"user_prefix": "<|im_start|>user\n",
Expand All @@ -1445,10 +1453,6 @@
"<think>",
"</think>"
],
"thinking_control": {
"template_kwarg": "enable_thinking",
"assistant_prefill_disable": "<think>\n\n</think>\n\n"
},
"reasoning_support": true,
"patterns": [
"lfm3-",
Expand Down
35 changes: 31 additions & 4 deletions abstractcore/assets/llamacpp_known_architectures.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"schema": "llamacpp_known_architectures_v1",
"llama_cpp_python": "0.3.36",
"llama_cpp_commit": "0c1e57098bba43ac29e6e3b677cdceebdd22334f",
"source": "src/llama-arch.cpp LLM_ARCH_NAMES of the llama.cpp commit vendored by llama-cpp-python 0.3.36",
"llama_cpp_python": "0.3.38",
"llama_cpp_commit": "f5e6915c28f10330885fcb9243a93ae98d3115ab",
"source": "src/llama-arch.cpp LLM_ARCH_NAMES of the llama.cpp commit vendored by llama-cpp-python 0.3.38",
"architectures": [
"afmoe",
"apertus",
Expand All @@ -13,12 +13,15 @@
"bailingmoe",
"bailingmoe2",
"bailingmoe3",
"beam",
"bert",
"bitnet",
"bloom",
"chameleon",
"chatglm",
"clef",
"clip",
"clover_moe",
"codeshell",
"cogvlm",
"cohere2",
Expand All @@ -31,7 +34,9 @@
"deepseek2-ocr",
"deepseek32",
"deepseek4",
"deepseek41",
"dflash",
"domynedge",
"dots1",
"dots3note",
"dream",
Expand All @@ -44,8 +49,10 @@
"exaone4",
"falcon",
"falcon-h1",
"flint",
"gemma",
"gemma-embedding",
"gemma-embedding2",
"gemma2",
"gemma3",
"gemma3n",
Expand All @@ -72,38 +79,51 @@
"hunyuan_vl",
"hy_v3",
"hy_v4",
"inkling2",
"inkling2_loop",
"internlm2",
"jais",
"jais2",
"jamba",
"jina-bert-v2",
"jina-bert-v3",
"k2-horizon",
"kimi-k3",
"kimi-k31",
"kimi-linear",
"kokoro",
"kolibri1",
"laguna",
"lfm2",
"lfm2moe",
"lfm3",
"limite",
"llada",
"llada-moe",
"llama",
"llama-embed",
"llama4",
"maincoder",
"maion-coder",
"mamba",
"mamba2",
"maple",
"mellum",
"metis16",
"mimo2",
"minicpm",
"minicpm3",
"minimax-01",
"minimax-m2",
"minimax-m3",
"mistral-large4",
"mistral3",
"mistral4",
"modern-bert",
"moshi",
"mpt",
"muse-glimmer",
"muse-spark",
"nanbeige",
"nemotron",
"nemotron_h",
Expand Down Expand Up @@ -140,11 +160,13 @@
"qwen3vlmoe",
"qwen4exp",
"refact",
"ricursive",
"rnd1",
"rwkv6",
"rwkv6qwen2",
"rwkv7",
"seed_oss",
"sensenova_u1",
"smallthinker",
"smollm3",
"spark2_5",
Expand All @@ -155,7 +177,12 @@
"t5",
"t5encoder",
"talkie",
"tiny-voca",
"vllm-decision2",
"wavtokenizer-dec",
"xverse"
"xing4_0",
"xverse",
"zaya1",
"zonos3"
]
}
29 changes: 23 additions & 6 deletions abstractcore/assets/model_capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -12507,18 +12507,26 @@
},
"lfm3-1.7b": {
"canonical_name": "lfm3-1.7b",
"gguf_template_tools": true,
"thinking_off_leaks_close_tag": true,
"aliases": [
"LiquidAI/LFM3-1.7B",
"LiquidAI/LFM3-1.7B-GGUF",
"lmstudio-community/LFM3-1.7B-GGUF",
"LiquidAI/LFM3-1.7B-MLX-4bit",
"LiquidAI/LFM3-1.7B-MLX-8bit"
"LiquidAI/LFM3-1.7B-MLX-5bit",
"LiquidAI/LFM3-1.7B-MLX-6bit",
"LiquidAI/LFM3-1.7B-MLX-8bit",
"LiquidAI/LFM3-1.7B-MLX-bf16",
"LiquidAI/LFM3-1.7B-FP8",
"LiquidAI/LFM3-1.7B-NVFP4",
"LiquidAI/LFM3-1.7B-ONNX"
],
"max_tokens": 262144,
"max_output_tokens": null,
"tool_support": "native",
"structured_output": "prompted",
"parallel_tools": false,
"parallel_tools": true,
"max_tools": -1,
"vision_support": false,
"audio_support": false,
Expand All @@ -12535,19 +12543,27 @@
"text"
]
},
"notes": "Text-only tri-hybrid LFM3: 13 short-convolution, 5 sliding-attention and 6 full-attention layers. Its chat template supports enable_thinking and Qwen3-Coder XML tool calls. This is the post-trained text model, not the Base, VL, Audio or Omni checkpoint.",
"source": "https://huggingface.co/LiquidAI/LFM3-1.7B model card, config.json and chat_template.jinja, accessed 2026-10-30.",
"notes": "Text-only tri-hybrid LFM3: 13 short-convolution, 5 sliding-attention (256-token window) and 6 full-attention layers, so only the 6 full-attention layers keep a whole-context cache (12,288 bytes per token in bf16, measured on MLX). Reasoning is on by default: the chat template opens <think> in the generation prompt; enable_thinking=False writes an empty <think></think> instead. Qwen3-Coder XML tool calls (<tool_call><function=...><parameter=...>), several calls in one reply. Card sampling (generation_config.json): temperature 0.1, top_k 50, repetition_penalty 1.1, no top_p (1.0). With thinking off the model still reasons in its answer on harder prompts (sometimes followed by a stray </think>, or a <think> block it opens itself); Core reports that text as reasoning, never as the answer and never discarded. The card does not recommend it for agentic coding or complex multi-step reasoning. This is the post-trained text model, not the Base, VL, Audio or Omni checkpoint. Loads on mlx-vlm >= 0.7.12 (no mlx-lm release has lfm3; 0.7.11 has the module but leaks the reasoning into the answer) and llama-cpp-python >= 0.3.38.",
"source": "https://huggingface.co/LiquidAI/LFM3-1.7B model card, config.json, generation_config.json and chat_template.jinja (accessed 2026-11-30); LiquidAI/LFM3-1.7B-GGUF metadata (general.sampling.*); real runs on mlx-vlm 0.7.12 and llama-cpp-python 0.3.38, 2026-11-30 (two tool calls in one reply on both engines).",
"thinking_tags": [
"<think>",
"</think>"
],
"thinking_control": {
"template_kwarg": "enable_thinking"
"template_kwarg": "enable_thinking",
"assistant_prefill_disable": "<think></think>"
},
"inference_parameters": {
"temperature": 0.1,
"top_p": 1.0,
"top_k": 50,
"repeat_penalty": 1.1
},
"license": "lfm1.0"
},
"lfm3-vl-2b": {
"canonical_name": "lfm3-vl-2b",
"thinking_off_leaks_close_tag": true,
"aliases": [
"LiquidAI/LFM3-VL-2B",
"LiquidAI/LFM3-VL-2B-GGUF",
Expand Down Expand Up @@ -12592,7 +12608,8 @@
"</think>"
],
"thinking_control": {
"template_kwarg": "enable_thinking"
"template_kwarg": "enable_thinking",
"assistant_prefill_disable": "<think></think>"
},
"license": "lfm1.0",
"inference_parameters": {
Expand Down
30 changes: 23 additions & 7 deletions abstractcore/assets/model_downloads_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -6094,17 +6094,27 @@
"provider": "huggingface",
"artifact": "LiquidAI/LFM3-1.7B-GGUF:Q4_K_M",
"quant": "q4_k_m",
"download_bytes": null,
"size_source": "unknown",
"verified": false
"download_bytes": 1099627808,
"size_source": "catalog",
"verified": true,
"upstream": {
"method": "hf_api",
"checked": "2026-11-30",
"revision": "cd0c74c575b5c416f3011b5b4c298077f26ca8c2"
}
},
{
"provider": "mlx",
"artifact": "LiquidAI/LFM3-1.7B-MLX-4bit",
"quant": "4bit",
"download_bytes": null,
"size_source": "unknown",
"verified": false
"download_bytes": 973083386,
"size_source": "catalog",
"verified": true,
"upstream": {
"method": "hf_api",
"checked": "2026-11-30",
"revision": "91f34088d6946482cbcae11b85d4657093618c34"
}
},
{
"provider": "lmstudio",
Expand All @@ -6115,7 +6125,13 @@
"verified": false
}
],
"notes": "Primary model cards and local engine inventory audited 2026-10-30; installed variants retain their exact identifiers."
"notes": "Sizes and revisions from the Hugging Face API on 2026-11-30 (weight files only); both artifacts ran end to end through AbstractCore on 2026-11-30 (MLX via mlx-vlm >= 0.7.12, GGUF via llama-cpp-python >= 0.3.38). The LM Studio row is the catalog name; its size is not recorded.",
"kv_geometry": {
"n_layers": 6,
"n_kv_heads": 4,
"head_dim": 128,
"source": "config.json of LiquidAI/LFM3-1.7B-MLX-4bit@91f34088: 6 of 24 layers are full_attention (layer_types); 5 sliding_attention layers keep a 256-token window and 13 conv layers a fixed state. Measured on MLX 2026-11-30: 12,288 bytes per cached token"
}
},
{
"id": "bonsai-27b",
Expand Down
4 changes: 4 additions & 0 deletions abstractcore/core/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ def __init__(self, config: Optional[RetryConfig] = None):
"InvalidRequestError",
"ModelNotFoundError",
"UnsupportedFeatureError",
# An attachment that cannot be read stays unreadable on attempt 2.
"MediaProcessingError",
"UnsupportedMediaTypeError",
"FileSizeExceededError",
"ConfigurationError",
# A lane that cannot speculate will not start speculating on
# attempt 2; retrying only multiplies the latency the caller was
Expand Down
Loading
Loading