Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public void applyOptions(
if (presencePenalty != null) {
params.setPresencePenalty(presencePenalty);
}

// Apply parallel tool calls
Boolean parallelToolCalls =
getOption(options, defaultOptions, GenerateOptions::getParallelToolCalls);
if (parallelToolCalls != null) {
params.setParallelToolCalls(parallelToolCalls);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ public class DashScopeParameters {
@JsonProperty("enable_thinking")
private Boolean enableThinking;

/** Token budget for thinking. */
@JsonProperty("thinking_budget")
private Integer thinkingBudget;

/** Enable search mode. */
@JsonProperty("enable_search")
private Boolean enableSearch;

/** Token budget for thinking. */
@JsonProperty("thinking_budget")
private Integer thinkingBudget;
/** Strategies for web search. */
@JsonProperty("search_options")
private DashScopeSearchOptions searchOptions;

/** Enable code interpreter mode. */
@JsonProperty("enable_code_interpreter")
private Boolean enableCodeInterpreter;

/** List of available tools. */
@JsonProperty("tools")
Expand All @@ -79,6 +87,10 @@ public class DashScopeParameters {
@JsonProperty("tool_choice")
private Object toolChoice;

/** Whether to enable parallel tool calls. */
@JsonProperty("parallel_tool_calls")
private Boolean parallelToolCalls;

/** Random seed for reproducibility. */
@JsonProperty("seed")
private Integer seed;
Expand Down Expand Up @@ -181,6 +193,22 @@ public void setEnableSearch(Boolean enableSearch) {
this.enableSearch = enableSearch;
}

public DashScopeSearchOptions getSearchOptions() {
return searchOptions;
}

public void setSearchOptions(DashScopeSearchOptions searchOptions) {
this.searchOptions = searchOptions;
}

public Boolean getEnableCodeInterpreter() {
return enableCodeInterpreter;
}

public void setEnableCodeInterpreter(Boolean enableCodeInterpreter) {
this.enableCodeInterpreter = enableCodeInterpreter;
}

public List<DashScopeTool> getTools() {
return tools;
}
Expand All @@ -197,6 +225,14 @@ public void setToolChoice(Object toolChoice) {
this.toolChoice = toolChoice;
}

public Boolean getParallelToolCalls() {
return parallelToolCalls;
}

public void setParallelToolCalls(Boolean parallelToolCalls) {
this.parallelToolCalls = parallelToolCalls;
}

public Integer getSeed() {
return seed;
}
Expand Down Expand Up @@ -289,6 +325,21 @@ public Builder thinkingBudget(Integer thinkingBudget) {
return this;
}

public Builder enableSearch(Boolean enableSearch) {
params.setEnableSearch(enableSearch);
return this;
}

public Builder searchOptions(DashScopeSearchOptions searchOptions) {
params.setSearchOptions(searchOptions);
return this;
}

public Builder enableCodeInterpreter(Boolean enableCodeInterpreter) {
params.setEnableCodeInterpreter(enableCodeInterpreter);
return this;
}

public Builder tools(List<DashScopeTool> tools) {
params.setTools(tools);
return this;
Expand All @@ -299,6 +350,11 @@ public Builder toolChoice(Object toolChoice) {
return this;
}

public Builder parallelToolCalls(Boolean parallelToolCalls) {
params.setParallelToolCalls(parallelToolCalls);
return this;
}

public Builder seed(Integer seed) {
params.setSeed(seed);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/*
* Copyright 2024-2026 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.agentscope.core.formatter.dashscope.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* DashScope search options DTO.
*
* <p>This class represents the search strategy configuration in a DashScope API request.
* It is used to control internet search behavior when enable_search is true.
*
* <p>Example JSON:
* <pre>{@code
* {
* "enable_source": true,
* "enable_citation": true,
* "citation_format": "[<number>]",
* "forced_search": false,
* "search_strategy": "turbo",
* "enable_search_extension": false,
* "prepend_search_result": false
* }
* }</pre>
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DashScopeSearchOptions {

/**
* Whether to display searched information in the return results.
* Default value is false.
*/
@JsonProperty("enable_source")
private Boolean enableSource;

/**
* Whether to enable citation markers like [1] or [ref_1].
* Only effective when enable_source is true.
* Default value is false.
*/
@JsonProperty("enable_citation")
private Boolean enableCitation;

/**
* The style of citation markers.
* Only effective when enable_citation is true.
* Default value is "[<number>]".
* Optional values: "[<number>]", "[ref_<number>]".
*/
@JsonProperty("citation_format")
private String citationFormat;

/**
* Whether to force enable search.
* Default value is false.
*/
@JsonProperty("forced_search")
private Boolean forcedSearch;

/**
* The strategy for searching internet information.
* Default value is "turbo".
* Optional values: "turbo", "max", "agent", "agent_max".
*/
@JsonProperty("search_strategy")
private SearchStrategy searchStrategy;

/**
* Whether to enable specific domain enhancement.
* Default value is false.
*/
@JsonProperty("enable_search_extension")
private Boolean enableSearchExtension;

/**
* In streaming output with enable_source true, configures whether the first
* returned data packet contains only search source information.
* Default value is false.
* Note: Currently not supported in DashScope Java SDK according to docs,
* but included for completeness based on API spec.
*/
@JsonProperty("prepend_search_result")
private Boolean prependSearchResult;

public DashScopeSearchOptions() {}

public Boolean getEnableSource() {
return enableSource;
}

public void setEnableSource(Boolean enableSource) {
this.enableSource = enableSource;
}

public Boolean getEnableCitation() {
return enableCitation;
}

public void setEnableCitation(Boolean enableCitation) {
this.enableCitation = enableCitation;
}

public String getCitationFormat() {
return citationFormat;
}

public void setCitationFormat(String citationFormat) {
this.citationFormat = citationFormat;
}

public Boolean getForcedSearch() {
return forcedSearch;
}

public void setForcedSearch(Boolean forcedSearch) {
this.forcedSearch = forcedSearch;
}

public SearchStrategy getSearchStrategy() {
return searchStrategy;
}

public void setSearchStrategy(SearchStrategy searchStrategy) {
this.searchStrategy = searchStrategy;
}

public Boolean getEnableSearchExtension() {
return enableSearchExtension;
}

public void setEnableSearchExtension(Boolean enableSearchExtension) {
this.enableSearchExtension = enableSearchExtension;
}

public Boolean getPrependSearchResult() {
return prependSearchResult;
}

public void setPrependSearchResult(Boolean prependSearchResult) {
this.prependSearchResult = prependSearchResult;
}

public enum SearchStrategy {
/**
* Taking into account both responsiveness and search effect, it is suitable for most scenarios.(default)
*/
@JsonProperty("turbo")
TURBO,

/**
* With a more comprehensive search strategy, call multi-source search engines for more exhaustive
* search results, but response times may be longer
*/
@JsonProperty("max")
MAX,

/**
* Web search tools and large models can be called multiple times to achieve multiple rounds of information
* retrieval and content integration.
* <p>
* This strategy only works with qwen3.5-plus, qwen3.5-plus-2026-02-15, qwen3.5-flash, qwen3.5-flash-2026-02-23,
* qwen3-max with qwen3-max-2026-01-23 (streaming only), qwen3-max-2026-01-23 non-thinking mode, qwen3-max-2025-09-23.
* When this strategy is enabled, only the search source (enable_source: true) is supported,
* and other web search options are not available.
*/
@JsonProperty("agent")
AGENT,

/**
* Web extractor is supported on the basis of agent policies.
* <p>
* This strategy is only applicable to qwen3.5-plus, qwen3.5-plus-2026-02-15, qwen3.5-flash,
* qwen3.5-flash-2026-02-23, and qwen3-max and qwen3-max-2026-01-23 thinking modes.
* When this strategy is enabled, only the search source (enable_source: true) is supported,
* and other web search options are not available.
*/
@JsonProperty("agent_max")
AGENT_MAX
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private final DashScopeSearchOptions searchOptions = new DashScopeSearchOptions();

public Builder enableSource(Boolean enableSource) {
searchOptions.setEnableSource(enableSource);
return this;
}

public Builder enableCitation(Boolean enableCitation) {
searchOptions.setEnableCitation(enableCitation);
return this;
}

public Builder citationFormat(String citationFormat) {
searchOptions.setCitationFormat(citationFormat);
return this;
}

public Builder forcedSearch(Boolean forcedSearch) {
searchOptions.setForcedSearch(forcedSearch);
return this;
}

public Builder searchStrategy(SearchStrategy searchStrategy) {
searchOptions.setSearchStrategy(searchStrategy);
return this;
}

public Builder enableSearchExtension(Boolean enableSearchExtension) {
searchOptions.setEnableSearchExtension(enableSearchExtension);
return this;
}

public Builder prependSearchResult(Boolean prependSearchResult) {
searchOptions.setPrependSearchResult(prependSearchResult);
return this;
}

public DashScopeSearchOptions build() {
return searchOptions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ public void applyOptions(
request.setSeed(seed.intValue());
}

// Apply parallel tool calls
Boolean parallelToolCalls =
getOptionOrDefault(options, defaultOptions, GenerateOptions::getParallelToolCalls);
if (parallelToolCalls != null) {
request.setParallelToolCalls(parallelToolCalls);
}

// Apply additional body params (must be last to allow overriding)
applyAdditionalBodyParams(request, defaultOptions);
applyAdditionalBodyParams(request, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public static PublicKeyResult fetchPublicKey(
* @param publicKeyId the public key ID
* @param publicKey the Base64-encoded public key
*/
public static record PublicKeyResult(String publicKeyId, String publicKey) {}
public record PublicKeyResult(String publicKeyId, String publicKey) {}

private Map<String, String> buildHeaders(
boolean streaming, Map<String, String> additionalHeaders, EncryptionContext context) {
Expand Down
Loading
Loading