tool_call_markers.h

src/inference/tool_call_markers.h

@file tool_call_markers.h @brief gh#103 (v2.8.2): family-aware tool-call CLOSE markers, derived from the resolved common_chat format.

Owners: @tvanfossen

append_sequential_stop

void entropic::append_sequential_stop(GenerationParams &params, const std::string &marker)

Append a tool-call close marker to params.stop for sequential mode.

src/inference/tool_call_markers.h:93

Show on the map →

Called by SCENARIO, effective_stop

Calls none

Source · 8 lines
inline void append_sequential_stop(GenerationParams& params,
                                   const std::string& marker) {
    if (params.tool_call_mode != "sequential" || marker.empty()) { return; }
    if (std::find(params.stop.begin(), params.stop.end(), marker)
            == params.stop.end()) {
        params.stop.push_back(marker);
    }
}
Activity · 4 steps
lines 95–95◇ if (params.tool_call_mode != "sequential" || marker.empty())lines 95–95return;lines 96–97◇ if (std::find(params.stop.begin(), params.stop.end(), marker) == params.stop.end())lines 98–98params.stop.push_back(marker);

Requirements

REQ-INFER-013

close_marker_for_format

std::string entropic::close_marker_for_format(common_chat_format fmt)

Map a resolved common_chat format to its single-tool-call close marker.

src/inference/tool_call_markers.h:52

Show on the map →

Called by SCENARIO, tool_call_close_marker

Calls none

Source · 25 lines
inline std::string close_marker_for_format(common_chat_format fmt) {
    std::string marker;
    switch (fmt) {
        case COMMON_CHAT_FORMAT_PEG_NATIVE:
        case COMMON_CHAT_FORMAT_PEG_SIMPLE:
            marker = "</tool_call>";
            break;
        case COMMON_CHAT_FORMAT_PEG_GEMMA4:
            // gh#103 (v2.8.2): gemma4 wraps a call as
            // `<|tool_call>call:NAME{...}<tool_call|>` — the per-call CLOSE is
            // `<tool_call|>` (confirmed against a live gemma4_e4b transcript +
            // chat.cpp:1178). Distinct from the open `<|tool_call>`, so the
            // ends-with stop check fires on the close, never the open. This is
            // the family where the missing hard-stop is most severe: the
            // runaway past the call defeats extraction, so the terminal
            // directive registers as ZERO tool calls (gh#103 consumer report).
            marker = "<tool_call|>";
            break;
        default:
            // CONTENT_ONLY / unknown: no confirmed per-call close marker —
            // return "" so no stop is injected (batch-safe).
            break;
    }
    return marker;
}
Activity · 3 steps
lines 53–53std::string marker;lines 54–74switch (fmt) { case COMMON_CHAT_FORMAT_PEG_NATIVE: case COMMON_CHAT_FORMAT_PEG_SIMPLE: marker = "</tool_call>"; break; case COMMON_CHAT_FORMAT_PEG_GEMMA4: // gh#103 (v2.8.2): gemma4 wraps a call as // `<|tool_call>call:NAME{...}<tool_call|>` — the per-call CLOSE is // `<tool_call|>` (confirmed against a live gemma4_e4b transcript + // chat.cpp:1178). Distinct from the open `<|tool_call>`, so the // ends-with stop check fires on the close, never the open. This is // the family where the missing hard-stop is most severe: the // runaway past the call defeats extraction, so the terminal // directive registers as ZERO tool calls (gh#103 consumer report). marker = "<tool_call|>"; break; default: // CONTENT_ONLY / unknown: no confirmed per-call close marker — // return "" so no stop is injected (batch-safe). break; }lines 75–75return marker;

Requirements

REQ-INFER-013