microsoft/autogen · error · ValueError

Model does not support function calling and tools were provi

Error message

Model does not support function calling and tools were provided

What it means

OllamaChatCompletionClient pre-flight checks function-calling capability. If model_info['function_calling'] is False and a non-empty tools list is passed to create()/create_stream(), it raises ValueError rather than forwarding tools to Ollama. This guards against silent tool-ignoring behavior on models without tool support.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py:586

            # Remove format from create_args to prevent passing it twice.
            del create_args["format"]

        # TODO: allow custom handling.
        # For now we raise an error if images are present and vision is not supported
        if self.model_info["vision"] is False:
            for message in messages:
                if isinstance(message, UserMessage):
                    if isinstance(message.content, list) and any(isinstance(x, Image) for x in message.content):
                        raise ValueError("Model does not support vision and image was provided")

        if self.model_info["json_output"] is False and json_output is True:
            raise ValueError("Model does not support JSON output.")

        ollama_messages_nested = [to_ollama_type(m) for m in messages]
        ollama_messages = [item for sublist in ollama_messages_nested for item in sublist]

        if self.model_info["function_calling"] is False and len(tools) > 0:
            raise ValueError("Model does not support function calling and tools were provided")

        converted_tools: List[OllamaTool] = []

        # Handle tool_choice parameter in a way that is compatible with Ollama API.
        if isinstance(tool_choice, Tool):
            # If tool_choice is a Tool, convert it to OllamaTool.
            converted_tools = convert_tools([tool_choice])
        elif tool_choice == "none":
            # No tool choice, do not pass tools to the API.
            converted_tools = []
        elif tool_choice == "required":
            # Required tool choice, pass tools to the API.
            converted_tools = convert_tools(tools)
            if len(converted_tools) == 0:
                raise ValueError("tool_choice 'required' specified but no tools provided")
        else:
            converted_tools = convert_tools(tools)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Use a tool-capable model (llama3.1, qwen2.5, mistral-nemo) and pass model_info with 'function_calling': True
  2. Remove the tools argument when the model genuinely cannot call functions
  3. If calling manually, register tools as prompt text instead and parse the model's reply yourself (last resort)

Example fix

# before
client = OllamaChatCompletionClient(model='qwen2.5:7b')
await client.create(messages, tools=[{'type':'function','function':{...}}])  # ValueError

# after
client = OllamaChatCompletionClient(
    model='qwen2.5:7b',
    model_info={'vision': False, 'function_calling': True, 'json_output': True, 'family': ModelFamily.UNKNOWN, 'structured_output': False},
)
await client.create(messages, tools=[...])
Defensive patterns

Strategy: validation

Validate before calling

tools_ok = bool(client.model_info.get('function_calling', False))
if tools:
    assert tools_ok, f'Model {client._model_name!r} cannot call functions; drop tools or change model'
result = await client.create(messages, tools=tools if tools_ok else [])

Type guard

def supports_tools(model_info: dict) -> bool:
    return model_info.get('function_calling') is True

Try / catch

try:
    result = await client.create(messages, tools=tools)
except ValueError as e:
    if 'function calling' in str(e):
        result = await client.create(messages)  # degrade to no-tools turn
    else:
        raise

Prevention

When it happens

Trigger: Calling create(messages, tools=[...]) with a non-empty tools sequence while model_info['function_calling'] is False — typical when the model is unknown to the client or model_info was supplied without the function_calling flag.

Common situations: Running a tool-using agent (e.g. AssistantAgent with tools) against a local model like llama2 or an uncached model name; hand-written model_info missing the 'function_calling' key defaults it to False; upgrading autogen-ext so a previously-tolerated model name now resolves differently.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/1461d9bd712cc426. Report an issue: GitHub.