Commit graph

13 commits

Author SHA1 Message Date
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
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
xianghuijin
07a4af1fe2 refactor: improve comments for clarity in tool_choice reset logic 2025-03-23 20:41:18 +08:00
xianghuijin
0c747af743 refactor: streamline tool_choice reset logic
This update moves the tool_choice reset logic to a more appropriate location within the RunImpl class, ensuring that the original agent's model_settings remains unmodified during the reset process. The logic now checks for problematic scenarios before creating a modified copy of the agent's settings, maintaining expected behavior across sequential runs. This change enhances clarity and efficiency in handling tool choices.

Addresses previous feedback regarding the modification of the agent instance and improves the overall structure of the reset logic.
2025-03-23 20:04:39 +08: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
xianghuijin
fb77c74fa1 Fix potential infinite tool call loop by resetting tool_choice after tool execution 2025-03-20 21:22:27 +08:00
Rohan Mehta
10aa5555af Introduce tool_use_behavior on agents 2025-03-18 21:55:12 -04:00
Rohan Mehta
09d70c074d utils directory 2025-03-16 18:48:45 -04:00
hironow
9b118a10c6
Merge branch 'main' into hironow/chore-doc-type
# Conflicts:
#	tests/docs/config.md
#	tests/docs/guardrails.md
#	tests/docs/tracing.md
2025-03-12 10:13:25 +09:00
Rohan Mehta
c27d7b7d24 pin to openai 1.66.2, update tests 2025-03-11 15:26:06 -07:00
hironow
5a33e9b168
chore: fix type in doc and comment 2025-03-12 02:46:36 +09:00
Rohan Mehta
aaec57a426 Initial commit 2025-03-11 09:42:28 -07:00