Skip to content

Commit 846be16

Browse files
authored
Merge branch 'openai:main' into main
2 parents fe8a87d + 18cb55e commit 846be16

Some content is hidden

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

78 files changed

+4985
-2411
lines changed

.github/workflows/issues.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
days-before-pr-stale: 10
2222
days-before-pr-close: 7
2323
stale-pr-label: "stale"
24+
exempt-issue-labels: "skip-stale"
2425
stale-pr-message: "This PR is stale because it has been open for 10 days with no activity."
2526
close-pr-message: "This PR was closed because it has been inactive for 7 days since being marked as stale."
2627
repo-token: ${{ secrets.GITHUB_TOKEN }}

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Welcome to the OpenAI Agents SDK repository. This file contains the main points
3535

3636
Coverage can be generated with `make coverage`.
3737

38+
All python commands should be run via `uv run python ...`
39+
3840
## Snapshot tests
3941

4042
Some tests rely on inline snapshots. See `tests/README.md` for details on updating them:
@@ -64,6 +66,6 @@ Commit messages should be concise and written in the imperative mood. Small, foc
6466
## What reviewers look for
6567

6668
- Tests covering new behaviour.
67-
- Consistent style: code formatted with `ruff format`, imports sorted, and type hints passing `mypy`.
69+
- Consistent style: code formatted with `uv run ruff format`, imports sorted, and type hints passing `uv run mypy .`.
6870
- Clear documentation for any public API changes.
6971
- Clean history and a helpful PR description.

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Read the AGENTS.md file for instructions.

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ Explore the [examples](examples) directory to see the SDK in action, and read ou
2020

2121
1. Set up your Python environment
2222

23-
```
23+
- Option A: Using venv (traditional method)
24+
```bash
2425
python -m venv env
25-
source env/bin/activate
26+
source env/bin/activate # On Windows: env\Scripts\activate
27+
```
28+
29+
- Option B: Using uv (recommended)
30+
```bash
31+
uv venv
32+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
2633
```
2734

2835
2. Install Agents SDK
2936

30-
```
37+
```bash
3138
pip install openai-agents
3239
```
3340

@@ -50,7 +57,7 @@ print(result.final_output)
5057

5158
(_If running this, ensure you set the `OPENAI_API_KEY` environment variable_)
5259

53-
(_For Jupyter notebook users, see [hello_world_jupyter.py](examples/basic/hello_world_jupyter.py)_)
60+
(_For Jupyter notebook users, see [hello_world_jupyter.ipynb](examples/basic/hello_world_jupyter.ipynb)_)
5461

5562
## Handoffs example
5663

docs/context.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class UserInfo: # (1)!
3838

3939
@function_tool
4040
async def fetch_user_age(wrapper: RunContextWrapper[UserInfo]) -> str: # (2)!
41-
return f"User {wrapper.context.name} is 47 years old"
41+
"""Fetch the age of the user. Call this function to get user's age information."""
42+
return f"The user {wrapper.context.name} is 47 years old"
4243

4344
async def main():
4445
user_info = UserInfo(name="John", uid=123)

docs/guardrails.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Input guardrails run in 3 steps:
2323

2424
Output guardrails run in 3 steps:
2525

