AS AgentScopeAPI 手册 / API Reference

Builder

public static class Builder
源码Source io/agentscope/core/model/GenerateOptions.java:518–902

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

A class in io.agentscope.core.model that talks to model services and returns generated or embedded output. Declared in io.agentscope.core.model.

方法摘要Method Summary

方法Method说明Description
public Builder apiKey(String apiKey)
设置API 键。
Sets the API key for authentication.
public Builder baseUrl(String baseUrl)
设置基类 URL 用于 API 端点。
Sets the base URL for the API endpoint.
public Builder endpointPath(String endpointPath)
设置端点路径用于 API 请求。
Sets the endpoint path for the API request.
public Builder modelName(String modelName)
设置模型名称。
Sets the model name to use for generation.
public Builder stream(Boolean stream)
设置流。
Sets whether streaming mode is enabled.
public Builder temperature(Double temperature)
设置该配置项。
Sets the temperature for text generation.
public Builder topP(Double topP)
设置该配置项。
Sets the top-p (nucleus sampling) parameter.
public Builder maxTokens(Integer maxTokens)
设置最大令牌数。
Sets the maximum number of tokens to generate.
public Builder maxCompletionTokens(Integer maxCompletionTokens)
设置最大补全令牌数。
Sets the maximum number of completion tokens to generate.
public Builder frequencyPenalty(Double frequencyPenalty)
设置该配置项。
Sets the frequency penalty.
public Builder presencePenalty(Double presencePenalty)
设置该配置项。
Sets the presence penalty.
public Builder thinkingBudget(Integer thinkingBudget)
设置该配置项。
Sets the thinking budget (maximum tokens for reasoning/thinking content).
public Builder reasoningEffort(String reasoningEffort)
设置该配置项。
Sets the reasoning effort level for o1 models.
public Builder executionConfig(ExecutionConfig executionConfig)
设置执行配置用于超时和重试行为。
Sets the execution configuration for timeout and retry behavior.
public Builder toolChoice(ToolChoice toolChoice)
设置工具选项。
Sets the tool choice configuration for controlling how the model uses tools.
public Builder topK(Integer topK)
设置该配置项。
Sets the top-k sampling parameter.
public Builder seed(Long seed)
设置预置。
Sets the random seed for deterministic generation.
public Builder cacheControl(Boolean cacheControl)
设置该配置项。
Sets whether cache control is enabled for prompt caching.
public Builder parallelToolCalls(Boolean parallelToolCalls)
设置该配置项。
Sets whether to enable parallel function calling during tool use.
public Builder responseFormat(ResponseFormat responseFormat)
设置响应格式用于结构化输出。
Sets the response format for structured output.
public Builder additionalHeader(String key, String value)
执行 `additionalHeader` 方法。
Adds an additional HTTP header to include in API requests.
public Builder additionalHeaders(Map<String, String> headers)
设置该参数。
Sets all additional HTTP headers to include in API requests.
public Builder additionalBodyParam(String key, Object value)
执行 `additionalBodyParam` 方法。
Adds an additional parameter to include in the request body.
public Builder additionalBodyParams(Map<String, Object> params)
设置该参数。
Sets all additional parameters to include in the request body.
public Builder additionalQueryParam(String key, String value)
执行 `additionalQueryParam` 方法。
Adds an additional query parameter to include in API requests.
public Builder additionalQueryParams(Map<String, String> params)
设置该参数。
Sets all additional query parameters to include in API requests.
public GenerateOptions build()
构建新的GenerateOptions 实例使用设置值。
Builds a new GenerateOptions instance with the set values.

方法详情Method Detail

apiKey

public Builder apiKey(String apiKey)

设置API 键。

Sets the API key for authentication.

参数Parameters
名称Name类型Type说明Description
apiKeyStringAPI 密钥。the API key
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:552–555

baseUrl

public Builder baseUrl(String baseUrl)

设置基类 URL 用于 API 端点。

Sets the base URL for the API endpoint.

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL。the base URL
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:563–566

endpointPath

public Builder endpointPath(String endpointPath)

设置端点路径用于 API 请求。

Sets the endpoint path for the API request.

参数Parameters
名称Name类型Type说明Description
endpointPathString端点路径(类型 `String`)。the endpoint path (e.g., "/v1/chat/completions")
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:578–581

modelName

public Builder modelName(String modelName)

设置模型名称。

Sets the model name to use for generation.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称(类型 `String`)。the model name (e.g., "gpt-4", "gpt-3.5-turbo")
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:589–592

stream

public Builder stream(Boolean stream)

设置流。

Sets whether streaming mode is enabled.

参数Parameters
名称Name类型Type说明Description
streamBoolean流(类型 `Boolean`)。true for streaming, false for non-streaming
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:600–603

temperature

public Builder temperature(Double temperature)

设置该配置项。

Sets the temperature for text generation.

参数Parameters
名称Name类型Type说明Description
temperatureDoubletemperature(类型 `Double`)。the temperature value between 0 and 2
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:614–617

topP

public Builder topP(Double topP)

设置该配置项。

Sets the top-p (nucleus sampling) parameter.

参数Parameters
名称Name类型Type说明Description
topPDoubletop P(类型 `Double`)。the top-p value between 0 and 1
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:628–631

maxTokens

public Builder maxTokens(Integer maxTokens)

设置最大令牌数。

Sets the maximum number of tokens to generate.

参数Parameters
名称Name类型Type说明Description
maxTokensInteger最大令牌数(类型 `Integer`)。the maximum tokens limit
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:639–642

maxCompletionTokens

public Builder maxCompletionTokens(Integer maxCompletionTokens)

设置最大补全令牌数。

Sets the maximum number of completion tokens to generate.

