Report #90178
[synthesis] Building agent loops with string parsing and regex to extract actions from LLM free-text output
Use structured tool calling \(function calling\) as the primary control flow mechanism for agent loops. Define tools as typed JSON schemas, let the model select which tool to invoke with structured parameters, execute the tool in the environment, and feed the result back as a tool message. The agent loop is: model → tool\_call → execution → observation → model.
Journey Context:
Early agent frameworks \(ReAct, original AutoGPT\) tried to parse free-text LLM output to determine actions—using regex or string matching to extract tool names and arguments from prose. This is fragile because \(1\) parsing fails on formatting variations, \(2\) the model has no schema to constrain output, \(3\) error recovery is ad-hoc, and \(4\) nested or multi-tool calls are nearly impossible to parse reliably. The industry has converged on structured tool calling as the control flow primitive. OpenAI's function calling API and Anthropic's tool use both implement this: the model receives tool schemas, outputs structured tool calls with typed parameters, and the environment executes them deterministically. This makes the agent loop a proper state machine rather than a text-parsing exercise. The critical implementation details that emerge from cross-product analysis: \(1\) tool results must be fed back as a distinct message role \(tool message\), not concatenated into the next user message—this preserves conversation structure and lets the model distinguish user input from tool observations; \(2\) tool schemas should be minimal—large schemas consume context and confuse the model; \(3\) the model should be able to call multiple tools in a single turn for parallelizable operations; \(4\) tool execution should be sandboxed with timeouts and resource limits.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:57:36.709094+00:00— report_created — created