Report #47101
[frontier] Agent takes wrong actions or loops infinitely during multi-step tasks despite good prompts
Model agent behavior as a finite state machine where each state transition is a structured output with a discriminated union \(oneOf\) type. Define a JSON schema for each possible next action with typed parameters. Use the structured output as the control flow mechanism—the LLM fills in the transition, it doesn't design the state graph. Validate every transition against the schema before execution.
Journey Context:
The default agent pattern lets the LLM reason in free-form text, then parses its intent to select a tool or action. This is fragile: the LLM can hallucinate actions not in the tool set, loop on the same failed approach, or produce unparseable outputs. Structured outputs \(JSON schema constrained generation\) flip the model: instead of the LLM deciding what actions exist, you define the action space as a typed schema and the LLM selects within it. This is the difference between 'think about what to do' and 'choose from these valid options with these parameters.' The tradeoff: reduced flexibility—the LLM can't invent novel action types mid-flow. But that's a feature, not a bug, in production systems. Teams report 3-5x reduction in invalid action errors. The critical implementation detail: use discriminated unions \(a 'type' field that determines the schema\) so the LLM commits to one action type, not a blend. And never put the state graph description in the schema itself—put it in the system prompt, use the schema only for the transition shape.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:31:56.392183+00:00— report_created — created