AS AgentScopeAPI 手册 / API Reference
类class agentscope.credential

CredentialFactory

class CredentialFactory
源码Source agentscope/credential/_factory.py:20–120

凭证工厂,与模型服务通信并返回生成或向量化结果。位于 agentscope.credential 包。核心成员包括 register_credential、from_dict、get_credential_class、list_schemas。

Built-in credential types are pre-registered. Call :meth:register_credential to add custom types before starting the app.

Usage::

# Deserialize from storage
credential = CredentialFactory.from_dict(record.data)

# Register a custom type
CredentialFactory.register_credential(MyCredential)

# List schemas for the frontend form
schemas = CredentialFactory.list_schemas()

方法摘要Method Summary

方法Method说明Description
def register_credential(credential_cls: Type[CredentialBase]) -> None
注册凭证。
Register a custom :class:`CredentialBase` subclass.
def from_dict(data: dict) -> CredentialBase
设置该参数。
Deserialize a credential dict (from storage) to a typed instance.
def get_credential_class(provider: str) -> Type[CredentialBase] | None
获取凭证类。
Return the credential class for the given provider type, or None.
def list_schemas() -> list[dict]
返回JSON 模式用于所有已注册凭证类型。
Return JSON schemas for all registered credential types.

方法详情Method Detail

register_credential

def register_credential(credential_cls: Type[CredentialBase]) -> None

注册凭证。

The class must define a type field with a unique Literal default so Pydantic can use it as a discriminator.

参数Parameters
名称Name类型Type说明Description
credential_clsType[CredentialBase]凭证 cls(类型 `Type[CredentialBase]`)。The subclass to register.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/credential/_factory.py:63–75

from_dict

def from_dict(data: dict) -> CredentialBase

设置该参数。

Deserialize a credential dict (from storage) to a typed instance.

参数Parameters
名称Name类型Type说明Description
datadict数据(类型 `dict`)。Raw dict containing a `"type"` key.
返回Returns CredentialBase
返回CredentialBase。A typed :class:`CredentialBase` subclass instance.
源码Source agentscope/credential/_factory.py:78–87

get_credential_class

def get_credential_class(provider: str) -> Type[CredentialBase] | None

获取凭证类。

Return the credential class for the given provider type, or None.

参数Parameters
名称Name类型Type说明Description
providerstr提供者(类型 `str`)。The `type` discriminator value (e.g. `"openai"`).
返回Returns Type[CredentialBase] | None
返回类型[CredentialBase]|None。The matching :class:`CredentialBase` subclass, or `None` if not
源码Source agentscope/credential/_factory.py:90–112

list_schemas

def list_schemas() -> list[dict]

返回JSON 模式用于所有已注册凭证类型。

Used by the frontend to render credential forms dynamically.

返回Returns list[dict]
返回dict列表。Returns a list of dict.
源码Source agentscope/credential/_factory.py:115–120
基于官方固定版本源码静态生成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.