Commit graph

417 commits

Author SHA1 Message Date
Rehan Ul Haq
16fb29c1f0
Fix typo in assertion message for handoff function (#780)
### Overview

This PR fixes a typo in the assert statement within the `handoff`
function in `handoffs.py`, changing `'on_input'` to `'on_handoff`' for
accuracy and clarity.

### Changes

- Corrected the word “on_input” to “on_handoff” in the docstring.

### Motivation

Clear and correct documentation improves code readability and reduces
confusion for users and contributors.

### Checklist

- [x] I have reviewed the docstring after making the change.
- [x] No functionality is affected.
- [x] The change follows the repository’s contribution guidelines.
2025-05-30 11:53:15 -04:00
rob-openai
b699d9a533
Small fix for litellm model (#789)
Small fix:

Removing `import litellm.types` as its outside the try except block for
importing litellm so the import error message isn't displayed, and the
line actually isn't needed. I was reproducing a GitHub issue and came
across this in the process.
2025-05-30 10:32:25 -04:00
Sarmad Gulzar
47fa8e87b1
Fixed Python syntax (#665) 2025-05-29 17:24:31 -04:00
Daniele Morotti
71968625cc
Added RunErrorDetails object for MaxTurnsExceeded exception (#743)
### Summary

Introduced the `RunErrorDetails` object to get partial results from a
run interrupted by `MaxTurnsExceeded` exception. In this proposal the
`RunErrorDetails` object contains all the fields from `RunResult` with
`final_output` set to `None` and `output_guardrail_results` set to an
empty list. We can decide to return less information.

@rm-openai At the moment the exception doesn't return the
`RunErrorDetails` object for the streaming mode. Do you have any
suggestions on how to deal with it? In the `_check_errors` function of
`agents/result.py` file.

### Test plan

I have not implemented any tests currently, but if needed I can
implement a basic test to retrieve partial data.

### Issue number

This PR is an attempt to solve issue #719 

### Checks

- [ ] I've added new tests (if relevant)
- [ ] I've added/updated the relevant documentation
- [ ] I've run `make lint` and `make format`
- [ ] I've made sure tests pass
2025-05-29 16:11:33 -04:00
siddharth Sambharia
d46e2ec35b
Add Portkey AI as a tracing provider (#785)
This PR adds Portkey AI as a tracing provider. Portkey helps you take
your OpenAI agents from prototype to production.

Portkey turns your experimental OpenAI Agents into production-ready
systems by providing:

- Complete observability of every agent step, tool use, and interaction
- Built-in reliability with fallbacks, retries, and load balancing
- Cost tracking and optimization to manage your AI spend
- Access to 1600+ LLMs through a single integration
- Guardrails to keep agent behavior safe and compliant
- Version-controlled prompts for consistent agent performance


Towards #786
2025-05-29 11:43:25 -04:00
Rohan Mehta
6e078bf7a9
Fix Gemini API content filter handling (#746)
## Summary
- avoid AttributeError when Gemini API returns `None` for chat message
- return empty output if message is filtered
- add regression test

## Testing
- `make format`
- `make lint`
- `make mypy`
- `make tests`

Towards #744
2025-05-23 13:00:30 -04:00
Rohan Mehta
a96108e279
Update MCP and tool docs (#736)
## Summary
- mention MCPServerStreamableHttp in MCP server docs
- document CodeInterpreterTool, HostedMCPTool, ImageGenerationTool and
LocalShellTool
- update Japanese translations
2025-05-23 13:00:21 -04:00
Rohan Mehta
db462e32a3
Fix visualization recursion with cycle detection (#737)
## Summary
- avoid infinite recursion in visualization by tracking visited agents
- test cycle detection in graph utility

## Testing
- `make mypy`
- `make tests` 

Resolves #668
2025-05-23 13:00:10 -04:00
Andrew Han
1364f4408e
fix Gemini token validation issue with LiteLLM (#735)
Fix for #734
2025-05-21 17:59:47 -04:00
Rohan Mehta
1992be3e8d
v0.0.16 (#733) 2025-05-21 16:06:13 -04:00
Rohan Mehta
079764f0ab
Add support for local shell, image generator, code interpreter tools (#732) 2025-05-21 15:26:22 -04:00
Rohan Mehta
9fa5c39d69
Hosted MCP support (#731)
---
[//]: # (BEGIN SAPLING FOOTER)
* #732
* __->__ #731
2025-05-21 15:21:37 -04:00
Rohan Mehta
ce2e2a4571
Upgrade openAI sdk version (#730)
---
[//]: # (BEGIN SAPLING FOOTER)
* #732
* #731
* __->__ #730
2025-05-21 15:17:58 -04:00
WJPBProjects
466b44df18
Dev/add usage details to Usage class (#726)
PR to enhance the `Usage` object and related logic, to support more
granular token accounting, matching the details available in the [OpenAI
Responses API](https://platform.openai.com/docs/api-reference/responses)
. Specifically, it:

- Adds `input_tokens_details` and `output_tokens_details` fields to the
`Usage` dataclass, storing detailed token breakdowns (e.g.,
`cached_tokens`, `reasoning_tokens`).
- Flows this change through
- Updates and extends tests to match
- Adds a test for the Usage.add method

### Motivation
- Aligns the SDK’s usage with the latest OpenAI responses API Usage
object
- Supports downstream use cases that require fine-grained token usage
data (e.g., billing, analytics, optimization) requested by startups

---------

Co-authored-by: Wulfie Bain <wulfie@openai.com>
2025-05-20 18:23:56 +01:00
franz101
428c9a65bf
Add Galileo to external tracing processors list (#662) 2025-05-19 15:41:11 -04:00
Daniele Morotti
003cbfe5f5
Added mcp 'instructions' attribute to the server (#706)
Added the `instructions` attribute to the MCP servers to solve #704 .

Let me know if you want to add an example to the documentation.
2025-05-18 13:25:08 -04:00
Dominik Kundel
c282324d95
Create AGENTS.md (#707)
Adding an AGENTS.md file for Codex use
2025-05-18 13:24:24 -04:00
Rohan Mehta
5fe096df67
v0.0.15 (#701) 2025-05-15 18:41:00 -04:00
Akshit97
1847008e0f
feat: Streamable HTTP support (#643)
Co-authored-by: aagarwal25 <akshit_agarwal@intuit.com>
2025-05-14 14:45:14 -04:00
leohpark
02b6e7013c
Update search_agent.py (#677)
Added missing word "be" in prompt instructions.

This is unlikely to change the agent functionality in most cases, but
optimal clarity in prompt language is a best practice.
2025-05-14 12:37:06 -04:00
Ashok Saravanan
1994f9d4c4
feat: pass extra_body through to LiteLLM acompletion (#638)
**Purpose**  
Allow arbitrary `extra_body` parameters (e.g. `cached_content`) to be
forwarded into the LiteLLM call. Useful for context caching in Gemini
models
([docs](https://ai.google.dev/gemini-api/docs/caching?lang=python)).

**Example usage**  
```python
import os
from agents import Agent, ModelSettings
from agents.extensions.models.litellm_model import LitellmModel

cache_name = "cachedContents/34jopukfx5di"  # previously stored context

gemini_model = LitellmModel(
    model="gemini/gemini-1.5-flash-002",
    api_key=os.getenv("GOOGLE_API_KEY")
)

agent = Agent(
    name="Cached Gemini Agent",
    model=gemini_model,
    model_settings=ModelSettings(
        extra_body={"cached_content": cache_name}
    )
)
2025-05-14 12:34:27 -04:00
Daniele Morotti
2c46dae377
Fixed a bug for "detail" attribute in input image (#685)
When an input image is given as input, the code tries to access the
'detail' key, that may not be present as noted in #159.

With this pull request, now it tries to access the key, otherwise set
the value to `None`.
@pakrym-oai  or @rm-openai let me know if you want any changes.
2025-05-14 11:31:42 -04:00
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