microsoft/semantic-kernel · error · AgentInitializationException
Missing required 'client' in OpenAIResponsesAgent._from_dict
Error message
Missing required 'client' in OpenAIResponsesAgent._from_dict()
What it means
Raised by OpenAIResponsesAgent._from_dict() when the kwargs passed in do not contain a 'client' key (or it is None). The declarative-spec deserialization path requires a pre-built AsyncOpenAI client because the spec YAML describes the agent, not its credentials; the client must be supplied externally.
Source
Thrown at python/semantic_kernel/agents/open_ai/openai_responses_agent.py:542
*,
kernel: Kernel,
prompt_template_config: "PromptTemplateConfig | None" = None,
**kwargs,
) -> _T:
"""Create an Assistant Agent from the provided dictionary.
Args:
data: The dictionary containing the agent data.
kernel: The kernel to use for the agent.
prompt_template_config: The prompt template configuration.
kwargs: Additional keyword arguments. Note: unsupported keys may raise validation errors.
Returns:
AzureAIAgent: The OpenAI Assistant Agent instance.
"""
client: AsyncOpenAI = kwargs.pop("client", None)
if client is None:
raise AgentInitializationException("Missing required 'client' in OpenAIResponsesAgent._from_dict()")
spec = AgentSpec.model_validate(data)
if "settings" in kwargs:
kwargs.pop("settings")
args = data.pop("arguments", None)
arguments = None
if args:
arguments = KernelArguments(**args)
# Handle arguments from kwargs, merging with any arguments from data
if "arguments" in kwargs and kwargs["arguments"] is not None:
incoming_args = kwargs["arguments"]
arguments = arguments | incoming_args if arguments is not None else incoming_args
if not (spec.model and spec.model.id):
raise AgentInitializationException("model.id required when creating a new OpenAI Responses Agent.")View on GitHub (pinned to c028a0c7dc)
Solutions
- Build the client first (create_client()) and pass it: agent = OpenAIResponsesAgent.from_dict(data, kernel=kernel, client=client).
- Ensure the kwargs key is exactly 'client' (not 'openai_client' or 'async_client').
- If loading many agents from spec, create the client once and reuse it across from_dict calls.
Example fix
// before agent = OpenAIResponsesAgent.from_dict(spec, kernel=kernel) // after client = OpenAIResponsesAgent.create_client() agent = OpenAIResponsesAgent.from_dict(spec, kernel=kernel, client=client)
Defensive patterns
Strategy: validation
Validate before calling
client = kwargs.get('client')
if client is None:
client = OpenAIResponsesAgent.create_client()
agent = OpenAIResponsesAgent.from_dict(data, kernel=kernel, client=client) Type guard
from openai import AsyncOpenAI
def has_valid_client(kwargs) -> bool:
return isinstance(kwargs.get('client'), AsyncOpenAI) Try / catch
from semantic_kernel.exceptions.agent_exceptions import AgentInitializationException
try:
agent = OpenAIResponsesAgent.from_dict(data, kernel=kernel, client=client)
except AgentInitializationException as e:
if 'client' in str(e):
client = OpenAIResponsesAgent.create_client()
agent = OpenAIResponsesAgent.from_dict(data, kernel=kernel, client=client)
raise Prevention
- Always pass a pre-built AsyncOpenAI client to from_dict().
- Build the client once and reuse it across multiple from_dict() calls.
- Use the exact kwarg name 'client'.
When it happens
Trigger: Calling OpenAIResponsesAgent.from_dict(data, kernel=..., client=...) without providing client, or passing client=None. The method does not construct a client from settings — it expects one already instantiated.
Common situations: Loading an agent from a declarative YAML/JSON file and forgetting to thread the client through, or assuming from_dict() will read env vars like the constructor does. Common when wiring agents dynamically from config.
Related errors
- Missing required 'client' in AzureAIAgent._from_dict()
- Expected AzureOpenAISettings, got {type(settings).__name__}
- Expected AzureOpenAISettings, got {type(settings).__name__}
- Missing required 'client' in OpenAIAssistantAgent._from_dict
- model.id required when creating a new OpenAI Responses Agent
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/aa28b2f15e0bf9dd.
Report an issue: GitHub.