Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
context_fit.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
22#ifndef ENTROPIC_INFERENCE_CONTEXT_FIT_H
23#define ENTROPIC_INFERENCE_CONTEXT_FIT_H
24
25#include <cstddef>
26#include <string>
27
28namespace entropic {
29
41struct ContextFit {
42 int prompt_tokens = 0;
44 int system_tokens = 0;
45 int tool_tokens = 0;
46 std::size_t tool_bytes = 0;
47 int tool_count = 0;
48};
49
65inline bool context_fit_overflows(const ContextFit& f) {
66 return f.context_length > 0 && f.prompt_tokens >= f.context_length;
67}
68
77 const int rest = f.prompt_tokens - f.system_tokens - f.tool_tokens;
78 return rest > 0 ? rest : 0;
79}
80
94inline std::string context_fit_largest_contributor(const ContextFit& f) {
96 std::string who = "the message history";
97 if (f.tool_tokens > most) {
98 most = f.tool_tokens;
99 who = "the staged tool block";
100 }
101 if (f.system_tokens > most) {
102 who = "the system prompt";
103 }
104 return who;
105}
106
114inline std::string context_fit_breakdown(const ContextFit& f) {
115 return "staged tools " + std::to_string(f.tool_tokens) + " tok ("
116 + std::to_string(f.tool_count) + " tools, "
117 + std::to_string(f.tool_bytes) + " bytes); system prompt "
118 + std::to_string(f.system_tokens) + " tok; message history "
119 + std::to_string(context_fit_history_tokens(f)) + " tok";
120}
121
135inline std::string context_overflow_message(const ContextFit& f) {
136 return "Prompt does not fit this tier's context: "
137 + std::to_string(f.prompt_tokens) + " prompt tokens against "
138 "context_length=" + std::to_string(f.context_length)
139 + " (over by "
140 + std::to_string(f.prompt_tokens - f.context_length)
141 + " tokens). Largest contributor: "
142 + context_fit_largest_contributor(f) + ". Breakdown: "
144 + ". Refused before decode — compaction cannot shrink the staged "
145 "tool block. Raise this tier's context_length, or narrow its "
146 "allowed_tools.";
147}
148
149} // namespace entropic
150
151#endif // ENTROPIC_INFERENCE_CONTEXT_FIT_H
Activate model on GPU (WARM → ACTIVE).
std::string context_fit_largest_contributor(const ContextFit &f)
Name the single largest contributor to the overflow.
Definition context_fit.h:94
@ optional
optional: every escape asks the host's path approver
int context_fit_history_tokens(const ContextFit &f)
Tokens left over once system prompt and tool block are accounted.
Definition context_fit.h:76
std::string context_overflow_message(const ContextFit &f)
The refusal an operator reads, carrying every number they need.
std::string context_fit_breakdown(const ContextFit &f)
Per-contributor token breakdown, as one clause.
bool context_fit_overflows(const ContextFit &f)
Whether this turn's prompt cannot fit the tier's context at all.
Definition context_fit.h:65
One turn's irreducible prompt, measured against the tier budget.
Definition context_fit.h:41
int prompt_tokens
Rendered + tokenized prompt for this turn.
Definition context_fit.h:42
int tool_count
Number of staged tool definitions.
Definition context_fit.h:47
int tool_tokens
Tokens attributable to the staged tools.
Definition context_fit.h:45
std::size_t tool_bytes
Raw bytes of the staged tool JSON.
Definition context_fit.h:46
int context_length
Tier's PER-SESSION context window.
Definition context_fit.h:43
int system_tokens
Tokens attributable to the system prompt.
Definition context_fit.h:44