Skip to content

Commit e08036a

Browse files
Copiloteavanvalkenburg
authored andcommitted
Address review feedback for #4625: review comment fixes
1 parent f13bf56 commit e08036a

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

python/packages/core/agent_framework/_mcp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,7 @@ async def sampling_callback(
772772

773773
if params.temperature is not None:
774774
options["temperature"] = params.temperature
775-
if params.maxTokens is not None:
776-
options["max_tokens"] = params.maxTokens
775+
options["max_tokens"] = params.maxTokens
777776
if params.stopSequences is not None:
778777
options["stop"] = params.stopSequences
779778

python/packages/core/tests/core/test_mcp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,8 +1952,8 @@ async def test_mcp_tool_sampling_callback_omits_temperature_when_none():
19521952
assert "stop" not in options
19531953

19541954

1955-
async def test_mcp_tool_sampling_callback_omits_max_tokens_when_none():
1956-
"""Test sampling callback does not set max_tokens in options when it is None."""
1955+
async def test_mcp_tool_sampling_callback_always_passes_max_tokens():
1956+
"""Test sampling callback always sets max_tokens in options since maxTokens is a required int field."""
19571957
from agent_framework import Message
19581958

19591959
tool = MCPStdioTool(name="test_tool", command="python")
@@ -1973,7 +1973,7 @@ async def test_mcp_tool_sampling_callback_omits_max_tokens_when_none():
19731973
mock_message.content.text = "Test question"
19741974
params.messages = [mock_message]
19751975
params.temperature = None
1976-
params.maxTokens = None
1976+
params.maxTokens = 200
19771977
params.stopSequences = None
19781978
params.systemPrompt = None
19791979
params.tools = None
@@ -1983,8 +1983,8 @@ async def test_mcp_tool_sampling_callback_omits_max_tokens_when_none():
19831983

19841984
assert isinstance(result, types.CreateMessageResult)
19851985
call_kwargs = mock_chat_client.get_response.call_args
1986-
options = call_kwargs.kwargs.get("options")
1987-
assert options is None or "max_tokens" not in options
1986+
options = call_kwargs.kwargs.get("options") or {}
1987+
assert options["max_tokens"] == 200
19881988

19891989

19901990
async def test_connect_sampling_capabilities_with_client():

0 commit comments

Comments
 (0)