Entropic 2.9.4
Local-first agentic inference engine
Loading...
Searching...
No Matches
tool_call_markers.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
26#pragma once
27
28#include <entropic/types/config.h> // GenerationParams
29
30#include <chat.h>
31
32#include <algorithm>
33#include <string>
34
35namespace entropic {
36
49inline std::string close_marker_for_format(common_chat_format fmt) {
50 std::string marker;
51 switch (fmt) {
52 case COMMON_CHAT_FORMAT_PEG_NATIVE:
53 case COMMON_CHAT_FORMAT_PEG_SIMPLE:
54 marker = "</tool_call>";
55 break;
56 case COMMON_CHAT_FORMAT_PEG_GEMMA4:
57 // gh#103 (v2.8.2): gemma4 wraps a call as
58 // `<|tool_call>call:NAME{...}<tool_call|>` — the per-call CLOSE is
59 // `<tool_call|>` (confirmed against a live gemma4_e4b transcript +
60 // chat.cpp:1178). Distinct from the open `<|tool_call>`, so the
61 // ends-with stop check fires on the close, never the open. This is
62 // the family where the missing hard-stop is most severe: the
63 // runaway past the call defeats extraction, so the terminal
64 // directive registers as ZERO tool calls (gh#103 consumer report).
65 marker = "<tool_call|>";
66 break;
67 default:
68 // CONTENT_ONLY / unknown: no confirmed per-call close marker —
69 // return "" so no stop is injected (batch-safe).
70 break;
71 }
72 return marker;
73}
74
91 const std::string& marker) {
92 if (params.tool_call_mode != "sequential" || marker.empty()) { return; }
93 if (std::find(params.stop.begin(), params.stop.end(), marker)
94 == params.stop.end()) {
95 params.stop.push_back(marker);
96 }
97}
98
99} // namespace entropic
Configuration structs with defaults.
Activate model on GPU (WARM → ACTIVE).
void append_sequential_stop(GenerationParams &params, const std::string &marker)
Append a tool-call close marker to params.stop for sequential mode.
std::string close_marker_for_format(common_chat_format fmt)
Map a resolved common_chat format to its single-tool-call close marker.
Generation parameters for a single inference call.
Definition config.h:302
std::string tool_call_mode
Per-call tool-call generation mode (gh#103).
Definition config.h:372
std::vector< std::string > stop
Stop sequences.
Definition config.h:365