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
- Pass an OpenAI AsyncClient: client = AsyncOpenAI(api_key=...) from the openai package.
- Keep your ChatCompletionClient for OpenAIChatCompletionAgent / OpenAIAgent, and create a separate AsyncOpenAI for OpenAIAssistantAgent.
- 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
- Create one AsyncOpenAI() client for Assistants-API agents and separate ChatCompletionClients for chat agents.
- Name variables distinctly (assistant_client vs chat_client) to avoid mix-ups.
- Type-annotate constructor args so mypy catches the swap.
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
- Unsupported tool type: {type(tool)}
- Unsupported content type: {type(c)} in {message}
- Unsupported config type {config.GetType()}
- Messages should not be provided in options
- Parameter name cannot be null
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/e8bd1abd5f96afc1.
Report an issue: GitHub.