Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
grammar_source.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
22#pragma once
23
26
27#include <string>
28
29namespace entropic {
30
35enum class GrammarSource {
36 none,
37 request,
38
44 tier,
45
46 tool_call,
47
53 count,
54};
55
69inline constexpr int grammar_source_count() {
70 return static_cast<int>(GrammarSource::count);
71}
72
95 const std::string& tool_grammar,
96 bool request_from_tier = false) {
98 if (!request_grammar.empty()) {
101 } else if (!tool_grammar.empty()) {
103 }
104 return source;
105}
106
122 return source == GrammarSource::request || source == GrammarSource::tier;
123}
124
148 return params.grammar.empty()
149 && params.grammar_from_tier
150 && !params.resolved_grammar_key.empty();
151}
152
161inline const char* grammar_source_name(GrammarSource source) {
162 const char* name = "none";
163 if (source == GrammarSource::request) {
164 name = "request";
165 } else if (source == GrammarSource::tier) {
166 name = "tier";
167 } else if (source == GrammarSource::tool_call) {
168 name = "tool_call";
169 }
170 return name;
171}
172
182inline bool grammar_sources_collide(const std::string& request_grammar,
183 const std::string& tool_grammar) {
184 return !request_grammar.empty() && !tool_grammar.empty();
185}
186
208 const std::string& tool_grammar) {
209 const auto source = resolve_grammar_source(
210 params.grammar, tool_grammar, params.grammar_from_tier);
213 provenance.key = params.resolved_grammar_key;
214 provenance.resolved = (source != GrammarSource::none);
215 if (!provenance.resolved && !provenance.key.empty()) {
216 provenance.source = params.grammar_from_tier
219 }
221 provenance.conflict_winner = provenance.source;
222 }
223 return provenance;
224}
225
226} // namespace entropic
Configuration structs with defaults.
Generation output with metrics.
Activate model on GPU (WARM → ACTIVE).
bool tier_grammar_unresolved(const GenerationParams &params)
A TIER named a grammar and nothing resolved it (gh#154).
const char * grammar_source_name(GrammarSource source)
Stable wire name for a grammar source.
@ optional
optional: every escape asks the host's path approver
bool grammar_sources_collide(const std::string &request_grammar, const std::string &tool_grammar)
Whether both sources are active — a config error worth reporting.
GrammarSource
Which source, if any, constrains the decode.
@ request
GenerationParams::grammar (COMMON_GRAMMAR_TYPE_USER)
@ none
Unconstrained.
@ tool_call
Render-derived (COMMON_GRAMMAR_TYPE_TOOL_CALLS, needs prefill)
@ tier
The TIER's identity frontmatter grammar: stem (gh#154).
@ count
Sentinel — MUST remain last.
bool is_request_grammar(GrammarSource source)
Whether a source is applied as a request-side grammar.
GrammarSource resolve_grammar_source(const std::string &request_grammar, const std::string &tool_grammar, bool request_from_tier=false)
Resolve which grammar wins.
@ none
Child tools share the session's working dir (default)
GrammarProvenance describe_grammar(const GenerationParams &params, const std::string &tool_grammar)
Describe what constrained one decode, for the result record (gh#154).
constexpr int grammar_source_count()
Number of declared grammar sources, sentinel excluded.
Generation parameters for a single inference call.
Definition config.h:389
What constrained one decode, and what asked for it (gh#154).
std::string source
"request" | "tier" | "tool_call" | "none".