microsoft/autogen · error · ValueError

Function calls are not supported in this context

Error message

Function calls are not supported in this context

What it means

Thrown at the end of streaming response processing when the reconstructed stop_reason equals 'function_call', the legacy finish reason. This client only supports the modern 'tool_calls' stop reason; a legacy function-call stream means the response was produced by an endpoint emulating the deprecated API and cannot be represented by this client.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py:1009

                            full_tool_calls[idx].name += tool_call_chunk.function.name
                        if tool_call_chunk.function.arguments is not None:
                            full_tool_calls[idx].arguments += tool_call_chunk.function.arguments
            if choice.logprobs and choice.logprobs.content:
                logprobs = [
                    ChatCompletionTokenLogprob(
                        token=x.token,
                        logprob=x.logprob,
                        top_logprobs=[TopLogprob(logprob=y.logprob, bytes=y.bytes) for y in x.top_logprobs],
                        bytes=x.bytes,
                    )
                    for x in choice.logprobs.content
                ]

        # Finalize the CreateResult.

        # TODO: can we remove this?
        if stop_reason == "function_call":
            raise ValueError("Function calls are not supported in this context")

        # We need to get the model from the last chunk, if available.
        model = maybe_model or create_params.create_args["model"]
        model = model.replace("gpt-35", "gpt-3.5")  # hack for Azure API

        # Because the usage chunk is not guaranteed to be the last chunk, we need to check if it is available.
        if chunk and chunk.usage:
            prompt_tokens = chunk.usage.prompt_tokens
            completion_tokens = chunk.usage.completion_tokens
        else:
            prompt_tokens = 0
            completion_tokens = 0
        usage = RequestUsage(
            prompt_tokens=prompt_tokens,
            completion_tokens=completion_tokens,
        )

        # Detect whether it is a function call or just text.

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Upgrade or reconfigure the compatible endpoint to emit finish_reason='tool_calls'
  2. Use a newer api_version for Azure deployments
  3. Avoid passing tools when calling the legacy endpoint so it never emits a function-call finish reason

Example fix

# before: legacy gateway emits finish_reason='function_call'
client = OpenAIChatCompletionClient(model="local-model", base_url="http://localhost:8000/v1", api_key="x", model_info=...)

# after: disable tools on that endpoint, or point at a gateway version that emits 'tool_calls'
client.create([msg])  # non-streaming, without tools
Defensive patterns

Strategy: try-catch

Try / catch

try:
    stream = client.create_stream(messages, tools=tools)
    async for chunk in stream:
        ...
except ValueError as e:
    if "Function calls are not supported in this context" in str(e):
        result = await client.create(messages)  # retry without tools
    else:
        raise

Prevention

When it happens

Trigger: create_stream is called against an OpenAI-compatible endpoint whose streamed chunks terminate with finish_reason='function_call' instead of 'tool_calls'. Typically a proxy, gateway, or fine-tuned model speaking the legacy function-call protocol.

Common situations: OpenAI-compatible servers (older vLLM/LiteLLM/local gateways) that translate tool calls into the legacy streaming format; Azure deployments with old api_versions; legacy fine-tunes.

Related errors


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