Wire through parallel_tool_calls to Responses API

Signed-off-by: Anastas Stoyanovsky <astoyano@redhat.com>
This commit is contained in:
Anastas Stoyanovsky 2025-11-11 08:54:02 -05:00
parent 7093978754
commit 7a9b7ecdc2
9 changed files with 159 additions and 20 deletions

View file

@ -682,3 +682,96 @@ def test_max_tool_calls_with_builtin_tools(openai_client, client_with_models, te
# Verify we have a valid max_tool_calls field
assert response_3.max_tool_calls == max_tool_calls[1]
@pytest.mark.skip(reason="Tool calling is not reliable.")
def test_parallel_tool_calls_true(openai_client, client_with_models, text_model_id):
"""Test handling of max_tool_calls with function tools in responses."""
if isinstance(client_with_models, LlamaStackAsLibraryClient):
pytest.skip("OpenAI responses are not supported when testing with library client yet.")
client = openai_client
parallel_tool_calls = True
tools = [
{
"type": "function",
"name": "get_weather",
"description": "Get weather information for a specified location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city name (e.g., 'New York', 'London')",
},
},
},
}
]
# First create a response that triggers function tools
response = client.responses.create(
model=text_model_id,
input="Get the weather in New York and in Paris",
tools=tools,
stream=False,
parallel_tool_calls=parallel_tool_calls,
)
# Verify we got two function calls and that the max_tool_calls do not affect function tools
assert len(response.output) == 2
assert response.output[0].type == "function_call"
assert response.output[0].name == "get_weather"
assert response.output[0].status == "completed"
assert response.output[1].type == "function_call"
assert response.output[1].name == "get_weather"
assert response.output[0].status == "completed"
# Verify we have a valid max_tool_calls field
assert response.parallel_tool_calls == parallel_tool_calls
@pytest.mark.skip(reason="Tool calling is not reliable.")
def test_parallel_tool_calls_false(openai_client, client_with_models, text_model_id):
"""Test handling of max_tool_calls with function tools in responses."""
if isinstance(client_with_models, LlamaStackAsLibraryClient):
pytest.skip("OpenAI responses are not supported when testing with library client yet.")
client = openai_client
parallel_tool_calls = False
tools = [
{
"type": "function",
"name": "get_weather",
"description": "Get weather information for a specified location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city name (e.g., 'New York', 'London')",
},
},
},
}
]
# First create a response that triggers function tools
response = client.responses.create(
model=text_model_id,
input="Get the weather in New York and in Paris",
tools=tools,
stream=False,
parallel_tool_calls=parallel_tool_calls,
)
# Verify we got two function calls and that the max_tool_calls do not affect function tools
assert len(response.output) == 1
assert response.output[0].type == "function_call"
assert response.output[0].name == "get_weather"
assert response.output[0].status == "completed"
# Verify we have a valid max_tool_calls field
assert response.parallel_tool_calls == parallel_tool_calls