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
57 changes: 54 additions & 3 deletions agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class ReActAgent extends StructuredOutputCapableAgent {
private final int maxIters;
private final ExecutionConfig modelExecutionConfig;
private final ExecutionConfig toolExecutionConfig;
private final GenerateOptions generateOptions;
private final PlanNotebook planNotebook;
private final ToolExecutionContext toolExecutionContext;
private final StatePersistence statePersistence;
Expand All @@ -159,6 +160,7 @@ private ReActAgent(Builder builder, Toolkit agentToolkit) {
this.maxIters = builder.maxIters;
this.modelExecutionConfig = builder.modelExecutionConfig;
this.toolExecutionConfig = builder.toolExecutionConfig;
this.generateOptions = builder.generateOptions;
this.planNotebook = builder.planNotebook;
this.toolExecutionContext = builder.toolExecutionContext;
this.statePersistence =
Expand Down Expand Up @@ -786,11 +788,17 @@ private List<ToolUseBlock> extractPendingToolCalls() {

@Override
protected GenerateOptions buildGenerateOptions() {
GenerateOptions.Builder builder = GenerateOptions.builder();
// Start with user-configured generateOptions if available
GenerateOptions baseOptions = generateOptions;

// If modelExecutionConfig is set, merge it into the options
if (modelExecutionConfig != null) {
builder.executionConfig(modelExecutionConfig);
GenerateOptions execConfigOptions =
GenerateOptions.builder().executionConfig(modelExecutionConfig).build();
baseOptions = GenerateOptions.mergeOptions(execConfigOptions, baseOptions);
}
return builder.build();

return baseOptions != null ? baseOptions : GenerateOptions.builder().build();
}

// ==================== Hook Notification Methods ====================
Expand Down Expand Up @@ -962,6 +970,15 @@ public PlanNotebook getPlanNotebook() {
return planNotebook;
}

/**
* Gets the configured generation options for this agent.
*
* @return The generation options, or null if not configured
*/
public GenerateOptions getGenerateOptions() {
return generateOptions;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -979,6 +996,7 @@ public static class Builder {
private int maxIters = 10;
private ExecutionConfig modelExecutionConfig;
private ExecutionConfig toolExecutionConfig;
private GenerateOptions generateOptions;
private final Set<Hook> hooks = new LinkedHashSet<>();
private boolean enableMetaTool = false;
private StructuredOutputReminder structuredOutputReminder =
Expand Down Expand Up @@ -1156,6 +1174,39 @@ public Builder toolExecutionConfig(ExecutionConfig toolExecutionConfig) {
return this;
}

/**
* Sets the generation options for model API calls.
*
* <p>This configuration controls LLM generation parameters such as temperature, topP,
* maxTokens, frequencyPenalty, presencePenalty, etc. These options are passed to the
* model during the reasoning phase.
*
* <p><b>Example usage:</b>
* <pre>{@code
* ReActAgent agent = ReActAgent.builder()
* .name("assistant")
* .model(model)
* .generateOptions(GenerateOptions.builder()
* .temperature(0.7)
* .topP(0.9)
* .maxTokens(1000)
* .build())
* .build();
* }</pre>
*
* <p><b>Note:</b> If both generateOptions and modelExecutionConfig are set,
* the modelExecutionConfig's executionConfig will be merged into the generateOptions,
* with modelExecutionConfig taking precedence for execution settings.
*
* @param generateOptions The generation options for model calls, can be null
* @return This builder instance for method chaining
* @see GenerateOptions
*/
public Builder generateOptions(GenerateOptions generateOptions) {
this.generateOptions = generateOptions;
return this;
}

/**
* Sets the structured output enforcement mode.
*
Expand Down
Loading
Loading