I replaced the `timedelta` parameters for MCP timeouts with `float`
values, addressing issue #845 .
Given that the MCP official repository has incorporated these changes in
[this PR](https://github.com/modelcontextprotocol/python-sdk/pull/941),
updating the MCP version in openai-agents and specifying the timeouts as
floats should be enough.
This PR fixes issue:
https://github.com/openai/openai-agents-python/issues/559
By adding the tool_call_id to the RunContextWrapper prior to calling
tools. This gives the ability to access the tool_call_id in the
implementation of the tool.
In deep agent workflows, each sub‐agent automatically performs an LLM
step to summarize its tool calls before returning to its parent. This
leads to:
1. Excessive latency: every nested agent invokes the LLM, compounding
delays.
2. Loss of raw tool data: summaries may strip out details the top‐level
agent needs.
We discovered that `Agent.as_tool(...)` already accepts an
(undocumented) `custom_output_extractor` parameter. By providing a
callback, a parent agent can override what the sub‐agent returns e.g.
hand back raw tool outputs or a custom slice so that only the final
agent does summarization.
---
This PR adds a “Custom output extraction” section to the Markdown docs
under “Agents as tools,” with a minimal code example.
### Summary:
Allows a user to do `function_tool(is_enabled=<some_callable>)`; the
callable is called when the agent runs.
This allows you to dynamically enable/disable a tool based on the
context/env.
The meta-goal is to allow `Agent` to be effectively immutable. That
enables some nice things down the line, and this allows you to
dynamically modify the tools list without mutating the agent.
### Test Plan:
Unit tests
Closes#796. Shouldn't start a busy waiting thread if there aren't any
traces.
Test plan
```
import threading
assert threading.active_count() == 1
import agents
assert threading.active_count() == 1
```
### Summary:
Towards #767. We were caching the list of tools for an agent, so if you
did `agent.tools.append(...)` from a tool call, the next call to the
model wouldn't include the new tool. THis is a bug.
### Test Plan:
Unit tests. Note that now MCP tools are listed each time the agent runs
(users can still cache the `list_tools` however).
The EmbeddedResource from MCP tool call contains a field with type
AnyUrl that is not JSON-serializable. To avoid this exception, use
item.model_dump(mode="json") to ensure a JSON-serializable return value.
This pull request resolves#777; If you think we should introduce a new
item type for MCP call output, please let me know. As other hosted tools
use this event, I believe using the same should be good to go tho.
### Overview
This PR fixes a small typo in the docstring of the
`is_strict_json_schema` abstract method of the `AgentOutputSchemaBase`
class in `agent_output.py`.
### Changes
- Corrected the word “valis” to “valid” 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.
The documentation in `docs/mcp.md` listed three server types (stdio,
HTTP over SSE, Streamable HTTP) but incorrectly stated "two kinds of
servers" in the heading. This PR fixes the numerical discrepancy.
**Changes:**
- Modified from "two kinds of servers" to "three kinds of servers".
- File: `docs/mcp.md` (line 11).
### 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.
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.
### 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
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
## Summary
- mention MCPServerStreamableHttp in MCP server docs
- document CodeInterpreterTool, HostedMCPTool, ImageGenerationTool and
LocalShellTool
- update Japanese translations
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>
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.
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.
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>