Commit graph

327 commits

Author SHA1 Message Date
Toufik Airane
757b7dafb1
Update README.md (#405)
fix typo
2025-04-01 11:50:40 -04:00
Ddper
8b2bc0b4ba
fix duplicate declaration of _shutdown_event (#410)
fix duplicate declaration of _shutdown_event
reported by issue
https://github.com/openai/openai-agents-python/issues/314
2025-04-01 11:48:02 -04:00
Eric Peter
9c53abe8c1
Databricks MLflow tracing integration (#401) 2025-03-30 23:53:09 -04:00
Ali Waleed
382500d841
Add Langtrace to tracing.md (#371) 2025-03-27 21:33:49 -04:00
Martin Jagusch
b268829d08
Remove duplicate dependency definition of pynput (#367)
`pynput` is in the pyproject.toml file twice, as you can see on line 54.

The uv.lock file doesn't change.
2025-03-27 13:40:06 -04:00
amri369
377ddbace6
Hotfix mcp example (#365)
Small typo in uv command fixed
2025-03-27 13:05:30 -04:00
Steven Heidel
aad8accc86
Expose the "store" parameter through ModelSettings (#357)
Closes https://github.com/openai/openai-agents-python/issues/173

This will also set stored completions to True by default, encouraging a
best practice.
2025-03-26 19:01:28 -04:00
Rohan Mehta
4854a745e8
Raise error on more invalid function schemas (#356)
Towards #345

## Summary:
Using a `dict` or `Mapping` isn't strict-mode compliant. But we were
checking for the literal `True` whereas the value can also be an array,
for example. Fix that.

## Test Plan:

Unit tests
2025-03-26 15:52:19 -04:00
Rohan Mehta
f99fa5f23c
Tracing screenshot for MCP docs (#355) 2025-03-26 10:56:34 -07:00
Rohan Mehta
bd47a41d0b
MCP example for SSE (#354)
Simple example with a local SSE server.
2025-03-26 12:56:35 -04:00
Rohan Mehta
7f02967156
v0.0.7 (#353)
Upgrade version to prepare for a new release.
2025-03-26 09:06:24 -07:00
pakrym-oai
6d95a3f191
Mark handoff span as errored when multiple handoffs are requested (#344)
Also includes the set of requested agents in the error data.
<img width="968" alt="image"
src="https://github.com/user-attachments/assets/0c5c2e81-08f7-445c-bbb0-3e169ef744a5"
/>
2025-03-26 10:44:59 -04:00
Rohan Mehta
2261aabeeb
Adding Git MCP server example (#343)
- Adding new example showing a single agent interacting with local MCP
server for git
2025-03-25 19:54:59 -04:00
Rohan Mehta
b5ba22904a
[5/n] MCP tracing (#342)
## Summary:

Adds tracing and tests for tracing.
- Tools are added to the agents
- Theres a span for the mcp tools lookup
- Functions have MCP data

## Test Plan:

Unit tests
.
2025-03-25 19:54:28 -04:00
Dmitry Pimenov
5385f8b10e added readme, fixed typo 2025-03-25 16:52:52 -07:00
Dmitry Pimenov
88c8acbc5a fixing lint issues 2025-03-25 16:34:00 -07:00
Dmitry Pimenov
0944390c3f adding Git MCP server example 2025-03-25 16:30:50 -07:00
Rohan Mehta
010022777b [5/n] MCP tracing
## Summary:

Adds tracing and tests for tracing.
- Tools are added to the agents
- Theres a span for the mcp tools lookup
- Functions have MCP data

## Test Plan:

Unit tests
.
2025-03-25 19:28:48 -04:00
Rohan Mehta
dd881eed9a
feat: Add Graphviz-based agent visualization functionality (#147)
This pull request introduces functionality for visualizing agent
structures using Graphviz. The changes include adding a new dependency,
implementing functions to generate and draw graphs, and adding tests for
these functions.

New functionality for visualizing agent structures:

* Added `graphviz` as a new dependency in `pyproject.toml`.
* Implemented functions in `src/agents/visualizations.py` to generate
and draw graphs for agents using Graphviz. These functions include
`get_main_graph`, `get_all_nodes`, `get_all_edges`, and `draw_graph`.

Testing the new visualization functionality:

* Added tests in `tests/test_visualizations.py` to verify the
correctness of the graph generation and drawing functions. The tests
cover `get_main_graph`, `get_all_nodes`, `get_all_edges`, and
`draw_graph`.

For example, given the following code:

```python
from agents import Agent, function_tool
from agents.visualizations import draw_graph


@function_tool
def get_weather(city: str) -> str:
    return f"The weather in {city} is sunny."


spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
    tools=[get_weather],
)


draw_graph(triage_agent)
```

Generates the following image:

<img width="614" alt="Screenshot 2025-03-13 at 18 36 23"
src="https://github.com/user-attachments/assets/d01fe502-6886-4efb-aaf8-c92e4524b0fe"
/>
2025-03-25 19:22:58 -04:00
Rohan Mehta
a0c5abce8f
fix(examples): make sure audio playback finishes (#340)
Previously the stream was closing as soon as all the audio was added but
didn't wait for it to be finished. Additionally the audio might seem
chopped off if there is no additional silence so this PR also adds one
second of silence before exiting the program.
2025-03-25 15:22:55 -04:00
Dominik Kundel
2104f5400b fix(examples): make sure audio playback finishes 2025-03-25 12:11:33 -07:00
Martín Bravo
c16deb22a1 Remove Jupyter Notebook files from .gitignore 2025-03-25 19:31:32 +01:00
Martín Bravo
70aff1d39d linting 2025-03-25 19:18:57 +01:00
Martín Bravo
3068e42029 Fix type ignore comment for agent check in get_all_edges function 2025-03-25 19:17:35 +01:00
Martín Bravo
351b6074e5 Refactor visualization functions to improve formatting and streamline edge generation 2025-03-25 19:12:40 +01:00
Martín Bravo
5ad53d8000 Add start and end nodes to graph visualization and update edge generation 2025-03-25 19:11:43 +01:00
Martín Bravo
29103caba9 Add Jupyter Notebook files to .gitignore 2025-03-25 19:03:39 +01:00
Martín Bravo
b9d32cda0f Refactor get_all_edges function to remove unused parent parameter 2025-03-25 19:02:21 +01:00
Martín Bravo
d8922ff472 Add visualization.md to navigation in mkdocs.yml 2025-03-25 18:56:01 +01:00
Martín Bravo
2f2606e5ea Add graphviz as a dependency and update import statements 2025-03-25 18:46:23 +01:00
Rohan Mehta
59aed3490d
Update pyproject.toml 2025-03-25 13:37:01 -04:00
Rohan Mehta
6be9b2a222
Update visualization.md 2025-03-25 13:34:45 -04:00
Rohan Mehta
ad020b73b5
Make the reset behavior on tool use configurable (#335)
## Summary:

#263 added this behavior. The goal was to prevent infinite loops when
tool choice was set. The key change I'm making is:
1. Making it configurable on the agent.
2. Doing bookkeeping in the Runner to track this, to prevent mutating
agents.
3. Not resetting the global tool choice in RunConfig.

## Test Plan:
Unit tests.
.
2025-03-25 13:30:32 -04:00
Martín Bravo
698fd69eb4 Update installation instructions for visualization dependency to use 'viz' 2025-03-25 18:29:55 +01:00
Rohan Mehta
6fb5792b77 Make the reset behavior on tool use configurable
## Summary:

#263 added this behavior. The goal was to prevent infinite loops when tool choice was set. The key change I'm making is:
1. Making it configurable on the agent.
2. Doing bookkeeping in the Runner to track this, to prevent mutating agents.
3. Not resetting the global tool choice in RunConfig.

## Test Plan:
Unit tests.
.
2025-03-25 13:29:32 -04:00
Rohan Mehta
362a9dc078
[4/n] Add docs for MCP (#338)
Just adding docs.

(Repeat of #324)
2025-03-25 13:27:15 -04:00
Rohan Mehta
86618494a9
[3/n] Add an MCP stdio example (#337)
### Summary:
Spins up a stdio server with some local files, then asks the model
questions.

### Test Plan:
Run the example, see it work.

(repeat of #322)
2025-03-25 13:27:05 -04:00
Rohan Mehta
b98a6bd4ac [4/n] Add docs for MCP
Just adding docs.
-
2025-03-25 13:25:50 -04:00
Rohan Mehta
de1e9a754d [3/n] Add an MCP stdio example
### Summary:
Spins up a stdio server with some local files, then asks the model questions.

### Test Plan:
Run the example, see it work.
2025-03-25 13:24:18 -04:00
Martín Bravo
57ecebfe35 Refactor visualization node label formatting in get_all_nodes function 2025-03-25 18:16:29 +01:00
Martín Bravo
48fad9e2d3 Merge branch 'main' of https://github.com/openai/openai-agents-python into feat/draw_graph 2025-03-25 18:02:51 +01:00
Martín Bravo
9d04671095 Rename visualization dependency to viz in pyproject.toml 2025-03-25 18:01:45 +01:00
Rohan Mehta
4f8cbfa676
[2/n] Add MCP support to Runner (#321)
### Summary:
This enables users to **use** MCP inside the SDK.
1. You add a list of MCP servers to `Agent`, via `mcp_server=[...]`
2. When an agent runs, we look up its MCP tools and add them to the list
of tools.
3. When a tool call occurs, we call the relevant MCP server.

Notes:
1. There's some refactoring to make sure we send the full list of tools
to the Runner/Model etc.
2. Right now, you could have a locally defined tool that conflicts with
an MCP defined tool. I didn't add errors for that, will do in a
followup.

### Test Plan:
See unit tests. Also has an end to end example next PR.

---
[//]: # (BEGIN SAPLING FOOTER)
* #324
* #322
* __->__ #321
* #320
2025-03-25 12:53:29 -04:00
Rohan Mehta
91feb7dd18
[1/n] Add MCP types to the SDK (#320)
### Summary:
1. Add the MCP dep for python 3.10, since it doesn't support 3.9 and
below
2. Create MCPServer, which is the agents SDK representation of an MCP
server
3. Create implementations for HTTP-SSE and StdIO servers, directly
copying the [MCP SDK
example](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py)
4. Add a util to transform MCP tools into Agent SDK tools

Note: I added optional caching support to the servers. That way, if you
happen to know a server's tools don't change, you can just cache them.

### Test Plan:

Checks pass. I added tests at the end of the stack.

--- 

#324
#322
#321
-> #320
#319
2025-03-25 12:53:10 -04:00
Rohan Mehta
97e3dc3c76 [1/n] Add MCP types to the SDK
### Summary:
1. Add the MCP dep for python 3.10, since it doesn't support 3.9 and below
2. Create MCPServer, which is the agents SDK representation of an MCP server
3. Create implementations for HTTP-SSE and StdIO servers, directly copying the [MCP SDK example](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py)
4. Add a util to transform MCP tools into Agent SDK tools

Note: I added optional caching support to the servers. That way, if you happen to know a server's tools don't change, you can just cache them.

### Test Plan:

Checks pass. I added tests at the end of the stack.
2025-03-25 12:51:40 -04:00
Martín Bravo
b3addcff13 Add visualization optional dependency for graphviz 2025-03-25 16:59:17 +01:00
Martín Bravo
900a97fa55 Merge branch 'main' of https://github.com/openai/openai-agents-python into feat/draw_graph 2025-03-25 16:58:01 +01:00
Rohan Mehta
923a3547eb
Fix parallel_tool_calls when False (#333)
Currently, when we set `parallel_tool_calls=False` in the
`model_settings`, the responses API is called with `parallel_tool_calls
== NotGiven`, which defaults to true on the Response API side
(https://platform.openai.com/docs/api-reference/responses/create#responses-create-parallel_tool_calls).

This PR attempts to fix that.

```
agent = Agent(
    ...,
    model_settings=ModelSettings(
        parallel_tool_calls=False,
    ),
)
```
2025-03-25 11:31:06 -04:00
Rohan Mehta
927a29c56b
Fix potential infinite tool call loop by resetting tool_choice after … (#263)
# Fix potential infinite tool call loop by resetting tool_choice after
tool execution

## Summary

This PR fixes an issue where setting `tool_choice` to "required" or a
specific function name could cause models to get stuck in an infinite
tool call loop.

When `tool_choice` is set to force tool usage, this setting persists
across model invocations. This PR automatically resets `tool_choice` to
"auto" after tool execution, allowing the model to decide whether to
make additional tool calls in subsequent turns.

Unlike using `tool_use_behavior="stop_on_first_tool"`, this approach
lets the model continue processing tool results while preventing forced
repeated tool calls.

## Test plan

- Added tests to verify tool_choice reset behavior for both agent and
run_config settings
- Added integration test to verify the solution prevents infinite loops
- All tests pass

## Checks

- [x] I've added new tests for the fix
- [x] I've updated the relevant documentation (added comment in code)
- [x] I've run `make lint` and `make format`
- [x] I've made sure tests pass
2025-03-25 11:30:53 -04:00
apeccaud
326ff09127 Fix parallel_tool_calls when False 2025-03-25 14:52:48 +00:00