Skip to content

Commit 01cfec3

Browse files
committed
add feature flag
Signed-off-by: Jiaping Zeng <[email protected]>
1 parent 1caab62 commit 01cfec3

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

common/src/main/java/org/opensearch/ml/common/settings/MLCommonsSettings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,10 @@ private MLCommonsSettings() {}
483483
// Feature flag for streaming feature
484484
public static final Setting<Boolean> ML_COMMONS_STREAM_ENABLED = Setting
485485
.boolSetting(ML_PLUGIN_SETTING_PREFIX + "stream_enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
486+
487+
// Feature flag for AG-UI agent support
488+
public static final Setting<Boolean> ML_COMMONS_AG_UI_ENABLED = Setting
489+
.boolSetting(ML_PLUGIN_SETTING_PREFIX + "ag_ui_enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
490+
public static final String ML_COMMONS_AG_UI_DISABLED_MESSAGE =
491+
"The AG-UI agent feature is not enabled. To enable, please update the setting " + ML_COMMONS_AG_UI_ENABLED.getKey();
486492
}

common/src/main/java/org/opensearch/ml/common/settings/MLFeatureEnabledSetting.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_REMOTE_INFERENCE_ENABLED;
2323
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_STATIC_METRIC_COLLECTION_ENABLED;
2424
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_STREAM_ENABLED;
25+
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_AG_UI_ENABLED;
2526

2627
import java.util.ArrayList;
2728
import java.util.List;
@@ -63,6 +64,8 @@ public class MLFeatureEnabledSetting {
6364

6465
private volatile Boolean isStreamEnabled;
6566

67+
private volatile Boolean isAGUIEnabled;
68+
6669
private final List<SettingsChangeListener> listeners = new ArrayList<>();
6770

6871
public MLFeatureEnabledSetting(ClusterService clusterService, Settings settings) {
@@ -83,6 +86,7 @@ public MLFeatureEnabledSetting(ClusterService clusterService, Settings settings)
8386
isAgenticMemoryEnabled = ML_COMMONS_AGENTIC_MEMORY_ENABLED.get(settings);
8487
isIndexInsightEnabled = ML_COMMONS_INDEX_INSIGHT_FEATURE_ENABLED.get(settings);
8588
isStreamEnabled = ML_COMMONS_STREAM_ENABLED.get(settings);
89+
isAGUIEnabled = ML_COMMONS_AG_UI_ENABLED.get(settings);
8690

8791
clusterService
8892
.getClusterSettings()
@@ -112,6 +116,7 @@ public MLFeatureEnabledSetting(ClusterService clusterService, Settings settings)
112116
clusterService
113117
.getClusterSettings()
114118
.addSettingsUpdateConsumer(ML_COMMONS_INDEX_INSIGHT_FEATURE_ENABLED, it -> isIndexInsightEnabled = it);
119+
clusterService.getClusterSettings().addSettingsUpdateConsumer(ML_COMMONS_AG_UI_ENABLED, it -> isAGUIEnabled = it);
115120
clusterService.getClusterSettings().addSettingsUpdateConsumer(ML_COMMONS_STATIC_METRIC_COLLECTION_ENABLED, it -> {
116121
isStaticMetricCollectionEnabled = it;
117122
for (SettingsChangeListener listener : listeners) {
@@ -245,4 +250,12 @@ public boolean isIndexInsightEnabled() {
245250
public boolean isStreamEnabled() {
246251
return isStreamEnabled;
247252
}
253+
254+
/**
255+
* Whether the AG-UI agent feature is enabled. If disabled, AG-UI agents will be blocked.
256+
* @return whether the AG-UI agent feature is enabled.
257+
*/
258+
public boolean isAGUIEnabled() {
259+
return isAGUIEnabled;
260+
}
248261
}

plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,8 @@ public List<Setting<?>> getSettings() {
13641364
MLCommonsSettings.ML_COMMONS_INDEX_INSIGHT_FEATURE_ENABLED,
13651365
MLCommonsSettings.REMOTE_METADATA_GLOBAL_TENANT_ID,
13661366
MLCommonsSettings.REMOTE_METADATA_GLOBAL_RESOURCE_CACHE_TTL,
1367-
MLCommonsSettings.ML_COMMONS_STREAM_ENABLED
1367+
MLCommonsSettings.ML_COMMONS_STREAM_ENABLED,
1368+
MLCommonsSettings.ML_COMMONS_AG_UI_ENABLED
13681369
);
13691370
return settings;
13701371
}

plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_EXECUTE_TOOL_DISABLED_MESSAGE;
1212
import static org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI;
1313
import static org.opensearch.ml.utils.MLExceptionUtils.AGENT_FRAMEWORK_DISABLED_ERR_MSG;
14+
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_AG_UI_DISABLED_MESSAGE;
1415
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_AGENT_ID;
1516
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_ALGORITHM;
1617
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_TOOL_NAME;
@@ -128,6 +129,9 @@ MLExecuteTaskRequest getRequest(RestRequest request) throws IOException {
128129

129130
String requestBodyJson = request.contentOrSourceParam().v2().utf8ToString();
130131
if (AGUIInputConverter.isAGUIInput(requestBodyJson)) {
132+
if (!mlFeatureEnabledSetting.isAGUIEnabled()) {
133+
throw new IllegalStateException(ML_COMMONS_AG_UI_DISABLED_MESSAGE);
134+
}
131135
throw new IllegalArgumentException(
132136
"AG-UI agents require streaming execution. "
133137
+ "Please use the streaming endpoint: POST /_plugins/_ml/agents/"

plugin/src/main/java/org/opensearch/ml/rest/RestMLExecuteStreamAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import static org.opensearch.ml.plugin.MachineLearningPlugin.STREAM_EXECUTE_THREAD_POOL;
1717
import static org.opensearch.ml.utils.MLExceptionUtils.AGENT_FRAMEWORK_DISABLED_ERR_MSG;
1818
import static org.opensearch.ml.utils.MLExceptionUtils.STREAM_DISABLED_ERR_MSG;
19+
import static org.opensearch.ml.common.settings.MLCommonsSettings.ML_COMMONS_AG_UI_DISABLED_MESSAGE;
1920
import static org.opensearch.ml.utils.RestActionUtils.PARAMETER_AGENT_ID;
2021
import static org.opensearch.ml.utils.RestActionUtils.isAsync;
2122
import static org.opensearch.ml.utils.TenantAwareHelper.getTenantID;
@@ -361,6 +362,9 @@ MLExecuteTaskRequest getRequest(String agentId, RestRequest request, BytesRefere
361362
String requestBodyJson = content.utf8ToString();
362363
Input input;
363364
if (AGUIInputConverter.isAGUIInput(requestBodyJson)) {
365+
if (!mlFeatureEnabledSetting.isAGUIEnabled()) {
366+
throw new IllegalStateException(ML_COMMONS_AG_UI_DISABLED_MESSAGE);
367+
}
364368
log.debug("AG-UI: Detected AG-UI input format for streaming agent: {}", agentId);
365369
input = AGUIInputConverter.convertFromAGUIInput(requestBodyJson, agentId, tenantId, async);
366370
} else {

0 commit comments

Comments
 (0)