AS AgentScopeAPI 手册 / API Reference
包package agentscope

agentscope

module agentscope

agentscope 属于基础设施,类型、异常、传输与工具函数。 该包共收录 5 个公开类型。

The agentscope package.

源码Source agentscope/__init__.py:1

子包Subpackages

函数Functions

set_id_factory
函数function
覆盖全局 ID 工厂
Override the global ID factory used by all AgentScope entities.
set_timestamp_factory
函数function
覆盖全局时间戳工厂
Override the global timestamp factory used by all AgentScope entities.
setup_logger
函数function
初始化日志记录器
Set up the agentscope logger.

属性Attributes

__version__
字段attribute
—
logger
字段attribute
—

函数详情Function Details

set_id_factory

def set_id_factory(factory: Callable[[], str]) -> None

替换 AgentScope 所有实体使用的 ID 生成策略;应在创建任何实体前调用,常用于测试或自定义标识。

Entity IDs default to uuid.uuid4().hex.

示例Example

>>> from agentscope import set_id_factory
    >>> set_id_factory(lambda: uuid7().hex)

说明Notes

  • 注意:该行为受运行时配置或底层实现影响,建议结合对应源码与版本说明确认。Note: Security-sensitive tokens (gateway tokens, Redis lock tokens) are **not** affected and always use `uuid.uuid4().hex`.
参数Parameters
名称Name类型Type说明Description
factoryCallable[[], str]工厂(类型 `Callable[[], str]`)。A no-arg callable returning a string ID.
返回Returns None
无返回值。No value is returned.
异常Raises
  • TypeError 可能抛出 `TypeError`。If `factory` is not callable.
源码Source agentscope/_utils/_common.py:32–58

set_timestamp_factory

def set_timestamp_factory(factory: Callable[[], str]) -> None

替换 AgentScope 所有实体使用的时间戳生成策略;应在创建任何实体前调用,便于测试与回放。

Override the global timestamp factory used by all AgentScope entities.

参数Parameters
名称Name类型Type说明Description
factoryCallable[[], str]工厂(类型 `Callable[[], str]`)。A no-arg callable returning a string ID.
返回Returns None
无返回值。No value is returned.
异常Raises
  • TypeError 可能抛出 `TypeError`。If `factory` is not callable.
源码Source agentscope/_utils/_common.py:61–76

setup_logger

def setup_logger(level: str, filepath: str | None = None) -> None

配置 agentscope 日志的级别、格式与输出目标,统一框架与业务侧的日志观测。

Set up the agentscope logger.

参数Parameters
名称Name类型Type说明Description
levelstr级别(类型 `str`)。The logging level, chosen from "INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL".
filepath默认default Nonestr | Nonefilepath(类型 `str | None`)。The filepath to save the logging output.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/_logging.py:15–44

属性详情Attribute Details

__version__

 = '2.0.11'

版本字段。

The version field.

源码Source agentscope/_version.py:4

logger

 = logging.getLogger('as')

日志记录器字段。

The logger field.

源码Source agentscope/_logging.py:12
基于官方固定版本源码静态生成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.