Skip to content

Commit 8fb2592

Browse files
committed
agentic memory integration with agent framework
Signed-off-by: Dhrubo Saha <[email protected]>
1 parent 3950a87 commit 8fb2592

File tree

21 files changed

+3424
-430
lines changed

21 files changed

+3424
-430
lines changed

MLChatAgentRunner_Memory_Extension_Plan.md

Lines changed: 589 additions & 0 deletions
Large diffs are not rendered by default.

common/src/main/java/org/opensearch/ml/common/MLAgentType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static MLAgentType from(String value) {
2020
try {
2121
return MLAgentType.valueOf(value.toUpperCase(Locale.ROOT));
2222
} catch (Exception e) {
23-
throw new IllegalArgumentException("Wrong Agent type");
23+
throw new IllegalArgumentException(value + " is not a valid Agent Type");
2424
}
2525
}
2626
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package org.opensearch.ml.common;
7+
8+
import java.util.Locale;
9+
10+
public enum MLMemoryType {
11+
CONVERSATION_INDEX,
12+
AGENTIC_MEMORY;
13+
14+
public static MLMemoryType from(String value) {
15+
if (value != null) {
16+
try {
17+
return MLMemoryType.valueOf(value.toUpperCase(Locale.ROOT));
18+
} catch (Exception e) {
19+
throw new IllegalArgumentException("Wrong Memory type");
20+
}
21+
}
22+
return null;
23+
}
24+
}

common/src/main/java/org/opensearch/ml/common/agent/MLAgent.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.ArrayList;
1616
import java.util.HashSet;
1717
import java.util.List;
18-
import java.util.Locale;
1918
import java.util.Map;
2019
import java.util.Optional;
2120
import java.util.Set;
@@ -113,7 +112,7 @@ private void validate() {
113112
String.format("Agent name cannot be empty or exceed max length of %d characters", MLAgent.AGENT_NAME_MAX_LENGTH)
114113
);
115114
}
116-
validateMLAgentType(type);
115+
MLAgentType.from(type);
117116
if (type.equalsIgnoreCase(MLAgentType.CONVERSATIONAL.toString()) && llm == null) {
118117
throw new IllegalArgumentException("We need model information for the conversational agent type");
119118
}
@@ -130,19 +129,6 @@ private void validate() {
130129
}
131130
}
132131

133-
private void validateMLAgentType(String agentType) {
134-
if (type == null) {
135-
throw new IllegalArgumentException("Agent type can't be null");
136-
} else {
137-
try {
138-
MLAgentType.valueOf(agentType.toUpperCase(Locale.ROOT)); // Use toUpperCase() to allow case-insensitive matching
139-
} catch (IllegalArgumentException e) {
140-
// The typeStr does not match any MLAgentType, so throw a new exception with a clearer message.
141-
throw new IllegalArgumentException(agentType + " is not a valid Agent Type");
142-
}
143-
}
144-
}
145-
146132
public MLAgent(StreamInput input) throws IOException {
147133
Version streamInputVersion = input.getVersion();
148134
name = input.readString();

common/src/main/java/org/opensearch/ml/common/transport/agent/MLAgentUpdateInput.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.opensearch.core.xcontent.ToXContentObject;
2727
import org.opensearch.core.xcontent.XContentBuilder;
2828
import org.opensearch.core.xcontent.XContentParser;
29+
import org.opensearch.ml.common.MLMemoryType;
2930
import org.opensearch.ml.common.agent.LLMSpec;
3031
import org.opensearch.ml.common.agent.MLAgent;
3132
import org.opensearch.ml.common.agent.MLMemorySpec;
@@ -383,9 +384,7 @@ private void validate() {
383384
String.format("Agent name cannot be empty or exceed max length of %d characters", MLAgent.AGENT_NAME_MAX_LENGTH)
384385
);
385386
}
386-
if (memoryType != null && !memoryType.equals("conversation_index")) {
387-
throw new IllegalArgumentException(String.format("Invalid memory type: %s", memoryType));
388-
}
387+
MLMemoryType.from(memoryType);
389388
if (tools != null) {
390389
Set<String> toolNames = new HashSet<>();
391390
for (MLToolSpec toolSpec : tools) {

common/src/test/java/org/opensearch/ml/common/MLAgentTypeTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public void testFromWithMixedCase() {
4444
public void testFromWithInvalidType() {
4545
// This should throw an IllegalArgumentException
4646
exceptionRule.expect(IllegalArgumentException.class);
47-
exceptionRule.expectMessage("Wrong Agent type");
47+
exceptionRule.expectMessage(" is not a valid Agent Type");
4848
MLAgentType.from("INVALID_TYPE");
4949
}
5050

5151
@Test
5252
public void testFromWithEmptyString() {
5353
exceptionRule.expect(IllegalArgumentException.class);
54-
exceptionRule.expectMessage("Wrong Agent type");
54+
exceptionRule.expectMessage(" is not a valid Agent Type");
5555
// This should also throw an IllegalArgumentException
5656
MLAgentType.from("");
5757
}

common/src/test/java/org/opensearch/ml/common/transport/agent/MLAgentUpdateInputTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void testValidationWithInvalidMemoryType() {
9494
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
9595
MLAgentUpdateInput.builder().agentId("test-agent-id").name("test-agent").memoryType("invalid_type").build();
9696
});
97-
assertEquals("Invalid memory type: invalid_type", e.getMessage());
97+
assertEquals("Wrong Memory type", e.getMessage());
9898
}
9999

100100
@Test

0 commit comments

Comments
 (0)