context_fit.h¶
src/inference/context_fit.h
@file context_fit.h @brief v2.13.0 prompt-vs-context admission arithmetic for one turn.
Owners: @tvanfossen
context_fit_breakdown
std::string entropic::context_fit_breakdown(const ContextFit &f)
Per-contributor token breakdown, as one clause.
src/inference/context_fit.h:114
Source · 7 lines
inline std::string context_fit_breakdown(const ContextFit& f) {
return "staged tools " + std::to_string(f.tool_tokens) + " tok ("
+ std::to_string(f.tool_count) + " tools, "
+ std::to_string(f.tool_bytes) + " bytes); system prompt "
+ std::to_string(f.system_tokens) + " tok; message history "
+ std::to_string(context_fit_history_tokens(f)) + " tok";
}Activity · 1 steps
Requirements
context_fit_overflows
bool entropic::context_fit_overflows(const ContextFit &f)
Whether this turn's prompt cannot fit the tier's context at all.
src/inference/context_fit.h:65
Source · 3 lines
inline bool context_fit_overflows(const ContextFit& f) {
return f.context_length > 0 && f.prompt_tokens >= f.context_length;
}Activity · 1 steps
Requirements
context_overflow_message
std::string entropic::context_overflow_message(const ContextFit &f)
The refusal an operator reads, carrying every number they need.
src/inference/context_fit.h:135
Called by SCENARIO, refuse_over_context
Calls context_fit_breakdown, context_fit_largest_contributor
Source · 13 lines
inline std::string context_overflow_message(const ContextFit& f) {
return "Prompt does not fit this tier's context: "
+ std::to_string(f.prompt_tokens) + " prompt tokens against "
"context_length=" + std::to_string(f.context_length)
+ " (over by "
+ std::to_string(f.prompt_tokens - f.context_length)
+ " tokens). Largest contributor: "
+ context_fit_largest_contributor(f) + ". Breakdown: "
+ context_fit_breakdown(f)
+ ". Refused before decode — compaction cannot shrink the staged "
"tool block. Raise this tier's context_length, or narrow its "
"allowed_tools.";
}