AS AgentScopeAPI 手册 / API Reference

ModelCreationContext

public final class ModelCreationContext
源码Source io/agentscope/core/model/ModelCreationContext.java:43–290

模型 Creation 上下文,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.model 包。核心成员包括 empty、builder、toBuilder、getApiKey、getBaseUrl、getEndpointPath。

Provider-neutral model creation context used by ModelRegistry and model provider SPI implementations.

This type has two layers:

  • Standard fields such as apiKey, baseUrl, endpointPath, stream, and enableThinking. These are common enough to be understood by multiple providers and can safely participate in automatic cache identity when CachePolicy#ENABLED is selected.

  • Provider-specific options (#option(String)) and typed components (#component(Class)). These allow extension modules to consume advanced builder settings such as formatters, HTTP transports, credentials, proxies, and default generation options without adding provider types to core.

Options and components are intentionally opaque to core. ModelRegistry never deep hashes them or uses their hashCode() values for cache identity. When they are present and caching is enabled, callers must provide an explicit Builder#cacheId(String).

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
A class in io.agentscope.core.model that talks to model services and returns generated or embedded output.

方法摘要Method Summary

方法Method说明Description
public static ModelCreationContext empty()
static
返回 `empty` 结果。
Returns the empty.
public static Builder builder()
static
返回构建器实例。
Returns the builder.
public Builder toBuilder()
返回可变构建器已初始化来自此上下文。
Returns a mutable builder initialized from this context.
public String getApiKey()
获取API 键。
API key or token to pass to a provider.
public String getBaseUrl()
获取基类 URL。
Provider base URL override, for self-hosted or compatible API endpoints.
public String getEndpointPath()
获取端点路径。
Provider endpoint path override, mainly for OpenAI-compatible APIs.
public Boolean getStream()
获取流。
Whether the created model should use streaming by default.
public Boolean getEnableThinking()
获取 `getEnableThinking`。
Whether provider thinking/reasoning mode should be enabled.
public CachePolicy getCachePolicy()
用于`ModelRegistry#resolve(String, ModelCreationContext)`的缓存策略。
Cache policy for `ModelRegistry#resolve(String, ModelCreationContext)`.
public String getCacheId()
获取缓存标识。
Explicit cache identity used when `#getCachePolicy()` is `CachePolicy#ENABLED`.
public Map<String, Object> getOptions()
获取选项。
Provider-specific scalar or value options keyed by extension-defined names.
public Object option(String key)
设置选项。
Returns a provider-specific option value, or `null`.
public T T option(String key, Class<T> type)
执行选项相关操作。
Returns a provider-specific option cast to the requested type, or `null`.
public Map<Class<?>, Object> getComponents()
获取 `getComponents`。
Provider-specific component objects keyed by type.
public T T component(Class<T> type)
设置该参数。
Returns a provider-specific component by type, or `null`.
public boolean isEmpty()
判断是否 `isEmpty`。
Returns whether this context has no effective settings.
public boolean hasOpaqueCacheInputs()
判断是否具有 `hasOpaqueCacheInputs`。
Returns whether the context contains values that core cannot fingerprint safely.
public String toString()
返回 `toString` 结果。
Returns the to string.

方法详情Method Detail

empty

public static ModelCreationContext empty()
static

返回 empty 结果。

Returns the empty.

返回Returns ModelCreationContext
返回ModelCreationContext。Returns model creation context.
源码Source io/agentscope/core/model/ModelCreationContext.java:69–71

builder

public static Builder builder()
static

返回构建器实例。

Returns the builder.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/core/model/ModelCreationContext.java:73–75

toBuilder

public Builder toBuilder()

返回可变构建器已初始化来自此上下文。

Returns a mutable builder initialized from this context.

返回Returns Builder
返回当前实例,以支持链式调用。Returns the current instance for chaining.
源码Source io/agentscope/core/model/ModelCreationContext.java:83–85

getApiKey

public String getApiKey()

获取API 键。

API key or token to pass to a provider.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/model/ModelCreationContext.java:88–90

getBaseUrl

public String getBaseUrl()

获取基类 URL。

Provider base URL override, for self-hosted or compatible API endpoints.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/model/ModelCreationContext.java:93–95

getEndpointPath

public String getEndpointPath()

获取端点路径。

Provider endpoint path override, mainly for OpenAI-compatible APIs.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/model/ModelCreationContext.java:98–100

getStream

public Boolean getStream()

获取流。

Whether the created model should use streaming by default.

返回Returns Boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/model/ModelCreationContext.java:103–105

getEnableThinking

public Boolean getEnableThinking()

获取 getEnableThinking。

Whether provider thinking/reasoning mode should be enabled.

返回Returns Boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/model/ModelCreationContext.java:108–110

getCachePolicy

public CachePolicy getCachePolicy()

用于ModelRegistry#resolve(String, ModelCreationContext)的缓存策略。

Cache policy for ModelRegistry#resolve(String, ModelCreationContext).

返回Returns CachePolicy
返回CachePolicy。Returns cache policy.
源码Source io/agentscope/core/model/ModelCreationContext.java:113–115

getCacheId

public String getCacheId()

获取缓存标识。

Explicit cache identity used when #getCachePolicy() is CachePolicy#ENABLED.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/model/ModelCreationContext.java:118–120

getOptions

public Map<String, Object> getOptions()

获取选项。

Provider-specific scalar or value options keyed by extension-defined names.

返回Returns Map<String, Object>
返回映射。Returns map.
源码Source io/agentscope/core/model/ModelCreationContext.java:123–125

option

public Object option(String key)

设置选项。

Returns a provider-specific option value, or null.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key.
返回Returns Object
返回对象。Returns object.
源码Source io/agentscope/core/model/ModelCreationContext.java:128–130

option

public T T option(String key, Class<T> type)

执行选项相关操作。

Returns a provider-specific option cast to the requested type, or null.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key.
typeClass<T>类型(类型 `Class`)。The type.
返回Returns T
返回T。Returns t.
源码Source io/agentscope/core/model/ModelCreationContext.java:133–136

getComponents

public Map<Class<?>, Object> getComponents()

获取 getComponents。

Provider-specific component objects keyed by type.

返回Returns Map<Class<?>, Object>
返回映射,对象>。Returns map object.
源码Source io/agentscope/core/model/ModelCreationContext.java:139–141

component

public T T component(Class<T> type)

设置该参数。

Returns a provider-specific component by type, or null.

参数Parameters
名称Name类型Type说明Description
typeClass<T>类型(类型 `Class`)。The type.
返回Returns T
返回T。Returns t.
源码Source io/agentscope/core/model/ModelCreationContext.java:144–147

isEmpty

public boolean isEmpty()

判断是否 isEmpty。

Returns whether this context has no effective settings.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/model/ModelCreationContext.java:154–164

hasOpaqueCacheInputs

public boolean hasOpaqueCacheInputs()

判断是否具有 hasOpaqueCacheInputs。

Returns whether the context contains values that core cannot fingerprint safely.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/model/ModelCreationContext.java:167–169

toString

public String toString()

返回 toString 结果。

Returns the to string.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/model/ModelCreationContext.java:171–196

嵌套类详情Nested Class Detail

Builder

public static final class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.core.model 包。核心成员包括 apiKey、baseUrl、endpointPath、stream、enableThinking、cachePolicy。

A class in io.agentscope.core.model 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.