Misc small fixes - mcp version, test for function_schema, version gen (#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
This commit is contained in:
Rohan Mehta 2025-04-03 12:08:01 -04:00 committed by GitHub
parent bf302c574c
commit 7c2d7f4abd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 52 additions and 6 deletions

7
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}

View file

@ -13,7 +13,7 @@ dependencies = [
"typing-extensions>=4.12.2, <5",
"requests>=2.0, <3",
"types-requests>=2.0, <3",
"mcp; python_version >= '3.10'",
"mcp>=1.6.0, <2; python_version >= '3.10'",
]
classifiers = [
"Typing :: Typed",

View file

@ -100,6 +100,7 @@ from .tracing import (
transcription_span,
)
from .usage import Usage
from .version import __version__
def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
@ -247,4 +248,5 @@ __all__ = [
"gen_trace_id",
"gen_span_id",
"default_tool_error_function",
"__version__",
]

View file

@ -1,7 +1,7 @@
import importlib.metadata
try:
__version__ = importlib.metadata.version("agents")
__version__ = importlib.metadata.version("openai-agents")
except importlib.metadata.PackageNotFoundError:
# Fallback if running from source without being installed
__version__ = "0.0.0"

View file

@ -3,6 +3,7 @@ import json
from typing import Any, Optional
import pytest
from inline_snapshot import snapshot
from agents import function_tool
from agents.run_context import RunContextWrapper
@ -198,3 +199,37 @@ async def test_all_optional_params_function():
input_data = {"x": 10, "y": "world", "z": 99}
output = await tool.on_invoke_tool(ctx_wrapper(), json.dumps(input_data))
assert output == "10_world_99"
@function_tool
def get_weather(city: str) -> str:
"""Get the weather for a given city.
Args:
city: The city to get the weather for.
"""
return f"The weather in {city} is sunny."
@pytest.mark.asyncio
async def test_extract_descriptions_from_docstring():
"""Ensure that we extract function and param descriptions from docstrings."""
tool = get_weather
assert tool.description == "Get the weather for a given city."
params_json_schema = tool.params_json_schema
assert params_json_schema == snapshot(
{
"type": "object",
"properties": {
"city": {
"description": "The city to get the weather for.",
"title": "City",
"type": "string",
}
},
"title": "get_weather_args",
"required": ["city"],
"additionalProperties": False,
}
)

10
uv.lock
View file

@ -1,4 +1,5 @@
version = 1
revision = 1
requires-python = ">=3.9"
resolution-markers = [
"python_full_version >= '3.10'",
@ -718,7 +719,7 @@ wheels = [
[[package]]
name = "mcp"
version = "1.5.0"
version = "1.6.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "anyio", marker = "python_full_version >= '3.10'" },
@ -730,9 +731,9 @@ dependencies = [
{ name = "starlette", marker = "python_full_version >= '3.10'" },
{ name = "uvicorn", marker = "python_full_version >= '3.10'" },
]
sdist = { url = "https://files.pythonhosted.org/packages/6d/c9/c55764824e893fdebe777ac7223200986a275c3191dba9169f8eb6d7c978/mcp-1.5.0.tar.gz", hash = "sha256:5b2766c05e68e01a2034875e250139839498c61792163a7b221fc170c12f5aa9", size = 159128 }
sdist = { url = "https://files.pythonhosted.org/packages/95/d2/f587cb965a56e992634bebc8611c5b579af912b74e04eb9164bd49527d21/mcp-1.6.0.tar.gz", hash = "sha256:d9324876de2c5637369f43161cd71eebfd803df5a95e46225cab8d280e366723", size = 200031 }
wheels = [
{ url = "https://files.pythonhosted.org/packages/c1/d1/3ff566ecf322077d861f1a68a1ff025cad337417bd66ad22a7c6f7dfcfaf/mcp-1.5.0-py3-none-any.whl", hash = "sha256:51c3f35ce93cb702f7513c12406bbea9665ef75a08db909200b07da9db641527", size = 73734 },
{ url = "https://files.pythonhosted.org/packages/10/30/20a7f33b0b884a9d14dd3aa94ff1ac9da1479fe2ad66dd9e2736075d2506/mcp-1.6.0-py3-none-any.whl", hash = "sha256:7bd24c6ea042dbec44c754f100984d186620d8b841ec30f1b19eda9b93a634d0", size = 76077 },
]
[[package]]
@ -1133,7 +1134,7 @@ dev = [
requires-dist = [
{ name = "graphviz", marker = "extra == 'viz'", specifier = ">=0.17" },
{ name = "griffe", specifier = ">=1.5.6,<2" },
{ name = "mcp", marker = "python_full_version >= '3.10'" },
{ name = "mcp", marker = "python_full_version >= '3.10'", specifier = ">=1.6.0,<2" },
{ name = "numpy", marker = "python_full_version >= '3.10' and extra == 'voice'", specifier = ">=2.2.0,<3" },
{ name = "openai", specifier = ">=1.66.5" },
{ name = "pydantic", specifier = ">=2.10,<3" },
@ -1142,6 +1143,7 @@ requires-dist = [
{ name = "typing-extensions", specifier = ">=4.12.2,<5" },
{ name = "websockets", marker = "extra == 'voice'", specifier = ">=15.0,<16" },
]
provides-extras = ["voice", "viz"]
[package.metadata.requires-dev]
dev = [