Skip to content

tools parameter is silently ignored when max_turns is not set #286

@peterbaksa

Description

@peterbaksa

Problem

When calling client.chat.completions.create() with tools= but without max_turns=, the tools parameter is silently ignored. The model receives no tool definitions and responds as if no tools were provided — with no warning or error.

Example

import aisuite as ai
from datetime import datetime

def get_current_time():
    """Returns the current time as a string."""
    return datetime.now().strftime("%H:%M:%S")

client = ai.Client()
messages = [{"role": "user", "content": "What time is it?"}]

# WITHOUT max_turns — tools silently ignored, model says "I can't tell the time"
response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=messages,
    tools=[get_current_time],
)
print(response.choices[0].message.content)
# >> "I'm unable to provide real-time information..."

# WITH max_turns — works correctly
response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=messages,
    tools=[get_current_time],
    max_turns=2,
)
print(response.choices[0].message.content)
# >> "The current time is 23:42:32."

Where the problem is

In aisuite/client.py, the create() method has this condition:

if max_turns is not None and tools is not None:
    return self._tool_runner(provider, model_name, messages.copy(), tools, max_turns, **kwargs)

# falls through to standard completion — tools are discarded
response = provider.chat_completions_create(model_name, messages, **kwargs)

When max_turns is None, the code falls through to a standard completion call where tools are never passed to the provider. No warning is raised.

Proposed solution

At minimum, raise a warning when tools is provided without max_turns:

if tools is not None and max_turns is None:
    import warnings
    warnings.warn(
        "tools parameter is ignored without max_turns. "
        "Set max_turns (e.g. max_turns=1) to enable tool calling.",
        UserWarning,
    )

A better approach might be to default max_turns=1 when tools is provided, so that tool calling works out of the box:

if tools is not None and max_turns is None:
    max_turns = 1

This would match user expectations — if you pass tools, you expect them to be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions