% --- Context-management mechanism: truncation + adaptive summarization --- \begin{figure}[htbp] \centering \begin{tikzpicture}[vqfont, msg/.style={vqbox, minimum width=0.62cm, minimum height=0.62cm, inner sep=1pt, font=\vqtiny}, oldm/.style={msg, fill=VQInk!8, draw=VQInk!45}, recm/.style={msg, fill=VQTeal!16, draw=VQTeal!70!black}, brace/.style={decorate, decoration={brace, amplitude=4pt}, draw=VQInk!55, line width=0.5pt}] % ---- BEFORE row ---- \node[vqsmall, anchor=west, text=VQInk] at (-0.2,2.5) {\textbf{Before} (full message history)}; \foreach \i in {0,1,2,3,4} { \node[oldm] (o\i) at (\i*0.7,1.3) {}; } \node[recm] (r0) at (3.7,1.3) {}; \node[recm] (r1) at (4.4,1.3) {}; \node[recm] (r2) at (5.1,1.3) {}; \node[recm] (r3) at (5.8,1.3) {}; \node[recm] (r4) at (6.5,1.3) {}; % oversized tool result being capped \node[vqbox, fill=VQRed!10, draw=VQRed!75!black, minimum width=0.62cm, minimum height=1.15cm, inner sep=1pt, font=\vqtiny] (big) at (1.4,1.55) {}; \node[vqtag, right=1pt of big, yshift=6pt] {cap at 5000 chars}; \draw[brace] (-0.25,0.92) -- (2.75,0.92); \node[vqsmall, anchor=north, text=VQInk!75] at (1.25,0.82) {older turns}; \draw[brace] (3.4,0.92) -- (6.8,0.92); \node[vqsmall, anchor=north, text=VQTeal!60!black] at (5.1,0.82) {last $k=5$}; % ---- Transformation gate ---- \node[vqorange, text width=6.0cm] (gate) at (3.2,-0.55) {\textbf{Estimate} $t \approx \text{chars}/4$. \quad If $t>\tau=10^{5}$:}; \draw[vqarr] (1.25,0.5) -- (gate.north -| 1.25,0); % ---- AFTER row ---- \node[vqsmall, anchor=west, text=VQInk] at (-0.2,-2.55) {\textbf{After}}; \node[vqpurple, minimum width=2.75cm, minimum height=0.62cm, font=\vqtiny] (sum) at (1.18,-1.95) {\textbf{[summary]} (one model call)}; \node[recm] (s0) at (3.7,-1.95) {}; \node[recm] (s1) at (4.4,-1.95) {}; \node[recm] (s2) at (5.1,-1.95) {}; \node[recm] (s3) at (5.8,-1.95) {}; \node[recm] (s4) at (6.5,-1.95) {}; \draw[vqflow] (gate.west) to[out=180,in=90] node[vqtag,pos=0.6,left]{summarize} (sum.north); \draw[vqarr] (gate.east) to[out=0,in=90] node[vqtag,pos=0.55,right]{keep} (5.1,-1.63); \end{tikzpicture} \caption{\textbf{Context management.} Before each model call the server caps every individual tool-result block at a fixed character budget (red), then estimates the total token count with a cheap chars-per-four heuristic. If the estimate exceeds the threshold $\tau$, the older turns are compressed by a single dedicated summarization call into one synthetic \texttt{[summary]} message (purple), while the most recent $k=5$ turns (teal) are kept verbatim. The mechanism makes conversation length effectively unbounded at the cost of one extra call when the threshold is crossed.} \label{fig:context} \end{figure}