26-
1. First, the guardrail receives the same input passed to the agent.
26+
1. First, the guardrail receives the output produced by the agent.
2727
2. Next, the guardrail function runs to produce a [`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput], which is then wrapped in an [`OutputGuardrailResult`][agents.guardrail.OutputGuardrailResult]
2828
3. Finally, we check if [`.tripwire_triggered`][agents.guardrail.GuardrailFunctionOutput.tripwire_triggered] is true. If true, an [`OutputGuardrailTripwireTriggered`][agents.exceptions.OutputGuardrailTripwireTriggered] exception is raised, so you can appropriately respond to the user or handle the exception.
2929

docs/ja/guardrails.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ search:
44
---
55
# ガードレール
66

7-
ガードレールは エージェント と _並列_ に実行され、 ユーザー入力 のチェックとバリデーションを行います。たとえば、顧客からのリクエストを支援するために非常に賢い (そのため遅く / 高価な) モデルを使うエージェントがあるとします。悪意のある ユーザー がモデルに数学の宿題を手伝わせようとするのは避けたいですよね。その場合、 高速 / 低コスト のモデルでガードレールを実行できます。ガードレールが悪意のある利用を検知した場合、即座にエラーを送出して高価なモデルの実行を停止し、時間と費用を節約できます
7+
ガードレールは エージェント と _並行して_ 実行され、ユーザー入力のチェックとバリデーションを行えます。例えば、とても賢い(つまり遅く/高価な)モデルを使用してカスタマーリクエストを処理するエージェントがあるとします。悪意のある ユーザー がモデルに数学の宿題を手伝わせようとするのは避けたいでしょう。そこで、速く/安価なモデルで動くガードレールを実行できます。ガードレールが悪意のある利用を検知すると、直ちにエラーを送出して高価なモデルの実行を停止し、時間とコストを節約できます
88

9-
ガードレールには 2 種類あります
9+
ガードレールには 2 種類あります:
1010

11-
1. Input ガードレールは最初の ユーザー入力 に対して実行されます
12-
2. Output ガードレールは最終的なエージェント出力に対して実行されます
11+
1. 入力ガードレール は初期 ユーザー 入力に対して実行されます
12+
2. 出力ガードレール は最終的なエージェント出力に対して実行されます
1313

14-
## Input ガードレール
14+
## 入力ガードレール
1515

16-
Input ガードレールは 3 つのステップで実行されます。
16+
入力ガードレールは 3 ステップで実行されます:
1717

1818
1. まず、ガードレールはエージェントに渡されたものと同じ入力を受け取ります。
19-
2. 次に、ガードレール関数が実行され [`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput] を生成し、それが [`InputGuardrailResult`][agents.guardrail.InputGuardrailResult] でラップされます
20-
3. 最後に [`.tripwire_triggered`][agents.guardrail.GuardrailFunctionOutput.tripwire_triggered] が true かどうかを確認します。true の場合、[`InputGuardrailTripwireTriggered`][agents.exceptions.InputGuardrailTripwireTriggered] 例外が送出されるので、 ユーザー への適切な応答や例外処理を行えます
19+
2. 次に、ガードレール関数が実行され [`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput] を生成し、それが [`InputGuardrailResult`][agents.guardrail.InputGuardrailResult] にラップされます
20+
3. 最後に [.tripwire_triggered][agents.guardrail.GuardrailFunctionOutput.tripwire_triggered] が true かどうかを確認します。true の場合、[`InputGuardrailTripwireTriggered`][agents.exceptions.InputGuardrailTripwireTriggered] 例外が送出されるので、適切に ユーザー に応答したり例外を処理できます
2121

2222
!!! Note
2323

24-
Input ガードレールは ユーザー入力 に対して実行されることを想定しているため、エージェントのガードレールが実行されるのはそのエージェントが *最初* のエージェントである場合だけです。「なぜ `guardrails` プロパティがエージェントにあり、 `Runner.run` に渡さないのか?」と思うかもしれません。ガードレールは実際の エージェント に密接に関連する場合が多く、エージェントごとに異なるガードレールを実行するため、コードを同じ場所に置くことで可読性が向上するからです
24+
入力ガードレールは ユーザー 入力に対して実行されることを意図しているため、ガードレールは *最初* のエージェントでのみ実行されます。「なぜ `guardrails` プロパティがエージェントにあり、`Runner.run` に渡さないのか」と疑問に思うかもしれません。これは、ガードレールが実際の エージェント と密接に関連していることが多いからです。異なるエージェントには異なるガードレールを実行するため、コードを同じ場所に置くことで可読性が向上します
2525

26-
## Output ガードレール
26+
## 出力ガードレール
2727

28-
Output ガードレールは 3 つのステップで実行されます。
28+
出力ガードレールは 3 ステップで実行されます:
2929

30-
1. まず、ガードレールはエージェントに渡されたものと同じ入力を受け取ります
31-
2. 次に、ガードレール関数が実行され [`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput] を生成し、それが [`OutputGuardrailResult`][agents.guardrail.OutputGuardrailResult] でラップされます
32-
3. 最後に [`.tripwire_triggered`][agents.guardrail.GuardrailFunctionOutput.tripwire_triggered] が true かどうかを確認します。true の場合、[`OutputGuardrailTripwireTriggered`][agents.exceptions.OutputGuardrailTripwireTriggered] 例外が送出されるので、 ユーザー への適切な応答や例外処理を行えます
30+
1. まず、ガードレールはエージェントが生成した出力を受け取ります
31+
2. 次に、ガードレール関数が実行され [`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput] を生成し、それが [`OutputGuardrailResult`][agents.guardrail.OutputGuardrailResult] にラップされます
32+
3. 最後に [.tripwire_triggered][agents.guardrail.GuardrailFunctionOutput.tripwire_triggered] が true かどうかを確認します。true の場合、[`OutputGuardrailTripwireTriggered`][agents.exceptions.OutputGuardrailTripwireTriggered] 例外が送出されるので、適切に ユーザー に応答したり例外を処理できます
3333

3434
!!! Note
3535

36-
Output ガードレールは最終的なエージェント出力に対して実行されることを想定しているため、エージェントのガードレールが実行されるのはそのエージェントが *最後* のエージェントである場合だけです。Input ガードレール同様、ガードレールは実際の エージェント に密接に関連するため、コードを同じ場所に置くことで可読性が向上します。
36+
出力ガードレールは最終的なエージェント出力に対して実行されることを意図しているため、ガードレールは *最後* のエージェントでのみ実行されます。入力ガードレールの場合と同様、ガードレールが実際の エージェント と密接に関連していることが多いため、コードを同じ場所に置くことで可読性が向上します。
3737

38-
## トリップワイヤ
38+
## トリップワイヤー
3939

40-
入力または出力がガードレールに失敗した場合、ガードレールはトリップワイヤを用いてそれを通知できます。ガードレールがトリップワイヤを発火したことを検知すると、ただちに `{Input,Output}GuardrailTripwireTriggered` 例外を送出してエージェントの実行を停止します
40+
入力または出力がガードレールを通過できなかった場合、ガードレールはトリップワイヤーでそれを示すことができます。トリップワイヤーがトリガーされたガードレールを検知した時点で、直ちに `{Input,Output}GuardrailTripwireTriggered` 例外を送出し、エージェントの実行を停止します
4141

4242
## ガードレールの実装
4343

44-
入力を受け取り、[`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput] を返す関数を用意する必要があります。次の例では、内部で エージェント を実行してこれを行います。
44+
入力を受け取り、[`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput] を返す関数を提供する必要があります。この例では、内部で エージェント を実行してこれを行います。
4545

4646
```python
4747
from pydantic import BaseModel
@@ -94,12 +94,12 @@ async def main():
9494
print("Math homework guardrail tripped")
9595
```
9696

97-
1. この エージェント をガードレール関数内で使用します
98-
2. これはエージェントの入力 / コンテキストを受け取り、結果を返すガードレール関数です。
97+
1. このエージェントをガードレール関数内で使用します
98+
2. これはエージェントの入力/コンテキストを受け取り、結果を返すガードレール関数です。
9999
3. ガードレール結果に追加情報を含めることができます。
100100
4. これはワークフローを定義する実際のエージェントです。
101101

102-
Output ガードレールも同様です
102+
出力ガードレールも同様です
103103

104104
```python
105105
from pydantic import BaseModel
@@ -155,4 +155,4 @@ async def main():
155155
1. これは実際のエージェントの出力型です。
156156
2. これはガードレールの出力型です。
157157
3. これはエージェントの出力を受け取り、結果を返すガードレール関数です。
158-
4. これはワークフローを定義する実際のエージェントです。
158+
4. これはワークフローを定義する実際のエージェントです。

docs/ja/mcp.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ Agents SDK は MCP をサポートしており、これにより幅広い MCP
2323
たとえば、[公式 MCP filesystem サーバー](https://www.npmjs.com/package/@modelcontextprotocol/server-filesystem)を利用する場合は次のようになります。
2424

2525
```python
26+
from agents.run_context import RunContextWrapper
27+
2628
async with MCPServerStdio(
2729
params={
2830
"command": "npx",
2931
"args": ["-y", "@modelcontextprotocol/server-filesystem", samples_dir],
3032
}
3133
) as server:
32-
tools = await server.list_tools()
34+
# 注意:実際には通常は MCP サーバーをエージェントに追加し、
35+
# フレームワークがツール一覧の取得を自動的に処理するようにします。
36+
# list_tools() への直接呼び出しには run_context と agent パラメータが必要です。
37+
run_context = RunContextWrapper(context=None)
38+
agent = Agent(name="test", instructions="test")
39+
tools = await server.list_tools(run_context, agent)
3340
```
3441

3542
## MCP サーバーの利用

0 commit comments

Comments
 (0)