Skip to content

Commit 7c2d7f4

Browse files
authored
Misc small fixes - mcp version, test for function_schema, version gen (openai#429)
Summary: 1. Use <2 for MCP version so it doesn't break if the MCP sdk upgrades. 2. Test the func schema extraction logic. 3. Fix the logic to get the version nuber of the framework Test Plan: unit tests
1 parent bf302c5 commit 7c2d7f4

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

Diff for: .vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

Diff for: pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies = [
1313
"typing-extensions>=4.12.2, <5",
1414
"requests>=2.0, <3",
1515
"types-requests>=2.0, <3",
16-
"mcp; python_version >= '3.10'",
16+
"mcp>=1.6.0, <2; python_version >= '3.10'",
1717
]
1818
classifiers = [
1919
"Typing :: Typed",

Diff for: src/agents/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
transcription_span,
101101
)
102102
from .usage import Usage
103+
from .version import __version__
103104

104105

105106
def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
@@ -247,4 +248,5 @@ def enable_verbose_stdout_logging():
247248
"gen_trace_id",
248249
"gen_span_id",
249250
"default_tool_error_function",
251+
"__version__",
250252
]

Diff for: src/agents/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import importlib.metadata
22

33
try:
4-
__version__ = importlib.metadata.version("agents")
4+
__version__ = importlib.metadata.version("openai-agents")
55
except importlib.metadata.PackageNotFoundError:
66
# Fallback if running from source without being installed
77
__version__ = "0.0.0"

Diff for: tests/test_function_tool_decorator.py

+35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Any, Optional
44

55
import pytest
6+
from inline_snapshot import snapshot
67

78
from agents import function_tool
89
from agents.run_context import RunContextWrapper
@@ -198,3 +199,37 @@ async def test_all_optional_params_function():
198199
input_data = {"x": 10, "y": "world", "z": 99}
199200
output = await tool.on_invoke_tool(ctx_wrapper(), json.dumps(input_data))
200201
assert output == "10_world_99"
202+
203+
204+
@function_tool
205+
def get_weather(city: str) -> str:
206+
"""Get the weather for a given city.
207+
208+
Args:
209+
city: The city to get the weather for.
210+
"""
211+
return f"The weather in {city} is sunny."
212+
213+
214+
@pytest.mark.asyncio
215+
async def test_extract_descriptions_from_docstring():
216+
"""Ensure that we extract function and param descriptions from docstrings."""
217+
218+
tool = get_weather
219+
assert tool.description == "Get the weather for a given city."
220+
params_json_schema = tool.params_json_schema
221+
assert params_json_schema == snapshot(
222+
{
223+
"type": "object",
224+
"properties": {
225+
"city": {
226+
"description": "The city to get the weather for.",
227+
"title": "City",
228+
"type": "string",
229+
}
230+
},
231+
"title": "get_weather_args",
232+
"required": ["city"],
233+
"additionalProperties": False,
234+
}
235+
)

Diff for: uv.lock

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)