Commit graph

70 commits

Author SHA1 Message Date
Martín Bravo
900a97fa55 Merge branch 'main' of https://github.com/openai/openai-agents-python into feat/draw_graph 2025-03-25 16:58:01 +01:00
Rohan Mehta
923a3547eb
Fix parallel_tool_calls when False (#333)
Currently, when we set `parallel_tool_calls=False` in the
`model_settings`, the responses API is called with `parallel_tool_calls
== NotGiven`, which defaults to true on the Response API side
(https://platform.openai.com/docs/api-reference/responses/create#responses-create-parallel_tool_calls).

This PR attempts to fix that.

```
agent = Agent(
    ...,
    model_settings=ModelSettings(
        parallel_tool_calls=False,
    ),
)
```
2025-03-25 11:31:06 -04:00
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
apeccaud
326ff09127 Fix parallel_tool_calls when False 2025-03-25 14:52:48 +00:00
Martín Bravo
623063b633 refactor: clean up visualization functions by removing unused nodes and improving type hints 2025-03-24 09:47:21 +01:00
Martín Bravo
a5b7abe8b4 feat: enhance visualization functions with optional type hints and improved handling of agents and handoffs 2025-03-24 09:30:13 +01:00
Rohan Mehta
4cb011c4d2
Fix Typos (#258)
Noticed a bunch of typos when reading code, fixing.
2025-03-23 20:28:14 -04:00
Rohan Mehta
668fac0f74 Improve tracing error messages 2025-03-23 18:14:10 -04:00
xianghuijin
07a4af1fe2 refactor: improve comments for clarity in tool_choice reset logic 2025-03-23 20:41:18 +08:00
xianghuijin
0c747af743 refactor: streamline tool_choice reset logic
This update moves the tool_choice reset logic to a more appropriate location within the RunImpl class, ensuring that the original agent's model_settings remains unmodified during the reset process. The logic now checks for problematic scenarios before creating a modified copy of the agent's settings, maintaining expected behavior across sequential runs. This change enhances clarity and efficiency in handling tool choices.

Addresses previous feedback regarding the modification of the agent instance and improves the overall structure of the reset logic.
2025-03-23 20:04:39 +08:00
xianghuijin
6ed0bee672 fix: prevent modifying the original agent's model_settings
This fixes the issue where the original agent's model_settings was being directly modified during the tool choice reset process. The original implementation caused the agent's tool_choice to unintentionally reset to "auto" for subsequent runs, which could be unexpected behavior.

The fix creates new copies of the agent and model settings objects using dataclasses.replace() instead of modifying the original objects. This ensures that the tool choice reset is limited to the current run only, maintaining the expected behavior for sequential runs with the same agent.

Addresses feedback from @baderalfahad about the agent instance being modified when it should maintain its original state between runs.
2025-03-23 17:20:23 +08:00
xianghuijin
bbcda753df fix: optimize tool_choice reset logic and fix lint errors
- Refactor tool_choice reset to target only problematic edge cases
- Replace manual ModelSettings recreation with dataclasses.replace
- Fix line length and error handling lint issues in tests
2025-03-22 14:10:09 +08:00
Raduan77
ab0d940f19 revert src/ change per request 2025-03-22 01:06:01 +01:00
Rohan Mehta
c0794a90ec Read tracing API data lazily 2025-03-21 15:32:37 -04:00
Richie Caputo
b5305810d7
Create py.typed
- Ensure library is properly typehinted
2025-03-21 11:16:24 -04:00
Kazuhiro Sera
98c4b45b6a Make the optional dependency installation compatible with zsh 2025-03-21 10:01:24 +09:00
Rohan Mehta
1771c1e856 update tests 2025-03-20 13:08:38 -04:00
Dominik Kundel
c7ce154637 feat: add voice pipeline support
> Co-authored-by: rm@openai.com
2025-03-20 09:43:13 -07:00
xianghuijin
fb77c74fa1 Fix potential infinite tool call loop by resetting tool_choice after tool execution 2025-03-20 21:22:27 +08:00
Raduan77
e9f6d08260 fix typos in src/ 2025-03-20 11:24:08 +01:00
Rohan Mehta
8c9974bc90 Fix breaking changes from openai 1.66.2 2025-03-19 12:30:45 -04:00
Rohan Mehta
10aa5555af Introduce tool_use_behavior on agents 2025-03-18 21:55:12 -04:00
Rohan Mehta
6f7e801da0
Update tests and docs for strict mode decorator (#205)
As titled. Test plan: unit tests/docs.
2025-03-18 21:35:00 -04:00
Martín Bravo
f4edc1f372 style: improve string formatting in visualization functions 2025-03-18 10:15:41 +01:00
Martín Bravo
b7627cb642 style: improve string formatting 2025-03-18 10:14:52 +01:00
Martín Bravo
0079bca717 style: improve code formatting and readability in visualization functions 2025-03-18 10:09:44 +01:00
Martín Bravo
53367be893 feat: add visualization module for agent graphs using Graphviz 2025-03-18 09:55:30 +01:00
Martín Bravo
f7c594da08 feat: add visualization functions for agent graphs 2025-03-18 09:53:48 +01:00
Martín Bravo
aff1d60ea1 Merge branch 'main' of https://github.com/openai/openai-agents-python into feat/draw_graph 2025-03-17 23:50:52 +01:00
Rohan Mehta
d0a7b00086
Fix typo on Agent documentation (#151)
Argument name is not description but handoff_description
2025-03-17 16:51:47 -04:00
Carlos Souza
64150c8aea Fix lint 2025-03-17 16:14:28 -04:00
Rohan Mehta
0989cd9184
Add TracingProcessor export to __init__.py (#192)
# Summary
This adds the missing TracingProcessor export to  __init__.py.

# Behavior
When trying to add a custom tracing processor, the TracingProcessor
importing fails with not found error when trying the example usage
proposed in issue #164

Specifically this line throws the error:
`add_trace_processor(MyTracingProcessor("output"))`

# Expected Behavior
Inspecting the init file, simply the import/export was missing. Adding
these made the example code work for me

# Test plan
Local dev of example code in #164

# Issue number
#164

# Checks
None
2025-03-17 15:39:04 -04:00
Rohan Mehta
47aed7d362 Update tests and docs for strict mode decorator 2025-03-17 15:06:57 -04:00
Rohan Mehta
64e263b614 Pretty print result classes 2025-03-17 11:11:39 -04:00
Vincenzo Domina
1f58528f1c
Add TracingProcessor export to __init__.py 2025-03-17 10:37:43 +01:00
MartinEBravo
e984274da1 Merge branch 'main' of https://github.com/openai/openai-agents-python into feat/draw_graph 2025-03-17 10:17:36 +01:00
Rohan Mehta
09d70c074d utils directory 2025-03-16 18:48:45 -04:00
Rohan Mehta
951193bd21
feat: Add strict_mode option to function_schema and function_tool (#60)
This PR introduces a `strict_mode: bool = True` option to
`@function_tool`, allowing optional parameters when set to False. This
change enables more flexibility while maintaining strict JSON schema
validation by default.

resolves #43 

## Changes:

- Added `strict_mode` parameter to `@function_tool` and passed it to
`function_schema` and `FunctionTool`.
- Updated `function_schema.py` to respect `strict_mode` and allow
optional parameters when set to False.
- Added unit tests to verify optional parameters work correctly,
including multiple optional params with different types.

## Tests:

- Verified function calls with missing optional parameters behave as
expected.
- Added async tests to validate behavior under different configurations.
2025-03-16 17:43:46 -04:00
Carlos Souza
26828e5e68
Fix typo on Agent documentation
Argument name is not description but handoff_description
2025-03-13 16:18:40 -04:00
Rohan Mehta
7f68a7da2a
Consolidate to one logger (#149)
Results in double logging if we dont. Closes #141.
2025-03-13 11:38:18 -07:00
Rohan Mehta
17f0a425ba Consolidate to one logger 2025-03-13 13:55:15 -04:00
Martín Bravo
29e9983ae8 Linting 2025-03-13 18:49:12 +01:00
Martín Bravo
cecdcd0af4 Add visualization functions for agents using Graphviz 2025-03-13 18:33:12 +01:00
Rohan Mehta
4db24bdb3c Update tracing docs to be correct 2025-03-13 13:20:27 -04:00
Rohan Mehta
16cfce117c
Add examples and documentation for using custom model providers (#110) 2025-03-13 08:17:25 -07:00
Rohan Mehta
341198ff92 Add request ID 2025-03-12 18:07:59 -07:00
Rohan Mehta
25a633139d Add examples and documentation for using custom model providers 2025-03-12 17:34:38 -07:00
Rohan Mehta
2302b478af Fix streaming in chat completions 2025-03-12 17:17:07 -07:00
Rohan Mehta
18b10f1371
Merge pull request #105 from openai/pr105
Add max_tokens and documentation to model settings
2025-03-12 13:45:21 -07:00
Rohan Mehta
fde49cfcf7 Add max_tokens and documentation to model settings 2025-03-12 13:35:10 -07:00