Skip to content

Commit 36c0929

Browse files
Copiloteavanvalkenburg
authored andcommitted
Address review feedback for #4625: review comment fixes
1 parent 0ce9514 commit 36c0929

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
@@ -1040,8 +1040,7 @@ async def sampling_callback(
10401040

10411041
if params.temperature is not None:
10421042
options["temperature"] = params.temperature
1043-
if params.maxTokens is not None:
1044-
options["max_tokens"] = params.maxTokens
1043+
options["max_tokens"] = params.maxTokens
10451044
if params.stopSequences is not None:
10461045
options["stop"] = params.stopSequences
10471046

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

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

21272127

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

21322132
tool = MCPStdioTool(name="test_tool", command="python")
@@ -2146,7 +2146,7 @@ async def test_mcp_tool_sampling_callback_omits_max_tokens_when_none():
21462146
mock_message.content.text = "Test question"
21472147
params.messages = [mock_message]
21482148
params.temperature = None
2149-
params.maxTokens = None
2149+
params.maxTokens = 200
21502150
params.stopSequences = None
21512151
params.systemPrompt = None
21522152
params.tools = None
@@ -2156,8 +2156,8 @@ async def test_mcp_tool_sampling_callback_omits_max_tokens_when_none():
21562156

21572157
assert isinstance(result, types.CreateMessageResult)
21582158
call_kwargs = mock_chat_client.get_response.call_args
2159-
options = call_kwargs.kwargs.get("options")
2160-
assert options is None or "max_tokens" not in options
2159+
options = call_kwargs.kwargs.get("options") or {}
2160+
assert options["max_tokens"] == 200
21612161

21622162

21632163
async def test_connect_sampling_capabilities_with_client():

0 commit comments

Comments
 (0)