Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
db462e3
Fix visualization recursion with cycle detection (#737)
rm-openai May 23, 2025
a96108e
Update MCP and tool docs (#736)
rm-openai May 23, 2025
6e078bf
Fix Gemini API content filter handling (#746)
rm-openai May 23, 2025
d46e2ec
Add Portkey AI as a tracing provider (#785)
siddharthsambharia-portkey May 29, 2025
7196862
Added RunErrorDetails object for MaxTurnsExceeded exception (#743)
DanieleMorotti May 29, 2025
47fa8e8
Fixed Python syntax (#665)
sarmadgulzar May 29, 2025
b699d9a
Small fix for litellm model (#789)
robtinn May 30, 2025
16fb29c
Fix typo in assertion message for handoff function (#780)
Rehan-Ul-Haq May 30, 2025
0a28d71
Fix typo: Replace 'two' with 'three' in /docs/mcp.md (#757)
luochang212 May 30, 2025
ad80f78
Update input_guardrails.py (#774)
venkatnaveen7 May 30, 2025
6438350
docs: fix typo in docstring for is_strict_json_schema method (#775)
Rehan-Ul-Haq May 30, 2025
cfe9099
Add comment to handoff_occured misspelling (#792)
rm-openai May 30, 2025
3e7b286
Fix #777 by handling MCPCall events in RunImpl (#799)
seratch Jun 2, 2025
775d3e2
Ensure item.model_dump only contains JSON serializable types (#801)
westhood Jun 2, 2025
d4c7a23
Don't cache agent tools during a run (#803)
rm-openai Jun 2, 2025
995af4d
Only start tracing worker thread on first span/trace (#804)
rm-openai Jun 2, 2025
4046fcb
Add is_enabled to FunctionTool (#808)
rm-openai Jun 3, 2025
204bec1
v0.0.17 (#809)
rm-openai Jun 4, 2025
4a529e6
Add REPL run_demo_loop helper (#811)
rm-openai Jun 4, 2025
05db7a6
Crosslink to js/ts (#815)
rm-openai Jun 4, 2025
5c7c678
Add release documentation (#814)
rm-openai Jun 4, 2025
c98e234
Fix handoff transfer message JSON (#818)
jhills20 Jun 9, 2025
dcb88e6
docs: custom output extraction (#817)
jleguina Jun 9, 2025
8dfd6ff
Added support for passing tool_call_id via the RunContextWrapper (#766)
niv-hertz Jun 9, 2025
0eee6b8
Allow arbitrary kwargs in model (#842)
rm-openai Jun 10, 2025
6d2806f
Fix function_schema name override bug (#872)
rm-openai Jun 16, 2025
281a7b2
adopted float instead of timedelta for timeout parameters (#874)
DanieleMorotti Jun 16, 2025
2b9b8f7
Prompts support (#876)
rm-openai Jun 16, 2025
901d2ac
v0.0.18 (#878)
rm-openai Jun 16, 2025
0cf503e
Allow replacing AgentRunner and TraceProvider (#720)
pakrym-oai Jun 18, 2025
91c62c1
Prepare 0.0.19 release (#895)
pakrym-oai Jun 18, 2025
c1466c6
Add is_enabled to handoffs (#925)
rm-openai Jun 24, 2025
0f21c8a
Removed lines to avoid duplicate output in REPL utility (#928)
DanieleMorotti Jun 24, 2025
d88bf14
Bugfix | Fixed a bug when calling reasoning models with `store=False`…
niv-hertz Jun 24, 2025
3e5f3c0
Point CLAUDE.md to AGENTS.md (#930)
rm-openai Jun 24, 2025
421693a
Fix #890 by adjusting the guardrail document page (#903)
seratch Jun 24, 2025
7665dd1
Add exempt-issue-labels to the issue triage GH Action job (#936)
seratch Jun 25, 2025
c2005f8
Remove duplicate entry from `__init__.py` (#897)
Lightblues Jun 25, 2025
94f8035
Fix #604 Chat Completion model raises runtime error when response.cho…
seratch Jun 25, 2025
653abc5
Fix #892 by adding proper tool description in context.md (#937)
Abbas-Asad Jun 25, 2025
c1cb7ce
Duplicate Classifier in pyproject.toml (#951)
DanielHashmi Jun 27, 2025
a6580a5
fix: add ensure_ascii=False to json.dumps for correct Unicode output …
KatHaruto Jun 27, 2025
271a1a4
Add uv as an alternative Python environment setup option for issue #8…
Sucran Jun 27, 2025
816b770
Fix and Document `parallel_tool_calls` Attribute in ModelSettings (#763)
Rehan-Ul-Haq Jun 27, 2025
0475450
replace .py file with .ipynb for Jupyter example (#262)
ccmien Jun 27, 2025
4450339
feat: add MCP tool filtering support (#861)
devtalker Jun 27, 2025
25db658
Tweak in pyproject.toml (#952)
seratch Jun 27, 2025
c772205
Fix incorrect argument description in `on_trace_end` docstring (#958)
shirazkk Jun 27, 2025
381e90d
Fix #944 by updating the models document page to cover extra_args (#950)
seratch Jun 27, 2025
017ad69
Annotating the openai.Omit type so that ModelSettings can be serializ…
tconley1428 Jun 27, 2025
27912d4
Import Path Inconsistency (#960)
DanielHashmi Jun 27, 2025
fcafae1
Add reasoning content - fix on #494 (#871)
axion66 Jun 27, 2025
8664271
Add safety check handling for ComputerTool (#923)
rm-openai Jun 27, 2025
18cb55e
v0.1.0 (#963)
rm-openai Jun 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
days-before-pr-stale: 10
days-before-pr-close: 7
stale-pr-label: "stale"
exempt-issue-labels: "skip-stale"
stale-pr-message: "This PR is stale because it has been open for 10 days with no activity."
close-pr-message: "This PR was closed because it has been inactive for 7 days since being marked as stale."
repo-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Welcome to the OpenAI Agents SDK repository. This file contains the main points

Coverage can be generated with `make coverage`.

All python commands should be run via `uv run python ...`

## Snapshot tests

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

- Tests covering new behaviour.
- Consistent style: code formatted with `ruff format`, imports sorted, and type hints passing `mypy`.
- Consistent style: code formatted with `uv run ruff format`, imports sorted, and type hints passing `uv run mypy .`.
- Clear documentation for any public API changes.
- Clean history and a helpful PR description.
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Read the AGENTS.md file for instructions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ The OpenAI Agents SDK is a lightweight yet powerful framework for building multi

<img src="https://cdn.openai.com/API/docs/images/orchestration.png" alt="Image of the Agents Tracing UI" style="max-height: 803px;">

> [!NOTE]
> Looking for the JavaScript/TypeScript version? Check out [Agents SDK JS/TS](https://github.com/openai/openai-agents-js).

### Core concepts:

1. [**Agents**](https://openai.github.io/openai-agents-python/agents): LLMs configured with instructions, tools, guardrails, and handoffs
Expand All @@ -17,14 +20,21 @@ Explore the [examples](examples) directory to see the SDK in action, and read ou

1. Set up your Python environment

```
- Option A: Using venv (traditional method)
```bash
python -m venv env
source env/bin/activate
source env/bin/activate # On Windows: env\Scripts\activate
```

- Option B: Using uv (recommended)
```bash
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```

2. Install Agents SDK

```
```bash
pip install openai-agents
```

Expand All @@ -47,7 +57,7 @@ print(result.final_output)

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

(_For Jupyter notebook users, see [hello_world_jupyter.py](examples/basic/hello_world_jupyter.py)_)
(_For Jupyter notebook users, see [hello_world_jupyter.ipynb](examples/basic/hello_world_jupyter.ipynb)_)

## Handoffs example

Expand Down
3 changes: 2 additions & 1 deletion docs/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class UserInfo: # (1)!

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

async def main():
user_info = UserInfo(name="John", uid=123)
Expand Down
2 changes: 1 addition & 1 deletion docs/guardrails.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Input guardrails run in 3 steps:

Output guardrails run in 3 steps:

1. First, the guardrail receives the same input passed to the agent.
1. First, the guardrail receives the output produced by the agent.
2. Next, the guardrail function runs to produce a [`GuardrailFunctionOutput`][agents.guardrail.GuardrailFunctionOutput], which is then wrapped in an [`OutputGuardrailResult`][agents.guardrail.OutputGuardrailResult]
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.

Expand Down
44 changes: 22 additions & 22 deletions docs/ja/guardrails.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ search:
---
# ガードレール

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

ガードレールには 2 種類あります
ガードレールには 2 種類あります:

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

## Input ガードレール
## 入力ガードレール

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

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

!!! Note

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

## Output ガードレール
## 出力ガードレール

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

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

!!! Note

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

## トリップワイヤ
## トリップワイヤー

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

## ガードレールの実装

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

```python
from pydantic import BaseModel
Expand Down Expand Up @@ -94,12 +94,12 @@ async def main():
print("Math homework guardrail tripped")
```

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

Output ガードレールも同様です
出力ガードレールも同様です

```python
from pydantic import BaseModel
Expand Down Expand Up @@ -155,4 +155,4 @@ async def main():
1. これは実際のエージェントの出力型です。
2. これはガードレールの出力型です。
3. これはエージェントの出力を受け取り、結果を返すガードレール関数です。
4. これはワークフローを定義する実際のエージェントです。
4. これはワークフローを定義する実際のエージェントです。
18 changes: 13 additions & 5 deletions docs/ja/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@ Agents SDK は MCP をサポートしており、これにより幅広い MCP

## MCP サーバー

現在、MCP 仕様では使用するトランスポート方式に基づき 2 種類のサーバーが定義されています。
現在、MCP 仕様では使用するトランスポート方式に基づき 3 種類のサーバーが定義されています。

1. **stdio** サーバー: アプリケーションのサブプロセスとして実行されます。ローカルで動かすイメージです。
1. **stdio** サーバー: アプリケーションのサブプロセスとして実行されます。ローカルで動かすイメージです。
2. **HTTP over SSE** サーバー: リモートで動作し、 URL 経由で接続します。
3. **Streamable HTTP** サーバー: MCP 仕様に定義された Streamable HTTP トランスポートを使用してリモートで動作します。

これらのサーバーへは [`MCPServerStdio`][agents.mcp.server.MCPServerStdio][`MCPServerSse`][agents.mcp.server.MCPServerSse] クラスを使用して接続できます。
これらのサーバーへは [`MCPServerStdio`][agents.mcp.server.MCPServerStdio][`MCPServerSse`][agents.mcp.server.MCPServerSse]、[`MCPServerStreamableHttp`][agents.mcp.server.MCPServerStreamableHttp] クラスを使用して接続できます。

たとえば、[公式 MCP filesystem サーバー](https://www.npmjs.com/package/@modelcontextprotocol/server-filesystem)を利用する場合は次のようになります。

```python
from agents.run_context import RunContextWrapper

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

## MCP サーバーの利用
Expand All @@ -46,7 +54,7 @@ agent=Agent(

## キャッシュ

エージェントが実行されるたびに、MCP サーバーへ `list_tools()` が呼び出されます。サーバーがリモートの場合は特にレイテンシが発生します。ツール一覧を自動でキャッシュしたい場合は、[`MCPServerStdio`][agents.mcp.server.MCPServerStdio][`MCPServerSse`][agents.mcp.server.MCPServerSse] の両方に `cache_tools_list=True` を渡してください。ツール一覧が変更されないと確信できる場合のみ使用してください。
エージェントが実行されるたびに、MCP サーバーへ `list_tools()` が呼び出されます。サーバーがリモートの場合は特にレイテンシが発生します。ツール一覧を自動でキャッシュしたい場合は、[`MCPServerStdio`][agents.mcp.server.MCPServerStdio][`MCPServerSse`][agents.mcp.server.MCPServerSse]、[`MCPServerStreamableHttp`][agents.mcp.server.MCPServerStreamableHttp] の各クラスに `cache_tools_list=True` を渡してください。ツール一覧が変更されないと確信できる場合のみ使用してください。

キャッシュを無効化したい場合は、サーバーで `invalidate_tools_cache()` を呼び出します。

Expand Down
Loading