AS AgentScopeAPI 手册 / API Reference
类class agentscope.app.channel

ChannelTypeRegistry

class ChannelTypeRegistry
源码Source agentscope/app/channel/_registry.py:41–172

渠道类型注册表,把智能体接入外部消息渠道与企业平台。位于 agentscope.app.channel 包。核心成员包括 register、get、has_type、create_channel、schema_of、list_types。

The channel types a service allows, keyed by channel_type. Declared in agentscope.app.channel.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(channels: list[type['ChannelBase']] | None = None) -> None
初始化 `ChannelTypeRegistry` 实例。
Build the registry from a list of channel classes.

方法摘要Method Summary

方法Method说明Description
def __bool__() -> bool
判断是否任意渠道类型是已注册(特性已启用)。
Whether any channel type is registered (feature enabled).
def register(channel_cls: type['ChannelBase']) -> None
设置注册。
Register a channel class under its ``channel_type``.
def get(channel_type: str) -> type['ChannelBase'] | None
返回渠道类用于类型,或`None`。
Return the channel class for a type, or ``None``.
def has_type(channel_type: str) -> bool
判断是否类型是已注册。
Whether a type is registered.
def create_channel(channel_type: str, channel_id: str, credentials: dict, config: dict) -> 'ChannelBase'
创建渠道。
Validate stored credentials/config against the class's nested models and build the channel instance.
def schema_of(channel_cls: type['ChannelBase']) -> ChannelTypeSchema
设置模式的。
Build the frontend schema for one channel class.
def list_types() -> list[ChannelTypeSchema]
列出类型。
List frontend schemas for all registered types.
def extract_platform_bot_id(channel_type: str, credentials: dict) -> str
执行 `extract_platform_bot_id` 方法。
Read the bot-identifying credential field, for uniqueness.

构造器详情Constructor Detail

ChannelTypeRegistry

def __init__(channels: list[type['ChannelBase']] | None = None) -> None

初始化 ChannelTypeRegistry 实例。

Build the registry from a list of channel classes.

参数Parameters
名称Name类型Type说明Description
channels默认default Nonelist[type['ChannelBase']] | None渠道(类型 `list[type['ChannelBase']] | None`)。Channel classes to allow. Passed through from `create_app(channels=[...])`.
源码Source agentscope/app/channel/_registry.py:44–57

方法详情Method Detail

__bool__

def __bool__() -> bool

判断是否任意渠道类型是已注册(特性已启用)。

Whether any channel type is registered (feature enabled).

返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/app/channel/_registry.py:59–61

register

def register(channel_cls: type['ChannelBase']) -> None

设置注册。

Register a channel class under its channel_type.

参数Parameters
名称Name类型Type说明Description
channel_clstype['ChannelBase']渠道类到添加。The channel class to add.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/channel/_registry.py:63–75

get

def get(channel_type: str) -> type['ChannelBase'] | None

返回渠道类用于类型,或None。

Return the channel class for a type, or None.

参数Parameters
名称Name类型Type说明Description
channel_typestr平台类型标识。The platform type id.
返回Returns type['ChannelBase'] | None
返回类型['ChannelBase']|None。Returns type channel base none.
源码Source agentscope/app/channel/_registry.py:77–83

has_type

def has_type(channel_type: str) -> bool

判断是否类型是已注册。

Whether a type is registered.

参数Parameters
名称Name类型Type说明Description
channel_typestr平台类型标识。The platform type id.
返回Returns bool
返回布尔值,表示判断结果。Returns a boolean result.
源码Source agentscope/app/channel/_registry.py:85–91

create_channel

def create_channel(channel_type: str, channel_id: str, credentials: dict, config: dict) -> 'ChannelBase'

创建渠道。

Validate stored credentials/config against the class's nested models and build the channel instance.

参数Parameters
名称Name类型Type说明Description
channel_typestr平台类型标识。The platform type id.
channel_idstr渠道标识(类型 `str`)。The instance's unique id.
credentialsdict凭证(类型 `dict`)。Raw credentials to validate.
configdict配置对象(类型 `dict`)。Raw platform options to validate.
返回Returns 'ChannelBase'
返回'ChannelBase'。Returns channel base.
异常Raises
  • 当`ValueError`:If`channel_type`是不已注册时抛出 `Exception`。`ValueError`: If `channel_type` is not registered.
源码Source agentscope/app/channel/_registry.py:93–122

schema_of

def schema_of(channel_cls: type['ChannelBase']) -> ChannelTypeSchema

设置模式的。

Build the frontend schema for one channel class.

参数Parameters
名称Name类型Type说明Description
channel_clstype['ChannelBase']渠道类。The channel class.
返回Returns ChannelTypeSchema
返回ChannelTypeSchema。Returns channel type schema.
源码Source agentscope/app/channel/_registry.py:124–144

list_types

def list_types() -> list[ChannelTypeSchema]

列出类型。

List frontend schemas for all registered types.

返回Returns list[ChannelTypeSchema]
返回ChannelTypeSchema列表。Returns a list of channel type schema.
源码Source agentscope/app/channel/_registry.py:146–148

extract_platform_bot_id

def extract_platform_bot_id(channel_type: str, credentials: dict) -> str

执行 extract_platform_bot_id 方法。

Read the bot-identifying credential field, for uniqueness.

参数Parameters
名称Name类型Type说明Description
channel_typestr平台类型标识。The platform type id.
credentialsdict凭证(类型 `dict`)。Raw credentials to read the bot id from.
返回Returns str
返回字符串结果。Returns a string.
源码Source agentscope/app/channel/_registry.py:150–172
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.