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

HubBase

class HubBase
源码Source agentscope/app/hub/_base.py:10–72

中心基类,把智能体接入外部消息渠道与企业平台。位于 agentscope.app.hub 包。

A hub is addressed by :attr:hub_id in the HTTP routes, and a card is addressed globally by the (hub_id, card_id) pair, so the id must stay stable across restarts.

Hubs are entered once by the app lifespan and live as long as the process, so an implementation talking to a registry over HTTP can hold one client across requests instead of paying for a fresh handshake on every page of a catalog.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(hub_id: str, display_name: str, description: str = '', icon_url: str | None = None) -> None
初始化 `HubBase` 实例。
Initialize the hub identity.

方法摘要Method Summary

方法Method说明Description
async def __aenter__() -> Selfasync
进入异步上下文并返回自身。
Enter the hub — open whatever it talks to the registry with.
async def __aexit__(*exc: Any) -> Noneasync
退出异步上下文并清理资源。
Exit the hub — close what :meth:`__aenter__` opened.

构造器详情Constructor Detail

HubBase

def __init__(hub_id: str, display_name: str, description: str = '', icon_url: str | None = None) -> None

初始化 HubBase 实例。

Initialize the hub identity.

参数Parameters
名称Name类型Type说明Description
hub_idstr中心标识(类型 `str`)。The stable identifier addressing this hub. Must match `[a-zA-Z0-9_-]+` and be unique among the hubs of the same kind registered on one app.
display_namestr展示名称(类型 `str`)。The user-facing hub name.
description默认default ''str描述(类型 `str`)。The user-facing hub description.
icon_url默认default Nonestr | Noneicon URL(类型 `str | None`)。An image identifying the hub in the picker. `None` leaves the UI to fall back rather than show a gap.
异常Raises
  • 可能抛出 `Exception`。`ValueError`:
  • 可能抛出 `Exception`。When `hub_id` is not usable as a URL path segment.
源码Source agentscope/app/hub/_base.py:23–57

方法详情Method Detail

__aenter__

async def __aenter__() -> Self
async

进入异步上下文并返回自身。

The default is a no-op, so a hub with nothing to open needs no boilerplate.

返回Returns Self
返回自身。`HubBase`:
源码Source agentscope/app/hub/_base.py:59–69

__aexit__

async def __aexit__(*exc: Any) -> None
async

退出异步上下文并清理资源。

Exit the hub — close what :meth:__aenter__ opened.

参数Parameters
名称Name类型Type说明Description
excAnyexc(类型 `Any`)。The exc.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/hub/_base.py:71–72
基于官方固定版本源码静态生成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.