Skip to content

Commit 6df3f88

Browse files
authored
Merge branch 'openai:main' into fix/enable-unicode-json-output
2 parents cb0a285 + 8dfd6ff commit 6df3f88

Some content is hidden

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

47 files changed

+761
-130
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ The OpenAI Agents SDK is a lightweight yet powerful framework for building multi
44

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

7+
> [!NOTE]
8+
> Looking for the JavaScript/TypeScript version? Check out [Agents SDK JS/TS](https://github.com/openai/openai-agents-js).
9+
710
### Core concepts:
811

912
1. [**Agents**](https://openai.github.io/openai-agents-python/agents): LLMs configured with instructions, tools, guardrails, and handoffs

docs/ja/repl.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
search:
3+
exclude: true
4+
---
5+
# REPL ユーティリティ
6+
7+
`run_demo_loop` を使うと、ターミナルから手軽にエージェントを試せます。
8+
9+
```python
10+
import asyncio
11+
from agents import Agent, run_demo_loop
12+
13+
async def main() -> None:
14+
agent = Agent(name="Assistant", instructions="あなたは親切なアシスタントです")
15+
await run_demo_loop(agent)
16+
17+
if __name__ == "__main__":
18+
asyncio.run(main())
19+
```
20+
21+
`run_demo_loop` は入力を繰り返し受け取り、会話履歴を保持したままエージェントを実行します。既定ではストリーミング出力を表示します。
22+
`quit` または `exit` と入力するか `Ctrl-D` を押すと終了します。

docs/ja/tracing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ async def main():
119119
- [Comet Opik](https://www.comet.com/docs/opik/tracing/integrations/openai_agents)
120120
- [Langfuse](https://langfuse.com/docs/integrations/openaiagentssdk/openai-agents)
121121
- [Langtrace](https://docs.langtrace.ai/supported-integrations/llm-frameworks/openai-agents-sdk)
122-
- [Okahu‑Monocle](https://github.com/monocle2ai/monocle)
122+
- [Okahu‑Monocle](https://github.com/monocle2ai/monocle)
123+
- [Portkey AI](https://portkey.ai/docs/integrations/agents/openai-agents)

docs/mcp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Agents SDK has support for MCP. This enables you to use a wide range of MCP
88

99
## MCP servers
1010

11-
Currently, the MCP spec defines two kinds of servers, based on the transport mechanism they use:
11+
Currently, the MCP spec defines three kinds of servers, based on the transport mechanism they use:
1212

1313
1. **stdio** servers run as a subprocess of your application. You can think of them as running "locally".
1414
2. **HTTP over SSE** servers run remotely. You connect to them via a URL.

docs/ref/repl.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# `repl`
2+
3+
::: agents.repl
4+
options:
5+
members:
6+
- run_demo_loop

docs/release.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Release process
2+
3+
The project follows a slightly modified version of semantic versioning using the form `0.Y.Z`. The leading `0` indicates the SDK is still evolving rapidly. Increment the components as follows:
4+
5+
## Minor (`Y`) versions
6+
7+
We will increase minor versions `Y` for **breaking changes** to any public interfaces that are not marked as beta. For example, going from `0.0.x` to `0.1.x` might include breaking changes.
8+
9+
If you don't want breaking changes, we recommend pinning to `0.0.x` versions in your project.
10+
11+
## Patch (`Z`) versions
12+
13+
We will increment `Z` for non-breaking changes:
14+
15+
- Bug fixes
16+
- New features
17+
- Changes to private interfaces
18+
- Updates to beta features

docs/repl.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# REPL utility
2+
3+
The SDK provides `run_demo_loop` for quick interactive testing.
4+
5+
```python
6+
import asyncio
7+
from agents import Agent, run_demo_loop
8+
9+
async def main() -> None:
10+
agent = Agent(name="Assistant", instructions="You are a helpful assistant.")
11+
await run_demo_loop(agent)
12+
13+
if __name__ == "__main__":
14+
asyncio.run(main())
15+
```
16+
17+
`run_demo_loop` prompts for user input in a loop, keeping the conversation
18+
history between turns. By default it streams model output as it is produced.
19+
Type `quit` or `exit` (or press `Ctrl-D`) to leave the loop.

docs/tools.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ The `agent.as_tool` function is a convenience method to make it easy to turn an
270270
```python
271271
@function_tool
272272
async def run_my_agent() -> str:
273-
"""A tool that runs the agent with custom configs".
273+
"""A tool that runs the agent with custom configs"""
274274

275275
agent = Agent(name="My agent", instructions="...")
276276

@@ -284,6 +284,33 @@ async def run_my_agent() -> str:
284284
return str(result.final_output)
285285
```
286286

287+
### Custom output extraction
288+
289+
In certain cases, you might want to modify the output of the tool-agents before returning it to the central agent. This may be useful if you want to:
290+
291+
- Extract a specific piece of information (e.g., a JSON payload) from the sub-agent's chat history.
292+
- Convert or reformat the agent’s final answer (e.g., transform Markdown into plain text or CSV).
293+
- Validate the output or provide a fallback value when the agent’s response is missing or malformed.
294+
295+
You can do this by supplying the `custom_output_extractor` argument to the `as_tool` method:
296+
297+
```python
298+
async def extract_json_payload(run_result: RunResult) -> str:
299+
# Scan the agent’s outputs in reverse order until we find a JSON-like message from a tool call.
300+
for item in reversed(run_result.new_items):
301+
if isinstance(item, ToolCallOutputItem) and item.output.strip().startswith("{"):
302+
return item.output.strip()
303+
# Fallback to an empty JSON object if nothing was found
304+
return "{}"
305+
306+
307+
json_tool = data_agent.as_tool(
308+
tool_name="get_data_json",
309+
tool_description="Run the data agent and return only its JSON payload",
310+
custom_output_extractor=extract_json_payload,
311+
)
312+
```
313+
287314
## Handling errors in function tools
288315

289316
When you create a function tool via `@function_tool`, you can pass a `failure_error_function`. This is a function that provides an error response to the LLM in case the tool call crashes.

docs/tracing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ To customize this default setup, to send traces to alternative or additional bac
116116
- [Langtrace](https://docs.langtrace.ai/supported-integrations/llm-frameworks/openai-agents-sdk)
117117
- [Okahu-Monocle](https://github.com/monocle2ai/monocle)
118118
- [Galileo](https://v2docs.galileo.ai/integrations/openai-agent-integration#openai-agent-integration)
119+
- [Portkey AI](https://portkey.ai/docs/integrations/agents/openai-agents)

examples/agent_patterns/input_guardrails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Guardrails are checks that run in parallel to the agent's execution.
2121
They can be used to do things like:
2222
- Check if input messages are off-topic
23-
- Check that output messages don't violate any policies
23+
- Check that input messages don't violate any policies
2424
- Take over control of the agent's execution if an unexpected input is detected
2525
2626
In this example, we'll setup an input guardrail that trips if the user is asking to do math homework.

0 commit comments

Comments
 (0)