Commit graph

395 commits

Author SHA1 Message Date
pakrym-oai
f9763495b8
0.0.14 release (#635) 2025-04-30 08:15:35 -07:00
pakrym-oai
db0ee9d5a5
Update litellm version (#626)
Addresses https://github.com/openai/openai-agents-python/issues/614
2025-04-29 16:12:24 -07:00
N V J K Kartik
4187fba955
docs: add FutureAGI to tracing documentation (#592)
Hi Team! 

This PR adds FutureAGI to the tracing documentation as one of the
automatic tracing processors for OpenAI agents SDK.


![image](https://github.com/user-attachments/assets/4de3aadc-5efa-4712-8b02-decdedf8f8ef)
2025-04-25 12:10:59 -04:00
Stefano Baccianella
aa197e1e14
Make the TTS voices type exportable (#577)
When using the voice agent in typed code, it is suboptimal and error
prone to type the TTS voice variables in your code independently.

With this commit we are making the type exportable so that developers
can just use that and be future-proof.

Example of usage in code:

```
DEFAULT_TTS_VOICE: TTSModelSettings.TTSVoice = "alloy"

...

tts_voice: TTSModelSettings.TTSVoice = DEFAULT_TTS_VOICE 

...

output = await VoicePipeline(
  workflow=workflow,
  config=VoicePipelineConfig(
  tts_settings=TTSModelSettings(
    buffer_size=512,
    transform_data=transform_data,
    voice=tts_voice,
    instructions=tts_instructions,
  ))
).run(audio_input)
```

---------

Co-authored-by: Rohan Mehta <rm@openai.com>
2025-04-24 19:11:25 -04:00
Rohan Mehta
8fd7773a5e
Add usage to context in streaming (#595) 2025-04-24 18:20:35 -04:00
Rohan Mehta
3bbc7c48cb
v0.0.13 (#593) 2025-04-24 14:58:38 -04:00
Rohan Mehta
45eb41f1e6
More tests for cancelling streamed run (#590) 2025-04-24 14:45:03 -04:00
Daniele Morotti
e11b822d5f
Fix stream error using LiteLLM (#589)
In response to issue #587 , I implemented a solution to first check if
`refusal` and `usage` attributes exist in the `delta` object.

I added a unit test similar to `test_openai_chatcompletions_stream.py`.

Let me know if I should change something.

---------

Co-authored-by: Rohan Mehta <rm@openai.com>
2025-04-24 12:53:39 -04:00
Nathan Brake
af80e3a971
Prevent MCP ClientSession hang (#580)
Per
https://modelcontextprotocol.io/specification/draft/basic/lifecycle#timeouts

"Implementations SHOULD establish timeouts for all sent requests, to
prevent hung connections and resource exhaustion. When the request has
not received a success or error response within the timeout period, the
sender SHOULD issue a cancellation notification for that request and
stop waiting for a response.

SDKs and other middleware SHOULD allow these timeouts to be configured
on a per-request basis."

I picked 5 seconds since that's the default for SSE
2025-04-24 12:12:46 -04:00
Rohan Mehta
3755ea8658
Create to_json_dict for ModelSettings (#582)
Now that `ModelSettings` has `Reasoning`, a non-primitive object,
`dataclasses.as_dict()` wont work. It will raise an error when you try
to serialize (e.g. for tracing). This ensures the object is actually
serializable.
2025-04-23 20:39:07 -04:00
Andrew Han
a113fea0ee
Allow cancel out of the streaming result (#579)
Fix for #574 

@rm-openai I'm not sure how to add a test within the repo but I have
pasted a test script below that seems to work

```python
import asyncio
from openai.types.responses import ResponseTextDeltaEvent
from agents import Agent, Runner

async def main():
    agent = Agent(
        name="Joker",
        instructions="You are a helpful assistant.",
    )

    result = Runner.run_streamed(agent, input="Please tell me 5 jokes.")
    num_visible_event = 0
    async for event in result.stream_events():
        if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
            print(event.data.delta, end="", flush=True)
            num_visible_event += 1
            print(num_visible_event)
            if num_visible_event == 3:
                result.cancel()


if __name__ == "__main__":
    asyncio.run(main())
````
2025-04-23 19:51:10 -04:00
Kazuhiro Sera
178020ea33
Examples: Fix financial_research_agent instructions (#573) 2025-04-22 22:29:12 -04:00
Jonny Kalambay
111fc9ee66
Adding extra_headers parameters to ModelSettings (#550) 2025-04-22 22:26:47 -04:00
Rohan Mehta
83ce49ec7e
v0.0.12 (#564) 2025-04-21 23:06:09 -04:00
Steven Heidel
2bdf9b7b11
Pass through organization/project headers to tracing backend, fix speech_group enum (#562) 2025-04-21 16:59:46 -04:00
Rohan Mehta
942ba9840b
Docs and tests for litellm (#561) 2025-04-21 16:59:01 -04:00
Rohan Mehta
a0254b0b74
RFC: automatically use litellm if possible (#534)
## Summary
This replaces the default model provider with a `MultiProvider`, which
has the logic:
- if the model name starts with `openai/` or doesn't contain "/", use
OpenAI
- if the model name starts with `litellm/`, use LiteLLM to use the
appropriate model provider.

It's also extensible, so users can create their own mappings. I also
imagine that if we natively supported Anthropic/Gemini etc, we can add
it to MultiProvider to make it work.

The goal is that it should be really easy to use any model provider.
Today if you pass `model="gpt-4.1"`, it works great. But
`model="claude-sonnet-3.7"` doesn't. If we can make it that easy, it's a
win for devx.

I'm not entirely sure if this is a good idea - is it too magical? Is the
API too reliant on litellm? Comments welcome.

## Test plan

For now, the example. Will add unit tests if we agree its worth mergin.

---------

Co-authored-by: Steven Heidel <steven@heidel.ca>
2025-04-21 15:03:06 -04:00
Yuya Haruna
0a3dfa071a
Fix visualize graph filename to without extension. (#554)
Only the file name is needed since graphviz's `render()` automatically
adds the file extension.
Also, unnecessary .gv (.dot) files are output, so the `cleanup=True`
option has been modified to prevent them from being saved.

Here is a similar modification, but in a different content.
- https://github.com/openai/openai-agents-python/pull/451
2025-04-21 13:47:51 -04:00
Rohan Mehta
616d8e7f4b
Start and finish streaming trace in impl metod (#540)
Closes #435 and closes #538.

Unit tests.
2025-04-21 13:08:38 -04:00
Rohan Mehta
e3698f32b1
Enable non-strict output types (#539)
See #528, some folks are having issues because their output types are
not strict-compatible.

My approach was:
1. Create `AgentOutputSchemaBase`, which represents the base methods for
an output type - the json schema + validation
2. Make the existing `AgentOutputSchema` subclass
`AgentOutputSchemaBase`
3. Allow users to pass a `AgentOutputSchemaBase` to
`Agent(output_type=...)`
2025-04-21 11:58:36 -04:00
Rohan Mehta
4b8472da7e
Examples for image inputs (#553) 2025-04-21 11:14:25 -04:00
Kazuhiro Sera
5639606163
Docs: Switch to o3 model; exclude translated pages from search (#533)
This pull request introduces the following changes:
1. **Exclude translated pages from search**: I explored ways to make the
search plugin work with the i18n plugin, but it would require extensive
custom JavaScript hacks. So for now, I’m holding off on this work.
2. **Switch from GPT-4.1 to o3 for even better translation quality**:
While 4.1 performs well, o3 shows even greater quality for this task,
and there’s no reason to avoid using it.
2025-04-16 21:29:09 -04:00
Rohan Mehta
472e8c13bd
Docs for LiteLLM integration (#532) 2025-04-16 18:54:22 -04:00
Rohan Mehta
bd404e0f87
Litellm integration (#524)
litellm is a library that abstracts away details/differences for a lot
of model providers. Adding an extension, so that any provider can easily
be integrated.

---
[//]: # (BEGIN SAPLING FOOTER)
* #532
* __->__ #524
2025-04-16 18:48:41 -04:00
Rohan Mehta
0faadf7f7b
Show repo name/data in docs (#525)
Easy linking back to the repo, plus some social proof (stars/forks etc).
2025-04-16 14:27:23 -04:00
Rohan Mehta
65cae71b14
Extract chat completions streaming helpers (#523)
Small refactor.

---
[//]: # (BEGIN SAPLING FOOTER)
* #524
* __->__ #523
2025-04-15 18:42:09 -04:00
Rohan Mehta
80de53e879
Extract chat completions conversion code into helper (#522)
Small refactor for rest of stack.

---
[//]: # (BEGIN SAPLING FOOTER)
* #524
* #523
* __->__ #522
2025-04-15 18:31:17 -04:00
Rohan Mehta
ce1abe6006
Run CI on all commits, not just ones on main (#521)
Was not running on my stacked PRs.
2025-04-15 18:26:48 -04:00
Rohan Mehta
ca8e8bed5d
v0.0.11 (#520)
New release, to incorporate #519
2025-04-15 14:37:16 -04:00
Rohan Mehta
e625cb495e
Only include stream_options when streaming (#519)
Closes #518
2025-04-15 12:48:27 -04:00
Rohan Mehta
f329eef7e8
Examples and tests for previous_response_id (#512)
Examples + tests
2025-04-15 12:46:31 -04:00
RonaldChungHueyWu
b978b4382e
Support parallel_tool_calls=False for ChatCompletion API (#513)
The current ChatCompletion API supports only `parallel_tool_calls=True`
or `parallel_tool_calls=NOT_GIVEN`
This PR is to support setting `parallel_tool_calls=False`, a common
requirement in controlling agent tool use patterns (e.g. ensuring one
tool call at the time, to facilitate desired tool calling sequence).

I followed the merged
[PR#333](https://github.com/openai/openai-agents-python/pull/333) for
consistency.
2025-04-14 22:48:01 -04:00
Rohan Mehta
96a97af9be
v0.0.10 (#514) 2025-04-14 22:45:30 -04:00
Kazuhiro Sera
360f173b73
Evolve the doc translation workflow by using gpt-4.1 (#507)
This pull request enhances the document translation workflow by
switching to the new GPT-4.1 model. The generator script’s prompt now
includes a “workflow” section that guides the model to iterate
self-reviews on its outputs to autonomously achieve the highest quality.
This addition has noticeably improved the naturalness and consistency of
the wording in the translated outputs.
2025-04-14 22:04:07 -04:00
Rohan Mehta
92d6e3e66c
Previous response id (#509)
Allows passing in the previous_response_id to reduce sending the same
data again and again.

Test plan:
Examples. Adding tests in next PR shortly.

---
[//]: # (BEGIN SAPLING FOOTER)
* __->__ #509
* #508
2025-04-14 22:02:47 -04:00
Rohan Mehta
86ad99d798
Move dev-only deps to dev section (#506)
These two deps are only used in development/examples
2025-04-14 21:59:41 -04:00
Rohan Mehta
d6f5190d53
Replace referencable_id with response_id (#508)
Minor change - naming. So that it doesn't pollute the next PR.

---
[//]: # (BEGIN SAPLING FOOTER)
* #509
* __->__ #508
2025-04-14 21:37:18 -04:00
Daniele Morotti
e8f14da473
Fix type annotations examples (#496)
I fixed the type annotations errors for pydantic objects in some
examples as noted in #490 .

When running `make lint` the following error occurs "UP007 Use `X | Y`
for type annotations". If you know how to ignore it I will be happy to
edit the pull request, thanks.
2025-04-14 13:28:43 -04:00
Rohan Mehta
36f5b72449
Don't run tracing shutdown behavior if disabled (#503)
Towards #502
2025-04-14 12:46:00 -04:00
Rohan Mehta
5727a1c73a
Example for streaming guardrails (#505)
An example for the question in the issue attached - how to run
guardrails during streaming.

Towards #495.
2025-04-14 12:40:41 -04:00
Rohan Mehta
5183f528f4
Add docs for customizng agent-as-tool (#504)
Co-authored-by: pakrym-oai <pakrym@openai.com>
2025-04-14 12:40:32 -04:00
Kazuhiro Sera
25f97f979b
Fix typos and misspellings (#486)
Detected typos using typos-cli (https://crates.io/crates/typos-cli). It
detected "occured" in a string constant "handoff_occured" too, but I
didn't change the part this time because it could be a minor breaking
change.


Full outputs:
```
% typos .
error: `Supresses` should be `Suppresses`
  --> ./src/agents/function_schema.py:134:7
    |
134 |     # Supresses warnings about missing annotations for params
    |       ^^^^^^^^^
    |
error: `typ` should be `typo`, `type`
  --> ./src/agents/strict_schema.py:51:5
   |
51 |     typ = json_schema.get("type")
   |     ^^^
   |
error: `typ` should be `typo`, `type`
  --> ./src/agents/strict_schema.py:52:8
   |
52 |     if typ == "object" and "additionalProperties" not in json_schema:
   |        ^^^
   |
error: `typ` should be `typo`, `type`
  --> ./src/agents/strict_schema.py:55:9
   |
55 |         typ == "object"
   |         ^^^
   |
error: `occured` should be `occurred`
  --> ./src/agents/stream_events.py:34:18
   |
34 |         "handoff_occured",
   |                  ^^^^^^^
   |
error: `occured` should be `occurred`
  --> ./src/agents/_run_impl.py:723:69
    |
723 |                 event = RunItemStreamEvent(item=item, name="handoff_occured")
    |                                                                     ^^^^^^^
    |
error: `desitnation` should be `destination`
  --> ./src/agents/tracing/span_data.py:171:25
    |
171 |     Includes source and desitnation agents.
    |                         ^^^^^^^^^^^
    |
error: `exmaples` should be `examples`
  --> ./docs/scripts/translate_docs.py:71:145
   |
71 |         "* The term 'examples' must be code examples when the page mentions the code examples in the repo, it can be translated as either 'code exmaples' or 'sample code'.",
   |                                                                                                                                                 ^^^^^^^^
   |
error: `structed` should be `structured`
  --> ./tests/test_agent_hooks.py:227:16
    |
227 | async def test_structed_output_non_streamed_agent_hooks():
    |                ^^^^^^^^
    |
error: `structed` should be `structured`
  --> ./tests/test_agent_hooks.py:298:16
    |
298 | async def test_structed_output_streamed_agent_hooks():
    |                ^^^^^^^^
    |
```
2025-04-14 10:37:13 -04:00
Daniele Morotti
e04d87cb1f
Add extra request parameters extra_query and extra_body (#500)
Added the possibility to pass `extra_query` and `extra_body` parameters
when sending a request.
In this implementation I added the attributes to `ModelSettings` as
suggested by @rm-openai in #487 .

I'll be happy to add some tests if you have any suggestions.
2025-04-14 10:37:00 -04:00
LouisShark
d0693a192e
fix: ensure metadata is non-null in response handling (#483)
ensure metadata is non-null in response handling
2025-04-11 18:20:59 -04:00
Kazuhiro Sera
e115d5a459
Add model_settings guide to models document page (#484)
This is a pretty minor improvement to the docs: `model_settings`
parameter is only mentioned on the agent doc page, but first-time
visitors may want to know it’s also available on the models page.
2025-04-11 13:27:01 -04:00
Kazuhiro Sera
68c725f942
Improve translation pipeline details (#475)
This pull request improves the translation pipeline, which was
introduced by #460. Now the document generation works pretty well with
gpt-4o model.
2025-04-10 16:54:05 -04:00
Ddper
8ded8a9981
add overwrite mechanism for stream_options (#465)
fix issue https://github.com/openai/openai-agents-python/issues/442

below is an example to overwrite include_usage


```
    result = Runner.run_streamed(
        agent,
        "Write a haiku about recursion in programming.",
        run_config=RunConfig(
            model_provider=CUSTOM_MODEL_PROVIDER,
            model_settings=ModelSettings(include_usage=True)
        ),
    )
```
2025-04-10 16:54:00 -04:00
Dmitry Pimenov
84fb734ba0
Adding scope and span_data doc strings (#463)
Built docs and tested outputs locally
2025-04-09 14:59:07 -04:00
nikkie
d089886f01
examples(research_bot): Add space to INSTRUCTIONS (#439)
Thanks to awesome example `research_bot`

Fix andproduce and goodgrammar (and so on)

```python
>>> from examples.research_bot.agents import search_agent
>>> print(search_agent.INSTRUCTIONS)
You are a research assistant. Given a search term, you search the web for that term andproduce a concise summary of the results. The summary must 2-3 paragraphs and less than 300words. Capture the main points. Write succinctly, no need to have complete sentences or goodgrammar. This will be consumed by someone synthesizing a report, so its vital you capture theessence and ignore any fluff. Do not include any additional commentary other than the summaryitself.
```
2025-04-08 14:01:09 -04:00
nikkie
ccff74dcfa
docs: Make default model clear (#457)
close https://github.com/openai/openai-agents-python/issues/440
2025-04-08 11:47:23 -04:00