{"record":{"id":"3b99882b84787c0d","repo":"crewAIInc/crewAI","slug":"agent-id-is-required-to-query-the-contextual-ai-ag","errorCode":null,"errorMessage":"Agent ID is required to query the Contextual AI agent","messagePattern":"Agent ID is required to query the Contextual AI agent","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/contextualai_query_tool/contextual_query_tool.py","lineNumber":71,"sourceCode":"            return not any(\n                doc.get(\"status\") in (\"processing\", \"pending\") for doc in documents\n            )\n        return True\n\n    async def _wait_for_documents_async(\n        self, datastore_id: str, max_attempts: int = 20, interval: float = 30.0\n    ) -> bool:\n        \"\"\"Asynchronously poll until documents are ready, exiting early if possible.\"\"\"\n        for _attempt in range(max_attempts):\n            ready = await asyncio.to_thread(self._check_documents_ready, datastore_id)\n            if ready:\n                return True\n            await asyncio.sleep(interval)\n        return True  # give up but don't fail hard\n\n    def _run(self, query: str, agent_id: str, datastore_id: str | None = None) -> str:\n        if not agent_id:\n            raise ValueError(\"Agent ID is required to query the Contextual AI agent\")\n\n        if datastore_id:\n            ready = self._check_documents_ready(datastore_id)\n            if not ready:\n                try:\n                    # If no running event loop, use asyncio.run\n                    loop = asyncio.get_running_loop()\n                except RuntimeError:\n                    loop = None\n\n                if loop and loop.is_running():\n                    # Already inside an event loop\n                    try:\n                        import nest_asyncio  # type: ignore[import-untyped]\n\n                        nest_asyncio.apply(loop)\n                        loop.run_until_complete(\n                            self._wait_for_documents_async(datastore_id)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/contextualai_query_tool/contextual_query_tool.py#L53-L89","documentation":"Error \"Agent ID is required to query the Contextual AI agent\" thrown in crewAIInc/crewAI.","triggerScenarios":"Thrown at lib/crewai-tools/src/crewai_tools/tools/contextualai_query_tool/contextual_query_tool.py:71 when the library encounters an invalid state.","commonSituations":"Occurs when the Contextual AI query tool is called without an agent ID. Provide the agent ID of the agent to query.","solutions":["Pass a valid agent_id obtained from the Contextual AI console."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}