openai-agents-python/docs
Rohan Mehta 927a29c56b
Fix potential infinite tool call loop by resetting tool_choice after … (#263)
# Fix potential infinite tool call loop by resetting tool_choice after
tool execution

## Summary

This PR fixes an issue where setting `tool_choice` to "required" or a
specific function name could cause models to get stuck in an infinite
tool call loop.

When `tool_choice` is set to force tool usage, this setting persists
across model invocations. This PR automatically resets `tool_choice` to
"auto" after tool execution, allowing the model to decide whether to
make additional tool calls in subsequent turns.

Unlike using `tool_use_behavior="stop_on_first_tool"`, this approach
lets the model continue processing tool results while preventing forced
repeated tool calls.

## Test plan

- Added tests to verify tool_choice reset behavior for both agent and
run_config settings
- Added integration test to verify the solution prevents infinite loops
- All tests pass

## Checks

- [x] I've added new tests for the fix
- [x] I've updated the relevant documentation (added comment in code)
- [x] I've run `make lint` and `make format`
- [x] I've made sure tests pass
2025-03-25 11:30:53 -04:00
..
assets Initial commit 2025-03-11 09:42:28 -07:00
ref feat: add voice pipeline support 2025-03-20 09:43:13 -07:00
stylesheets Initial commit 2025-03-11 09:42:28 -07:00
voice Update quickstart.md 2025-03-23 17:56:55 -04:00
agents.md docs: Update tool_choice reset documentation to match implementation 2025-03-22 14:22:47 +08:00
config.md fix typo 2025-03-12 11:24:12 +08:00
context.md fix annotation numbering in context management 2025-03-21 21:10:30 +00:00
examples.md formatting updates to examples doc 2025-03-19 14:23:28 -07:00
guardrails.md fix line in guardrails 2025-03-21 15:58:34 -04:00
handoffs.md Initial commit 2025-03-11 09:42:28 -07:00
index.md fix: hyphenated compound adjective real world -> real-world for clarity 2025-03-12 10:48:29 +05:45
models.md Update model docs with common issues 2025-03-13 13:43:18 -04:00
multi_agent.md docs: clarify multi-agent orchestration description 2025-03-11 23:57:03 +01:00
quickstart.md Update quickstart.md 2025-03-12 00:48:29 +00:00
results.md docs: Fix typos in documentation files 2025-03-12 00:12:31 +01:00
running_agents.md fix: replace undefined variable name in documentation code snippet 2025-03-12 15:07:56 +03:00
streaming.md Initial commit 2025-03-11 09:42:28 -07:00
tools.md Initial commit 2025-03-11 09:42:28 -07:00
tracing.md Add Weights & Biases to tracing docs 2025-03-21 21:37:54 +00:00