agentscope-ai/agentscope · error · ValueError

Cannot extract platform_bot_id for type '{channel_type}'.

Error message

Cannot extract platform_bot_id for type '{channel_type}'.

What it means

ValueError raised by ChannelRegistry.extract_platform_bot_id when the given channel_type is not registered OR the registered class does not define a platform_bot_id_field. The method needs the class attribute to know which credential key holds the platform bot id; without it the bot id cannot be extracted from raw credentials.

Source

Thrown at src/agentscope/app/channel/_registry.py:157

    def list_types(self) -> list[ChannelTypeSchema]:
        """List frontend schemas for all registered types."""
        return [self.schema_of(c) for c in self._classes.values()]

    def extract_platform_bot_id(
        self,
        channel_type: str,
        credentials: dict,
    ) -> str:
        """Read the bot-identifying credential field, for uniqueness.

        Args:
            channel_type (`str`): The platform type id.
            credentials (`dict`): Raw credentials to read the bot id from.
        """
        channel_cls = self._classes.get(channel_type)
        if channel_cls is None or not channel_cls.platform_bot_id_field:
            raise ValueError(
                f"Cannot extract platform_bot_id for type '{channel_type}'.",
            )
        bot_id = credentials.get(channel_cls.platform_bot_id_field)
        if not bot_id:
            raise ValueError(
                f"Missing '{channel_cls.platform_bot_id_field}' in "
                f"credentials.",
            )
        return str(bot_id)

View on GitHub (pinned to e90f1c7592)

Solutions

  1. If the type is unregistered, pass the class to create_app(channels=[...])
  2. If it's your own channel class, set platform_bot_id_field (e.g. platform_bot_id_field = "bot_id") naming the credentials key that stores the bot id
  3. Audit the channel_type value being sent in the API payload for typos

Example fix

# before
class MyChannel(ChannelBase):
    channel_type = "mychat"
    # no platform_bot_id_field

# after
class MyChannel(ChannelBase):
    channel_type = "mychat"
    platform_bot_id_field = "bot_id"
Defensive patterns

Strategy: validation

Validate before calling

cls = registry.get(channel_type)
if cls is None or not getattr(cls, "platform_bot_id_field", None):
    raise RuntimeError(f"cannot extract bot id for {channel_type!r}; register the class and set platform_bot_id_field")

Type guard

def supports_bot_id_extraction(registry, channel_type: str) -> bool:
    cls = registry.get(channel_type)
    return cls is not None and bool(cls.platform_bot_id_field)

Try / catch

try:
    bot_id = registry.extract_platform_bot_id(t, creds)
except ValueError as e:
    if "Cannot extract platform_bot_id" in str(e):
        return HTTPException(400, "channel type unsupported for bot id extraction")

Prevention

When it happens

Trigger: Calling extract_platform_bot_id (directly, or via channel CRUD handlers _to_response/create/update/delete that persist credentials) with an unregistered channel_type, or with a registered custom channel class that lacks a platform_bot_id_field class attribute.

Common situations: Custom channel implementations that forget platform_bot_id_field, channel classes registered for messaging but used in CRUD flows that require bot identity, unregistered type strings coming from user-submitted channel configs.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/4f5ad65a81a98589. Report an issue: GitHub.