Mistral AI agent circuit breaker: stopping loop failures in Mistral Large and Mixtral function-calling agents

Mistral AI’s models — Mistral Large 2, Mixtral 8x22B, and Mistral 7B — support native function calling via the /v1/chat/completions API. Building an agentic loop on top of Mistral is straightforward: define tools, call the API, execute the returned function calls, append results, repeat. What’s missing is a runtime safety layer. If a Mistral agent enters a tool-call loop — calling the same function with the same arguments on every turn because the result never advances the agent’s goal — the loop runs until your billing quota is exhausted or you manually kill the process. RunGuard adds a circuit breaker at the model-call boundary: loop detection fires on the third repetition of any pattern up to length 4, and a dollar-based budget cap fires before each call if accumulated spend exceeds your threshold.

Why Mistral agents loop: the function-call failure modes

Adding a circuit breaker to a Mistral agent in Python

Mistral-specific considerations for production agents

Mistral API defaults vs. RunGuard

ControlMistral API defaultRunGuard
Tool-call loop detectionNot supportedloop: repeats=3 fires on 3rd repeat of same pattern
Per-run cost capNot supportedbudget: max_usd fires before each API call
Parallel-call cycle detectionNot supportedCompound signature (sorted tool names) covers parallel calls
Context-window guard400 error after request sentPre-call ContextOverflowError before request sent
Max turnsNot supported (host-side only)Implicit via loop + budget caps
Slack/PagerDuty alert on tripNot supportedalerts: slack_webhook or pagerduty_key