microsoft/autogen · error · ValueError

Incorrect client passed to OpenAIAssistantAgent. Please use

Error message

Incorrect client passed to OpenAIAssistantAgent. Please use an OpenAI AsyncClient instance instead of an AutoGen ChatCompletionClient instance.

What it means

OpenAIAssistantAgent talks to the OpenAI Assistants API directly through the openai SDK's AsyncOpenAI client — it does not use AutoGen's ChatCompletionClient abstraction. The constructor explicitly rejects ChatCompletionClient instances (including AsyncOpenAIChatCompletionClient) with this ValueError to prevent the common mistake of passing the wrong client kind.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py:259

        instructions: str,
        tools: Optional[
            Iterable[
                Union[
                    Literal["code_interpreter", "file_search"],
                    Tool | Callable[..., Any] | Callable[..., Awaitable[Any]],
                ]
            ]
        ] = None,
        assistant_id: Optional[str] = None,
        thread_id: Optional[str] = None,
        metadata: Optional[Dict[str, str]] = None,
        response_format: Optional["AssistantResponseFormatOptionParam"] = None,
        temperature: Optional[float] = None,
        tool_resources: Optional["ToolResources"] = None,
        top_p: Optional[float] = None,
    ) -> None:
        if isinstance(client, ChatCompletionClient):
            raise ValueError(
                "Incorrect client passed to OpenAIAssistantAgent. Please use an OpenAI AsyncClient instance instead of an AutoGen ChatCompletionClient instance."
            )

        super().__init__(name, description)
        if tools is None:
            tools = []

        # Store original tools and converted tools separately
        self._original_tools: List[Tool] = []
        converted_tools: List["AssistantToolParam"] = []
        for tool in tools:
            if isinstance(tool, str):
                if tool == "code_interpreter":
                    converted_tools.append(CodeInterpreterToolParam(type="code_interpreter"))
                elif tool == "file_search":
                    converted_tools.append(FileSearchToolParam(type="file_search"))
            elif isinstance(tool, Tool):
                self._original_tools.append(tool)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Pass an OpenAI AsyncClient: client = AsyncOpenAI(api_key=...) from the openai package.
  2. Keep your ChatCompletionClient for OpenAIChatCompletionAgent / OpenAIAgent, and create a separate AsyncOpenAI for OpenAIAssistantAgent.
  3. If you actually want the chat-completions style agent with AutoGen clients, use OpenAIChatCompletionAgent instead of OpenAIAssistantAgent.

Example fix

# before
from autogen_ext.models.openai import OpenAIChatCompletionClient
agent = OpenAIAssistantAgent(
    name="helper", instructions="...", model="gpt-4o",
    client=OpenAIChatCompletionClient(model="gpt-4o"),
)

# after
from openai import AsyncOpenAI
agent = OpenAIAssistantAgent(
    name="helper", instructions="...", model="gpt-4o",
    client=AsyncOpenAI(),  # uses OPENAI_API_KEY env var
)
Defensive patterns

Strategy: type-guard

Validate before calling

from openai import AsyncOpenAI
assert isinstance(client, AsyncOpenAI), "OpenAIAssistantAgent needs openai.AsyncOpenAI"

Type guard

from openai import AsyncOpenAI
from autogen_core.models import ChatCompletionClient

def is_assistant_client(client: object) -> bool:
    return isinstance(client, AsyncOpenAI) and not isinstance(client, ChatCompletionClient)

Prevention

When it happens

Trigger: OpenAIAssistantAgent(name=..., instructions=..., model=..., client=AsyncOpenAIChatCompletionClient(model="gpt-4o", api_key=...)) — any autogen ChatCompletionClient subclass as client.

Common situations: Copying client setup from OpenAIChatCompletionAgent examples; refactoring an agent from the chat-completion style to the Assistants API without changing the client; tutorials that construct a chat completion client once and pass it everywhere.

Related errors


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