Commit Graph

98 Commits

Author SHA1 Message Date
luijait 3b21b5ec1b Fix pretty print 2025-05-08 09:31:39 +02:00
lidia9 fcb67c5fcb adding fake openai api key 2025-04-30 12:35:40 +02:00
lidia9 66b4d7165e remove set disable in test 2025-04-30 11:41:40 +02:00
Mery-Sanz 1669254b5c tracing disabled 2025-04-30 11:37:06 +02:00
Mery-Sanz 2eb2eb7a59 final fiz 2025-04-23 09:04:48 +02:00
Mery-Sanz 1ecb90eaa2 fix test name 2025-04-23 08:12:09 +02:00
Mery-Sanz dae41dbba7 add test 2025-04-22 16:48:12 +02:00
Mery-Sanz 702a93b6c3 fix agent and add primary test 2025-04-22 16:32:26 +02:00
Mery-Sanz 11c6e4febb test 2025-04-11 13:49:06 +02:00
Mery-Sanz 83e8ca904d fix pipleines 2025-04-11 12:24:32 +02:00
Mery-Sanz e8c4734bab change gpt-4o and install in .yml 2025-04-11 11:38:21 +02:00
Mery-Sanz 3c019ea7a7 try to add ci 2025-04-11 10:06:25 +02:00
Mery-Sanz 34d73ac2cf fix test 2025-04-11 09:34:06 +02:00
Mery-Sanz 58327f19e9 fix mcp test 2025-04-11 08:24:26 +02:00
Mery-Sanz 6a28aff0a0 fix function schema test 2025-04-11 08:11:26 +02:00
Mery-Sanz ccdbf5baf9 fix some test 2025-04-11 08:04:19 +02:00
Mery-Sanz 67ab08dce1 add coments and docstring 2025-04-10 09:57:35 +02:00
Mery-Sanz d7fff2a6c3 improve test 2025-04-10 09:42:16 +02:00
Mery-Sanz b75754fdf4 add more test 2025-04-10 09:27:56 +02:00
Mery-Sanz 93803ffa0d add new test and fix previous 2025-04-10 08:54:21 +02:00
Mery-Sanz 59e8e444ca add test 2025-04-10 07:58:40 +02:00
Mery-Sanz 1bc4b8fd9e final fix 2025-04-09 16:17:06 +02:00
Mery-Sanz f5f43ff000 fix more test 2025-04-09 16:07:58 +02:00
Mery-Sanz dbac371f70 fix more test 2025-04-09 15:59:24 +02:00
Mery-Sanz 24e05fbf2b add 2 more test 2025-04-09 15:54:58 +02:00
Mery-Sanz be6a7ecadd fix test_agent_runner 2025-04-09 15:51:05 +02:00
Mery-Sanz b8ee04a8de fix test_agent_hooks.py and reorganize imports 2025-04-09 15:46:53 +02:00
María Sanz Gómez 2084ec6409 fix tests/test_agent_config.py 2025-04-09 15:42:26 +02:00
Víctor Mayoral Vilches d3b6f8a1ed Merge remote-tracking branch 'origin/main' into cai 2025-03-31 13:21:34 +02:00
Víctor Mayoral Vilches 859799c9f4 CLI responding, but only to proprietary models
Need to investigate why self-hosted models via OLLAMA fail API-wise

Signed-off-by: Víctor Mayoral Vilches <v.mayoralv@gmail.com>
2025-03-28 09:48:16 +01: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
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 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
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
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 2f2606e5ea Add graphviz as a dependency and update import statements 2025-03-25 18:46:23 +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
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
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
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 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
Rohan Mehta 68c800d2a3 [2/n] Add MCP support to Runner
### 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.
2025-03-24 15:08:02 -04:00
Martín Bravo 623063b633 refactor: clean up visualization functions by removing unused nodes and improving type hints 2025-03-24 09:47:21 +01:00
Rohan Mehta 4cb011c4d2
Fix Typos (#258)
Noticed a bunch of typos when reading code, fixing.
2025-03-23 20:28:14 -04:00
xianghuijin 6ed0bee672 fix: prevent modifying the original agent's model_settings
This fixes the issue where the original agent's model_settings was being directly modified during the tool choice reset process. The original implementation caused the agent's tool_choice to unintentionally reset to "auto" for subsequent runs, which could be unexpected behavior.

The fix creates new copies of the agent and model settings objects using dataclasses.replace() instead of modifying the original objects. This ensures that the tool choice reset is limited to the current run only, maintaining the expected behavior for sequential runs with the same agent.

Addresses feedback from @baderalfahad about the agent instance being modified when it should maintain its original state between runs.
2025-03-23 17:20:23 +08:00
xianghuijin bbcda753df fix: optimize tool_choice reset logic and fix lint errors
- Refactor tool_choice reset to target only problematic edge cases
- Replace manual ModelSettings recreation with dataclasses.replace
- Fix line length and error handling lint issues in tests
2025-03-22 14:10:09 +08:00
Rohan Mehta c0794a90ec Read tracing API data lazily 2025-03-21 15:32:37 -04:00