TeX 93.9%
Python 6%
1% --- Recursive tool-calling loop flowchart ---2\begin{figure}[htbp]3\centering4\begin{tikzpicture}[vqfont, node distance=0.72cm]56\node[vqteal, text width=3.2cm] (start)7 {\textbf{User query}\\\vqsmall (+ optional image)};8\node[vqblue, below=of start, text width=4.4cm] (stream)9 {\textbf{Stream model call}\\\vqsmall system prompt $+$ context $+$ tools};10\node[vqdecision, below=0.95cm of stream, text width=1.9cm] (dec)11 {\vqsmall tools\\requested?};12\node[vqgreen, right=2.0cm of dec, text width=3.0cm] (final)13 {\textbf{Final report}\\\vqsmall accumulated text $\to$ export};1415\node[vqblue, below=1.0cm of dec, text width=4.6cm] (asst)16 {\textbf{Append} assistant \texttt{tool\_use} blocks};17\node[vqblue, below=of asst, text width=6.0cm] (batch)18 {\textbf{For each batch ($\leq 5$ tools)}\\\vqsmall execute in batch $\cdot$ stream typed result $\cdot$ \textsc{wait} 500\,ms};19\node[vqblue, below=of batch, text width=4.6cm] (res)20 {\textbf{Append} user \texttt{tool\_result} blocks};2122% Edges23\draw[vqarr] (start) -- (stream);24\draw[vqarr] (stream) -- (dec);25\draw[vqarr] (dec) -- node[above, vqsmall]{no} (final);26\draw[vqarr] (dec) -- node[right, vqsmall]{yes} (asst);27\draw[vqarr] (asst) -- (batch);28\draw[vqarr] (batch) -- (res);2930% Recursion arrow (left side, back up to stream)31\draw[vqflow] (res.west) -- ++(-2.55,0)32 node[vqtag, midway, above]{recurse}33 |- (stream.west);3435\end{tikzpicture}36\caption{\textbf{The recursive tool-calling loop.} A single routine streams one model call. If no37tools are requested, the accumulated text is the report and the recursion unwinds. Otherwise the38server appends the model's \texttt{tool\_use} blocks (as an assistant turn), executes the requested39tools in throttled batches of at most five, appends the matching \texttt{tool\_result} blocks (as40a user turn), and \emph{re-enters} the same routine with the augmented context (heavy teal arrow).41The strict pairing of \texttt{tool\_use} and \texttt{tool\_result} blocks across the recursion is42the loop's central invariant.}43\label{fig:loop}44\end{figure}45