类class
agentscope.app.channelChannelClients
class ChannelClients
源码Source
agentscope/app/channel/_clients.py:47–230渠道客户端,封装与远端服务的连接和调用。位于 agentscope.app.channel 包。核心成员包括 get、deliver。
Builds and caches unconnected channel instances by channel id. Declared in agentscope.app.channel.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(storage: StorageBase, message_bus: MessageBus, type_registry: ChannelTypeRegistry) -> None | 初始化 `ChannelClients` 实例。 Bind storage, the bus, and the registry of channel classes. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def __aenter__() -> 'ChannelClients'async | 进入异步上下文并返回自身。 Enter the factory's lifecycle; nothing is built up front. |
async def __aexit__(exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> Noneasync | 退出异步上下文并清理资源。 Stop delivering, then release every instance built here. |
async def get(channel_id: str) -> ChannelBase | Noneasync | 返回实例用于`channel_id`,或`None`。 Return an instance for ``channel_id``, or ``None``. |
async def deliver(*, session_id: str, channel_id: str, chat_id: str, agent_id: str) -> Noneasync | 执行 `deliver` 方法。 Start streaming a run's reply back to its platform chat. |
构造器详情Constructor Detail
ChannelClients
def __init__(storage: StorageBase, message_bus: MessageBus, type_registry: ChannelTypeRegistry) -> None
初始化 ChannelClients 实例。
Bind storage, the bus, and the registry of channel classes.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
storage | StorageBase | 存储(类型 `StorageBase`)。Source of channel records. |
message_bus | MessageBus | 消息总线(类型 `MessageBus`)。Where a delivery reads the run's events from. |
type_registry | ChannelTypeRegistry | 类型注册表(类型 `ChannelTypeRegistry`)。Builds instances from a record's type, credentials and config. |
源码Source
agentscope/app/channel/_clients.py:50–70方法详情Method Detail
__aenter__
async def __aenter__() -> 'ChannelClients'
async
进入异步上下文并返回自身。
Enter the factory's lifecycle; nothing is built up front.
'ChannelClients'
返回'ChannelClients'。Returns channel clients.
源码Source
agentscope/app/channel/_clients.py:72–74__aexit__
async def __aexit__(exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None
async
退出异步上下文并清理资源。
Deliveries go first: they are what borrows the instances, so nothing is using one by the time it is closed.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc_type | type[BaseException] | None | exc 类型(类型 `type[BaseException] | None`)。The exc type. |
exc | BaseException | None | exc(类型 `BaseException | None`)。The exc. |
tb | TracebackType | None | tb(类型 `TracebackType | None`)。The tb. |
None
无返回值。No value is returned.
源码Source
agentscope/app/channel/_clients.py:76–97get
async def get(channel_id: str) -> ChannelBase | None
async
返回实例用于channel_id,或None。
Never calls start_listening, so this opens no connection and starts no background task — only the platform's REST surface is usable on the returned instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_id | str | 渠道到构建客户端用于。The channel to build a client for. |
ChannelBase | None
返回ChannelBase|None。`ChannelBase | None`: The instance, or `None` when the
源码Source
agentscope/app/channel/_clients.py:114–155deliver
async def deliver(*, session_id: str, channel_id: str, chat_id: str, agent_id: str) -> None
async
执行 deliver 方法。
Returns as soon as the delivery is under way — the caller is mid-run and must not wait on the platform.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
session_idkw | str | 会话标识(类型 `str`)。The run whose reply is delivered. |
channel_idkw | str | 渠道标识(类型 `str`)。The channel the session came from. |
chat_idkw | str | 聊天标识(类型 `str`)。The platform chat to deliver into. |
agent_idkw | str | 智能体标识(类型 `str`)。The agent that owns the session; pinned on a confirmation card so a click resumes this exact run. |
None
无返回值。No value is returned.
源码Source
agentscope/app/channel/_clients.py:157–230