AS AgentScopeAPI 手册 / API Reference

ModelRegistry

public final class ModelRegistry
源码Source io/agentscope/core/model/ModelRegistry.java:44–428

模型注册表,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.model 包。核心成员包括 register、registerFactory、resolve、canResolve、reset、reloadProviders。

Registry for resolving Model instances from string identifiers (named instances or provider:model patterns). User-registered factories take precedence over providers loaded from the ModelProvider SPI.

Provider extension modules read API keys from their own standard environment variables when auto-creating models.

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
ModelFactory接口interface
定义模型工厂契约的接口。
An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output.
ContextModelFactory接口interface
定义上下文模型工厂契约的接口。
An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output.

方法摘要Method Summary

方法Method说明Description
public static void register(String name, Model model)
static
执行注册相关操作。
Registers a named `Model` instance.
public static void registerFactory(String modelNameRegex, ModelFactory factory)
static
注册工厂。
Registers a factory matched against the full `modelId` string using `Pattern#matches`.
public static void registerFactory(String modelNameRegex, ContextModelFactory factory)
static
注册工厂。
Registers a context-aware factory matched against the full `modelId` string using `Pattern#matches`.
public static Model resolve(String modelId)
static
设置解析。
Resolves a `Model` for the given id: named registration first, then cached factory-created instance, then user factories (newest first), then SPI providers.
public static Model resolve(String modelId, ModelCreationContext context)
static
执行解析相关操作。
Resolves a `Model` for the given id and creation context: named registration first, then cache when enabled, then user factories (newest first), then SPI providers.
public static boolean canResolve(String modelId)
static
判断是否可以解析。
Returns `true` if `#resolve(String)` can find a named model or a matching factory/ provider pattern (without creating an instance).
public static boolean canResolve(String modelId, ModelCreationContext context)
static
判断是否可以解析。
Returns `true` if `#resolve(String, ModelCreationContext)` can find a named model or a matching factory/provider pattern (without creating an instance).
public static void reset()
static
清空或重置内部状态。
Clears named models, user-registered factories, the factory-resolution cache, and cached SPI providers.
public static void reloadProviders()
static
执行 `reloadProviders` 方法。
Clears the cached SPI providers so the next resolution can rediscover providers from the current classloader context.

方法详情Method Detail

register

public static void register(String name, Model model)
static

执行注册相关操作。

Registers a named Model instance.

参数Parameters
名称Name类型Type说明Description
nameString名称(类型 `String`)。The name.
modelModel模型实例(类型 `Model`)。The model.
源码Source io/agentscope/core/model/ModelRegistry.java:61–65

registerFactory

public static void registerFactory(String modelNameRegex, ModelFactory factory)
static

注册工厂。

Registers a factory matched against the full modelId string using Pattern#matches.

参数Parameters
名称Name类型Type说明Description
modelNameRegexString模型名称 Regex(类型 `String`)。regex with semantics of Pattern#matches(CharSequence) on the full model id
factoryModelFactory工厂(类型 `ModelFactory`)。creates a `Model` from the full model id
源码Source io/agentscope/core/model/ModelRegistry.java:76–80

registerFactory

public static void registerFactory(String modelNameRegex, ContextModelFactory factory)
static

注册工厂。

Registers a context-aware factory matched against the full modelId string using Pattern#matches.

参数Parameters
名称Name类型Type说明Description
modelNameRegexString模型名称 Regex(类型 `String`)。regex with semantics of Pattern#matches(CharSequence) on the full model id
factoryContextModelFactory工厂(类型 `ContextModelFactory`)。creates a `Model` from the full model id and creation context
源码Source io/agentscope/core/model/ModelRegistry.java:91–96

resolve

public static Model resolve(String modelId)
static

设置解析。

Resolves a Model for the given id: named registration first, then cached factory-created instance, then user factories (newest first), then SPI providers.

参数Parameters
名称Name类型Type说明Description
modelIdString模型标识(类型 `String`)。The model id.
返回Returns Model
返回模型。Returns model.
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if the id cannot be resolved or creation fails
源码Source io/agentscope/core/model/ModelRegistry.java:104–106

resolve

public static Model resolve(String modelId, ModelCreationContext context)
static

执行解析相关操作。

Resolves a Model for the given id and creation context: named registration first, then cache when enabled, then user factories (newest first), then SPI providers.

参数Parameters
名称Name类型Type说明Description
modelIdString模型标识(类型 `String`)。The model id.
contextModelCreationContext上下文(类型 `ModelCreationContext`)。The context.
返回Returns Model
返回模型。Returns model.
抛出Throws
  • IllegalArgumentException 可能抛出 `IllegalArgumentException`。if the id cannot be resolved, the context cannot be safely cached, or creation fails
源码Source io/agentscope/core/model/ModelRegistry.java:118–167

canResolve

public static boolean canResolve(String modelId)
static

判断是否可以解析。

Returns true if #resolve(String) can find a named model or a matching factory/ provider pattern (without creating an instance).

参数Parameters
名称Name类型Type说明Description
modelIdString模型标识(类型 `String`)。The model id.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/model/ModelRegistry.java:173–175

canResolve

public static boolean canResolve(String modelId, ModelCreationContext context)
static

判断是否可以解析。

Returns true if #resolve(String, ModelCreationContext) can find a named model or a matching factory/provider pattern (without creating an instance).

参数Parameters
名称Name类型Type说明Description
modelIdString模型标识(类型 `String`)。The model id.
contextModelCreationContext上下文(类型 `ModelCreationContext`)。The context.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/model/ModelRegistry.java:181–195

reset

public static void reset()
static

清空或重置内部状态。

Clears named models, user-registered factories, the factory-resolution cache, and cached SPI providers.

源码Source io/agentscope/core/model/ModelRegistry.java:201–206

reloadProviders

public static void reloadProviders()
static

执行 reloadProviders 方法。

Clears the cached SPI providers so the next resolution can rediscover providers from the current classloader context.

源码Source io/agentscope/core/model/ModelRegistry.java:212–214

嵌套类详情Nested Class Detail

ModelFactory

@FunctionalInterface public interface ModelFactory

定义模型工厂契约的接口。位于 io.agentscope.core.model 包。核心成员包括 create。

An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output. Declared in io.agentscope.core.model.

ContextModelFactory

@FunctionalInterface public interface ContextModelFactory

定义上下文模型工厂契约的接口。位于 io.agentscope.core.model 包。核心成员包括 create。

An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output. Declared in io.agentscope.core.model.

基于官方固定版本源码静态生成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.