参数Parameters
名称Name类型Type说明Description
maxCompletionTokensInteger最大补全令牌数(类型 `Integer`)。the maximum completion tokens limit
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:655–658

frequencyPenalty

public Builder frequencyPenalty(Double frequencyPenalty)

设置该配置项。

Sets the frequency penalty.

参数Parameters
名称Name类型Type说明Description
frequencyPenaltyDoublefrequency Penalty(类型 `Double`)。the frequency penalty between -2 and 2
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:669–672

presencePenalty

public Builder presencePenalty(Double presencePenalty)

设置该配置项。

Sets the presence penalty.

参数Parameters
名称Name类型Type说明Description
presencePenaltyDouble在线状态 Penalty(类型 `Double`)。the presence penalty between -2 and 2
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:683–686

thinkingBudget

public Builder thinkingBudget(Integer thinkingBudget)

设置该配置项。

Sets the thinking budget (maximum tokens for reasoning/thinking content).

参数Parameters
名称Name类型Type说明Description
thinkingBudgetIntegerthinking 预算(类型 `Integer`)。the maximum tokens for thinking content
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/core/model/GenerateOptions.java:698–701

reasoningEffort

public Builder reasoningEffort(String reasoningEffort)

设置该配置项。

Sets the reasoning effort level for o1 models.

参数Parameters
名称Name类型Type说明Description
reasoningEffortString推理 Effort(类型 `String`)。the reasoning effort level
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/core/model/GenerateOptions.java:712–715

executionConfig

public Builder executionConfig(ExecutionConfig executionConfig)

设置执行配置用于超时和重试行为。

Sets the execution configuration for timeout and retry behavior.

参数Parameters
名称Name类型Type说明Description
executionConfigExecutionConfig执行配置(类型 `ExecutionConfig`)。the execution configuration, or null to disable
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:726–729

toolChoice

public Builder toolChoice(ToolChoice toolChoice)

设置工具选项。

Sets the tool choice configuration for controlling how the model uses tools.

另见See also @see ToolChoice
参数Parameters
名称Name类型Type说明Description
toolChoiceToolChoice工具选项(类型 `ToolChoice`)。the tool choice configuration, or null for default (auto)
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:747–750

topK

public Builder topK(Integer topK)

设置该配置项。

Sets the top-k sampling parameter.

参数Parameters
名称Name类型Type说明Description
topKIntegertop K(类型 `Integer`)。the top-k value
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:761–764

seed

public Builder seed(Long seed)

设置预置。

Sets the random seed for deterministic generation.

参数Parameters
名称Name类型Type说明Description
seedLong预置值。the seed value
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:775–778

cacheControl

public Builder cacheControl(Boolean cacheControl)

设置该配置项。

Sets whether cache control is enabled for prompt caching.

参数Parameters
名称Name类型Type说明Description
cacheControlBoolean缓存 Control(类型 `Boolean`)。true to enable cache control, false to disable
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:789–792

parallelToolCalls

public Builder parallelToolCalls(Boolean parallelToolCalls)

设置该配置项。

Sets whether to enable parallel function calling during tool use.

参数Parameters
名称Name类型Type说明Description
parallelToolCallsBooleanparallel 工具调用(类型 `Boolean`)。true to enable parallel tool calls, false to disable
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:800–803

responseFormat

public Builder responseFormat(ResponseFormat responseFormat)

设置响应格式用于结构化输出。

Sets the response format for structured output.

参数Parameters
名称Name类型Type说明Description
responseFormatResponseFormat响应格式配置。the response format configuration
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:811–814

additionalHeader

public Builder additionalHeader(String key, String value)

执行 additionalHeader 方法。

Adds an additional HTTP header to include in API requests.

参数Parameters
名称Name类型Type说明Description
keyString请求头名称。the header name
valueString请求头值。the header value
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:823–829

additionalHeaders

public Builder additionalHeaders(Map<String, String> headers)

设置该参数。

Sets all additional HTTP headers to include in API requests.

参数Parameters
名称Name类型Type说明Description
headersMap<String, String>请求头映射。the headers map
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:837–840

additionalBodyParam

public Builder additionalBodyParam(String key, Object value)

执行 additionalBodyParam 方法。

Adds an additional parameter to include in the request body.

参数Parameters
名称Name类型Type说明Description
keyString参数名称。the parameter name
valueObject参数值。the parameter value
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:849–855

additionalBodyParams

public Builder additionalBodyParams(Map<String, Object> params)

设置该参数。

Sets all additional parameters to include in the request body.

参数Parameters
名称Name类型Type说明Description
paramsMap<String, Object>参数映射。the parameters map
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:863–866

additionalQueryParam

public Builder additionalQueryParam(String key, String value)

执行 additionalQueryParam 方法。

Adds an additional query parameter to include in API requests.

参数Parameters
名称Name类型Type说明Description
keyString参数名称。the parameter name
valueString参数值。the parameter value
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:875–881

additionalQueryParams

public Builder additionalQueryParams(Map<String, String> params)

设置该参数。

Sets all additional query parameters to include in API requests.

参数Parameters
名称Name类型Type说明Description
paramsMap<String, String>参数映射。the parameters map
返回Returns Builder
返回当前实例,以支持链式调用。this builder instance
源码Source io/agentscope/core/model/GenerateOptions.java:889–892

build

public GenerateOptions build()

构建新的GenerateOptions 实例使用设置值。

Builds a new GenerateOptions instance with the set values.

返回Returns GenerateOptions
一种新的GenerateOptions 实例。a new GenerateOptions instance
源码Source io/agentscope/core/model/GenerateOptions.java:899–901
基于官方固定版本源码静态生成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.