{"record":{"id":"fb819b71819bf86b","repo":"microsoft/autogen","slug":"thread-not-initialized","errorCode":null,"errorMessage":"Thread not initialized","messagePattern":"Thread not initialized","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/agents/azure/_azure_ai_agent.py","lineNumber":365,"sourceCode":"        self._temperature = temperature\n        self._tool_resources = tool_resources\n        self._top_p = top_p\n        self._vector_store_id: Optional[str] = None\n        self._uploaded_file_ids: List[str] = []\n\n        self._initial_message_ids: Set[str] = set()\n        self._initial_state_retrieved: bool = False\n\n    # Properties\n    @property\n    def produced_message_types(self) -> Sequence[type[ChatMessage]]:\n        \"\"\"The types of messages that the assistant agent produces.\"\"\"\n        return (TextMessage,)\n\n    @property\n    def thread_id(self) -> str:\n        if self._thread is None:\n            raise ValueError(\"Thread not initialized\")\n        return self._thread.id\n\n    @property\n    def _get_agent_id(self) -> str:\n        if self._agent is None:\n            raise ValueError(\"Agent not initialized\")\n        return self._agent.id\n\n    @property\n    def description(self) -> str:\n        if not self._description:\n            raise ValueError(\"Description not initialized\")\n        return self._description\n\n    @property\n    def agent_id(self) -> str:\n        if not self._agent_id:\n            raise ValueError(\"Agent not initialized\")","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/agents/azure/_azure_ai_agent.py#L347-L383","documentation":"The AzureAIAgent.thread_id property raises ValueError when the underlying Azure AI Projects agent thread has not been created yet. The agent is lazily initialized (_ensure_initialized creates/loads the thread); accessing thread_id before any on_messages/on_messages_stream/save_state call (or before explicit initialization) hits _thread is None.","triggerScenarios":"Constructing AzureAIAgent and reading agent.thread_id immediately, before calling any method that triggers _ensure_initialized; or after on_messages raised early so initialization never completed.","commonSituations":"Building the agent then immediately logging/associating its thread id; sharing a partially-initialized agent across tasks; an exception during the first run leaving the agent half-initialized.","solutions":["Trigger initialization first: await any on_messages/on_messages_stream call, or call the agent's initialization path (await agent._ensure_initialized() / perform a first run) before reading thread_id.","If you need the id up front, create the thread yourself with the project client and pass it in at construction time (the constructor accepts an existing thread).","Wrap the access in try/except ValueError and retry after the first successful run.","Check the agent's source version — newer versions expose async initialization; consult the class docstring for the supported way to pre-initialize."],"exampleFix":"# before\nagent = AzureAIAgent(client, name=\"a\")\nprint(agent.thread_id)  # ValueError\n# after\nawait agent.on_messages([TextMessage(content=\"hi\", source=\"user\")], CancellationToken())\nprint(agent.thread_id)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    tid = agent.thread_id\nexcept ValueError:\n    await agent.on_messages([TextMessage(content=\"init\", source=\"user\")], None)\n    tid = agent.thread_id","preventionTips":["Run one interaction (or explicit init) before reading thread_id/agent_id.","Create the thread yourself and pass it at construction when you need the id up front.","Don't log identity properties of a freshly constructed agent."],"tags":["azure","lifecycle","azure-ai-agent"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}