{"record":{"id":"1665b8e3e952e33e","repo":"microsoft/autogen","slug":"model-client-model-info-must-be-provided-when-max","errorCode":null,"errorMessage":"model_client.model_info must be provided when max_retries_on_error > 0","messagePattern":"model_client\\.model_info must be provided when max_retries_on_error > 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py","lineNumber":493,"sourceCode":"\n        self._model_client = None\n        if model_client is not None:\n            self._model_client = model_client\n\n        if model_context is not None:\n            self._model_context = model_context\n        else:\n            self._model_context = UnboundedChatCompletionContext()\n\n        self._system_messaages: List[SystemMessage] = []\n        if system_message is None:\n            self._system_messages = []\n        else:\n            self._system_messages = [SystemMessage(content=system_message)]\n\n        if self._max_retries_on_error > 0:\n            if not self._model_client or not self._model_client.model_info:\n                raise ValueError(\"model_client.model_info must be provided when max_retries_on_error > 0\")\n            if not self._model_client.model_info[\"structured_output\"]:\n                raise ValueError(\"Specified model_client doesn't support structured output mode.\")\n\n    @property\n    def produced_message_types(self) -> Sequence[type[BaseChatMessage]]:\n        \"\"\"The types of messages that the code executor agent produces.\"\"\"\n        return (TextMessage,)\n\n    @property\n    def model_context(self) -> ChatCompletionContext:\n        \"\"\"\n        The model context in use by the agent.\n        \"\"\"\n        return self._model_context\n\n    async def on_messages(self, messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken) -> Response:\n        async for message in self.on_messages_stream(messages, cancellation_token):\n            if isinstance(message, Response):","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py#L475-L511","documentation":"CodeExecutorAgent validates on construction that when max_retries_on_error > 0 a model_client with a populated model_info is available, because retries re-validate failed output against the expected structured format and need model capabilities metadata.","triggerScenarios":"Constructing CodeExecutorAgent(max_retries_on_error=2, model_client=None) or with a model client whose model_info is None (common with custom/test clients that skip model_info).","commonSituations":"Copying retry settings from AssistantAgent examples into a CodeExecutorAgent configured without a model client; custom ChatCompletionClient stubs that return None for model_info.","solutions":["Remove or zero out max_retries_on_error (it is only needed when you want structured-output retry validation).","Provide a model_client that exposes a filled model_info dict.","If using a custom client, implement the model_info property returning a valid ModelInfo dict."],"exampleFix":"// before\nagent = CodeExecutorAgent(\n    name=\"coder\",\n    code_executor=executor,\n    model_client=None,\n    max_retries_on_error=2,\n)\n\n// after\nagent = CodeExecutorAgent(\n    name=\"coder\",\n    code_executor=executor,\n    model_client=None,\n)","handlingStrategy":"validation","validationCode":"if max_retries_on_error > 0:\n    assert model_client is not None, \"retries require a model_client\"\n    assert getattr(model_client, \"model_info\", None), \"retries require model_client.model_info\"\n\nagent = CodeExecutorAgent(name=\"coder\", code_executor=exec_,\n                          model_client=model_client,\n                          max_retries_on_error=max_retries_on_error)","typeGuard":"def supports_retry_validation(client) -> bool:\n    return client is not None and bool(getattr(client, \"model_info\", None))","tryCatchPattern":null,"preventionTips":["Only set max_retries_on_error when a full-capability model client is wired in.","Implement model_info on custom clients if you plan to use retries.","Treat retries as optional hardening, not a default."],"tags":["validation","constructor","code-executor","model-info"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}