% --- Recursive tool-calling loop flowchart --- \begin{figure}[htbp] \centering \begin{tikzpicture}[vqfont, node distance=0.72cm] \node[vqteal, text width=3.2cm] (start) {\textbf{User query}\\\vqsmall (+ optional image)}; \node[vqblue, below=of start, text width=4.4cm] (stream) {\textbf{Stream model call}\\\vqsmall system prompt $+$ context $+$ tools}; \node[vqdecision, below=0.95cm of stream, text width=1.9cm] (dec) {\vqsmall tools\\requested?}; \node[vqgreen, right=2.0cm of dec, text width=3.0cm] (final) {\textbf{Final report}\\\vqsmall accumulated text $\to$ export}; \node[vqblue, below=1.0cm of dec, text width=4.6cm] (asst) {\textbf{Append} assistant \texttt{tool\_use} blocks}; \node[vqblue, below=of asst, text width=6.0cm] (batch) {\textbf{For each batch ($\leq 5$ tools)}\\\vqsmall execute in batch $\cdot$ stream typed result $\cdot$ \textsc{wait} 500\,ms}; \node[vqblue, below=of batch, text width=4.6cm] (res) {\textbf{Append} user \texttt{tool\_result} blocks}; % Edges \draw[vqarr] (start) -- (stream); \draw[vqarr] (stream) -- (dec); \draw[vqarr] (dec) -- node[above, vqsmall]{no} (final); \draw[vqarr] (dec) -- node[right, vqsmall]{yes} (asst); \draw[vqarr] (asst) -- (batch); \draw[vqarr] (batch) -- (res); % Recursion arrow (left side, back up to stream) \draw[vqflow] (res.west) -- ++(-2.55,0) node[vqtag, midway, above]{recurse} |- (stream.west); \end{tikzpicture} \caption{\textbf{The recursive tool-calling loop.} A single routine streams one model call. If no tools are requested, the accumulated text is the report and the recursion unwinds. Otherwise the server appends the model's \texttt{tool\_use} blocks (as an assistant turn), executes the requested tools in throttled batches of at most five, appends the matching \texttt{tool\_result} blocks (as a user turn), and \emph{re-enters} the same routine with the augmented context (heavy teal arrow). The strict pairing of \texttt{tool\_use} and \texttt{tool\_result} blocks across the recursion is the loop's central invariant.} \label{fig:loop} \end{figure}