Skip to content

Commit 900a97f

Browse files
committed
Merge branch 'main' of https://github.com/openai/openai-agents-python into feat/draw_graph
2 parents 623063b + 923a354 commit 900a97f

File tree

105 files changed

+6255
-767
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+6255
-767
lines changed

.github/workflows/issues.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ jobs:
1717
stale-issue-label: "stale"
1818
stale-issue-message: "This issue is stale because it has been open for 7 days with no activity."
1919
close-issue-message: "This issue was closed because it has been inactive for 3 days since being marked as stale."
20-
days-before-pr-stale: -1
21-
days-before-pr-close: -1
22-
any-of-labels: 'question,needs-more-info'
20+
any-of-issue-labels: 'question,needs-more-info'
21+
days-before-pr-stale: 10
22+
days-before-pr-close: 7
23+
stale-pr-label: "stale"
24+
stale-pr-message: "This PR is stale because it has been open for 10 days with no activity."
25+
close-pr-message: "This PR was closed because it has been inactive for 7 days since being marked as stale."
2326
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
branches:
99
- main
1010

11+
env:
12+
UV_FROZEN: "1"
13+
1114
jobs:
1215
lint:
1316
runs-on: ubuntu-latest
@@ -50,8 +53,8 @@ jobs:
5053
enable-cache: true
5154
- name: Install dependencies
5255
run: make sync
53-
- name: Run tests
54-
run: make tests
56+
- name: Run tests with coverage
57+
run: make coverage
5558

5659
build-docs:
5760
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ dmypy.json
135135
cython_debug/
136136

137137
# PyCharm
138-
#.idea/
138+
.idea/
139139

140140
# Ruff stuff:
141141
.ruff_cache/

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sync:
55
.PHONY: format
66
format:
77
uv run ruff format
8+
uv run ruff check --fix
89

910
.PHONY: lint
1011
lint:
@@ -18,6 +19,13 @@ mypy:
1819
tests:
1920
uv run pytest
2021

22+
.PHONY: coverage
23+
coverage:
24+
25+
uv run coverage run -m pytest
26+
uv run coverage xml -o coverage.xml
27+
uv run coverage report -m --fail-under=95
28+
2129
.PHONY: snapshots-fix
2230
snapshots-fix:
2331
uv run pytest --inline-snapshot=fix
@@ -29,7 +37,6 @@ snapshots-create:
2937
.PHONY: old_version_tests
3038
old_version_tests:
3139
UV_PROJECT_ENVIRONMENT=.venv_39 uv run --python 3.9 -m pytest
32-
UV_PROJECT_ENVIRONMENT=.venv_39 uv run --python 3.9 -m mypy .
3340

3441
.PHONY: build-docs
3542
build-docs:
@@ -42,4 +49,6 @@ serve-docs:
4249
.PHONY: deploy-docs
4350
deploy-docs:
4451
uv run mkdocs gh-deploy --force --verbose
52+
53+
4554

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ source env/bin/activate
3030
pip install openai-agents
3131
```
3232

33+
For voice support, install with the optional `voice` group: `pip install 'openai-agents[voice]'`.
34+
3335
## Hello world example
3436

3537
```python

docs/agents.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,23 @@ robot_agent = pirate_agent.clone(
130130
instructions="Write like a robot",
131131
)
132132
```
133+
134+
## Forcing tool use
135+
136+
Supplying a list of tools doesn't always mean the LLM will use a tool. You can force tool use by setting [`ModelSettings.tool_choice`][agents.model_settings.ModelSettings.tool_choice]. Valid values are:
137+
138+
1. `auto`, which allows the LLM to decide whether or not to use a tool.
139+
2. `required`, which requires the LLM to use a tool (but it can intelligently decide which tool).
140+
3. `none`, which requires the LLM to _not_ use a tool.
141+
4. Setting a specific string e.g. `my_tool`, which requires the LLM to use that specific tool.
142+
143+
!!! note
144+
145+
To prevent infinite loops, the framework automatically resets `tool_choice` to "auto" after a tool call in the following scenarios:
146+
147+
1. When `tool_choice` is set to a specific function name (any string that's not "auto", "required", or "none")
148+
2. When `tool_choice` is set to "required" AND there is only one tool available
149+
150+
This targeted reset mechanism allows the model to decide whether to make additional tool calls in subsequent turns while avoiding infinite loops in these specific cases.
151+
152+
If you want the Agent to completely stop after a tool call (rather than continuing with auto mode), you can set [`Agent.tool_use_behavior="stop_on_first_tool"`] which will directly use the tool output as the final response without further LLM processing.

docs/context.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ async def fetch_user_age(wrapper: RunContextWrapper[UserInfo]) -> str: # (2)!
4141
return f"User {wrapper.context.name} is 47 years old"
4242

4343
async def main():
44-
user_info = UserInfo(name="John", uid=123) # (3)!
44+
user_info = UserInfo(name="John", uid=123)
4545

46-
agent = Agent[UserInfo]( # (4)!
46+
agent = Agent[UserInfo]( # (3)!
4747
name="Assistant",
4848
tools=[fetch_user_age],
4949
)
5050

51-
result = await Runner.run(
51+
result = await Runner.run( # (4)!
5252
starting_agent=agent,
5353
input="What is the age of the user?",
5454
context=user_info,

docs/examples.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Examples
2+
3+
Check out a variety of sample implementations of the SDK in the examples section of the [repo](https://github.com/openai/openai-agents-python/tree/main/examples). The examples are organized into several categories that demonstrate different patterns and capabilities.
4+
5+
6+
## Categories
7+
8+
- **agent_patterns:**
9+
Examples in this category illustrate common agent design patterns, such as
10+
11+
- Deterministic workflows
12+
- Agents as tools
13+
- Parallel agent execution
14+
15+
- **basic:**
16+
These examples showcase foundational capabilities of the SDK, such as
17+
18+
- Dynamic system prompts
19+
- Streaming outputs
20+
- Lifecycle events
21+
22+
- **tool examples:**
23+
Learn how to implement OAI hosted tools such as web search and file search,
24+
and integrate them into your agents.
25+
26+
- **model providers:**
27+
Explore how to use non-OpenAI models with the SDK.
28+
29+
- **handoffs:**
30+
See practical examples of agent handoffs.
31+
32+
- **customer_service** and **research_bot:**
33+
Two more built-out examples that illustrate real-world applications
34+
35+
- **customer_service**: Example customer service system for an airline.
36+
- **research_bot**: Simple deep research clone.

docs/guardrails.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Output guardrails run in 3 steps:
2929

3030
!!! Note
3131

32-
Output guardrails are intended to run on the final agent input, so an agent's guardrails only run if the agent is the *last* agent. Similar to the input guardrails, we do this because guardrails tend to be related to the actual Agent - you'd run different guardrails for different agents, so colocating the code is useful for readability.
32+
Output guardrails are intended to run on the final agent output, so an agent's guardrails only run if the agent is the *last* agent. Similar to the input guardrails, we do this because guardrails tend to be related to the actual Agent - you'd run different guardrails for different agents, so colocating the code is useful for readability.
3333

3434
## Tripwires
3535

@@ -111,8 +111,8 @@ class MessageOutput(BaseModel): # (1)!
111111
response: str
112112

113113
class MathOutput(BaseModel): # (2)!
114-
is_math: bool
115114
reasoning: str
115+
is_math: bool
116116

117117
guardrail_agent = Agent(
118118
name="Guardrail check",

docs/ref/voice/events.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Events`
2+
3+
::: agents.voice.events

0 commit comments

Comments
 (0)