A setting that works once and then loops
Most model APIs let the caller force a tool call. In the OpenAI Agents SDK the agent's model_settings.tool_choice accepts "required" or a tool name. The Claude Messages API accepts tool_choice of type any or tool. The Gemini API's function calling configuration has a mode ANY, documented in the Google Gen AI SDK as "Model is constrained to always predicting function calls only." Forcing is useful: a help-desk agent at Belgavi's Book Store should look up the return case before it answers anything about CASE-5120, and forcing the first call removes one class of invented answers.
The trouble is that forcing is a per-request setting, and an agent loop sends many requests. If the same forced setting goes out with the request that carries the tool result, the model must call a tool again. Then again. The loop ends only when a turn limit, a budget or a timeout stops it, and the caller sees an error instead of an answer.
Measured with a scripted model
To see what the OpenAI Agents SDK does, I ran a small offline experiment with openai-agents 0.26.2 (installed with uv, --exclude-newer 2026-12-06) and a scripted model class that obeys whatever tool_choice it receives: it returns a function call when the setting is "required" or names the tool, and a text answer otherwise. No provider was called; the scripted model stands in for a model that follows the constraint, which is what the constraint promises.
reset_tool_choice | tool_choice | Model calls | Settings sent | Result |
|---|---|---|---|---|
| True (default) | required | 2 | required, then none | Final answer |
| True (default) | lookup_return | 2 | lookup_return, then none | Final answer |
| False | required | 6 | required every time | MaxTurnsExceeded at max_turns=6 |
| False | lookup_return | 6 | lookup_return every time | MaxTurnsExceeded at max_turns=6 |
The SDK's default is the safe one. In 0.26.2, Agent.reset_tool_choice defaults to True, with the docstring "This ensures that the agent doesn't enter an infinite loop of tool usage", and the run loop calls a helper that replaces the setting with None once the tool-use tracker shows the agent has used a tool. With the default, the second request goes out with no forced choice and the model answers. Turning the reset off reproduces the loop exactly: every request is forced, and the run stops only at the turn limit, which defaults to 10 when not set.
The SDK documentation adds two details worth keeping. Reset takes effect only after the agent has used a tool. And "required" forces a tool call before the agent has gathered any context, so if one of the available tools changes state, the first call can be the one that changes it.
Other providers put the reset on you
The Claude Messages API and the Gemini API are stateless with respect to this setting: each request carries its own tool_choice or function calling mode. Nothing resets it for you. If your loop builds every request from the same configuration object, a forced choice stays forced. Claude's documentation also notes that not every model and setting supports forced tool use (for example manual extended thinking), in which case any and tool fail while auto and none still work, and that changing tool_choice invalidates cached message blocks in prompt caching. That second point matters for cost: switching from forced to auto on the second request means the conversation prefix is not served from cache on that request.
The Google Gen AI Python SDK's automatic function calling runs the loop inside the SDK and stops after a maximum number of remote calls, 10 by default (AutomaticFunctionCallingConfig.maximum_remote_calls). With mode ANY set in the same config, that cap is what ends the loop.
What stays deterministic
The decision of when to force a tool is a property of the workflow, not of the model. Write it as code that looks at the run's state:
def choose_tool_setting(step: int, calls_so_far: list[str]) -> str:
"""Force the case lookup exactly once, then let the model decide."""
if step == 0 and "lookup_return" not in calls_so_far:
return "lookup_return" # provider-specific: tool name, {"type": "tool", ...} or mode ANY
return "auto"
assert choose_tool_setting(0, []) == "lookup_return"
assert choose_tool_setting(1, ["lookup_return"]) == "auto"Three rules cover most cases:
- Force a specific tool, once, at a known step. Forcing "any tool" when several tools exist lets the model pick a state-changing one first.
- Reset after the forced call completes, not after the model emits it. If the tool call fails and you retry, you may want to force it again; make that an explicit branch.
- Bound every loop independently. A turn limit, a tool-call budget and a wall-clock deadline should each be able to stop the run, and the stop should produce a clear error that names which bound fired.
When forcing is the wrong tool
If the workflow always needs the case lookup first, the cleanest design often removes the choice entirely: call the lookup in code, put its result in the context, and let the model answer with the data already present. That is cheaper, avoids a model round trip, and cannot loop. Forcing makes sense when the model must produce the tool's arguments from user text, for example extracting the case number from a free-form message, and you want the structured output of a tool call rather than free text.
Some SDKs offer a different exit: the OpenAI Agents SDK's tool_use_behavior="stop_on_first_tool" treats the first tool's output as the final output, and StopAtTools does the same for named tools. That suits extraction flows where the tool call is the product. It does not suit a help-desk flow where the model must read the tool's result and write a reply.
Failure modes
- Loop until the turn limit. The symptom is a run that ends with a turn-limit error and a log of identical tool calls. Search traces for repeated calls with the same arguments.
- Forced state change first. With
requiredand a mix of read and write tools, the first call may be the write. Force a named read tool, or expose only read tools at step 0. - Cache misses from switching. On providers where
tool_choiceis part of the cache key, alternating settings lowers the cache hit rate. Measure before and after. - Retries re-force a completed call. A retry wrapper that resends the original request also resends the forced setting. Build retries from the current run state.
- Unsupported combination. A forced choice combined with a mode that does not support it fails the request. Test each model and setting combination you deploy.
Tradeoffs between the three exits
Resetting the setting, stopping on the tool and removing the choice all end the loop, but they produce different runs. A reset adds one model round trip after the forced call: the model reads the tool result and writes the answer, which costs input tokens for the whole history again and the latency of a second call. Stopping on the first tool saves that round trip and returns the tool's output as the answer, which is right only when the tool output is what the caller wants. Calling the lookup in code before the model runs saves a model call entirely and makes the lookup unconditional, which is right when every case needs it and wrong when some messages are not about a case at all, for example a customer asking about opening hours.
A useful test is to write down, for each forced tool, what the run should look like in a trace: how many model calls, how many tool calls, and which call produces the final text. If that description has a fixed shape, it belongs in code. If it varies with the message, keep the model in the loop and force only the first step.
Verification
The companion example contains the scripted model used above, plus a framework-free loop that applies the same rule, with tests that fail if a forced setting is sent twice. In your own system, add an assertion in the request builder: if the previous request forced a tool and the run has since received that tool's result, the next request must not force it again unless the code path says so. Then check traces for runs ending at the turn limit; each one is either a loop or a task that genuinely needs more steps, and the two need different fixes.