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

ChannelClients

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
storageStorageBase存储(类型 `StorageBase`)。Source of channel records.
message_busMessageBus消息总线(类型 `MessageBus`)。Where a delivery reads the run's events from.
type_registryChannelTypeRegistry类型注册表(类型 `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.

返回Returns '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_typetype[BaseException] | Noneexc 类型(类型 `type[BaseException] | None`)。The exc type.
excBaseException | Noneexc(类型 `BaseException | None`)。The exc.
tbTracebackType | Nonetb(类型 `TracebackType | None`)。The tb.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/channel/_clients.py:76–97

get

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_idstr渠道到构建客户端用于。The channel to build a client for.
返回Returns ChannelBase | None
返回ChannelBase|None。`ChannelBase | None`: The instance, or `None` when the
源码Source agentscope/app/channel/_clients.py:114–155

deliver

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_idkwstr会话标识(类型 `str`)。The run whose reply is delivered.
channel_idkwstr渠道标识(类型 `str`)。The channel the session came from.
chat_idkwstr聊天标识(类型 `str`)。The platform chat to deliver into.
agent_idkwstr智能体标识(类型 `str`)。The agent that owns the session; pinned on a confirmation card so a click resumes this exact run.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/channel/_clients.py:157–230
基于官方固定版本源码静态生成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.