{"record":{"id":"d3ad5c0eaa0d88c5","repo":"agentscope-ai/agentscope","slug":"the-redis-package-is-required-for-redismessagebu","errorCode":null,"errorMessage":"The 'redis' package is required for RedisMessageBus. Install it with: pip install redis[async]","messagePattern":"The 'redis' package is required for RedisMessageBus\\. Install it with: pip install redis\\[async\\]","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/agentscope/app/message_bus/_redis_message_bus.py","lineNumber":105,"sourceCode":"        self._owned_pool: ConnectionPool | None = None\n\n    async def __aenter__(self) -> Self:\n        \"\"\"Create the connection pool and Redis client.\n\n        If an external pool was supplied at construction time it is\n        used directly and its lifecycle remains the caller's\n        responsibility. Otherwise, an internal pool is created from the\n        stored host/port/db parameters and will be closed by\n        :meth:`aclose`.\n\n        Returns:\n            `Self`:\n                The bus, ready for use as an async context manager.\n        \"\"\"\n        try:\n            import redis.asyncio as aioredis\n        except ImportError as e:\n            raise ImportError(\n                \"The 'redis' package is required for RedisMessageBus. \"\n                \"Install it with: pip install redis[async]\",\n            ) from e\n\n        if self._external_pool is not None:\n            pool = self._external_pool\n        else:\n            self._owned_pool = aioredis.ConnectionPool(\n                host=self._host,\n                port=self._port,\n                db=self._db,\n                password=self._password,\n                decode_responses=True,\n                **self._kwargs,\n            )\n            pool = self._owned_pool\n\n        self._client = aioredis.Redis(connection_pool=pool)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/app/message_bus/_redis_message_bus.py#L87-L123","documentation":"RedisMessageBus.__aenter__ raises ImportError when the optional 'redis' Python package (with asyncio support) is not installed in the environment. The library treats redis as an optional dependency and only imports it lazily when the bus is actually entered, so construction succeeds but 'async with bus' fails.","triggerScenarios":"Creating a RedisMessageBus and entering it: 'async with RedisMessageBus(...) as bus:' in an environment where 'import redis.asyncio' raises ImportError (package missing, or an ancient redis version without the asyncio subpackage).","commonSituations":"Installing agentscope without the message-bus extra; a fresh venv/CI image; a requirements pin of an old redis version (<4.2) that lacks redis.asyncio; dependency pruning tools stripping 'unused' imports.","solutions":["Install the async-capable redis client: pip install 'redis[async]'","Add 'redis[async]' to your project's dependencies/lockfile so it survives rebuilds","If it was working before, check that a requirements pruning or version downgrade did not remove redis.asyncio","Verify with: python -c \"import redis.asyncio\""],"exampleFix":"# before\nbus = RedisMessageBus(url=\"redis://localhost:6379\")\nasync with bus: ...\n# ImportError: The 'redis' package is required...\n\n# after\n# shell:\npip install 'redis[async]'","handlingStrategy":"validation","validationCode":"def redis_available() -> bool:\n    try:\n        import redis.asyncio  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nassert redis_available(), \"pip install 'redis[async]'\"","typeGuard":"null","tryCatchPattern":"try:\n    async with RedisMessageBus(url=url) as bus:\n        ...\nexcept ImportError as e:\n    if 'redis' in str(e):\n        raise RuntimeError('Install redis[async] to use RedisMessageBus') from e\n    raise","preventionTips":["Pin 'redis[async]' in project dependencies/lockfile","Smoke-test 'import redis.asyncio' at startup when the bus is configured","Use ImportError as a signal to fall back to an in-memory bus in dev"],"tags":["redis","message-bus","missing-dependency","importerror"],"backgroundTag":"missing-optional-dependency","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}