Skip to content

Commit 043c7f4

Browse files
committed
fix issues with PR
1 parent 5f26160 commit 043c7f4

File tree

28 files changed

+823
-224
lines changed

28 files changed

+823
-224
lines changed

.local.env

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.193
2-
SENTRIUS_SSH_VERSION=1.1.35
3-
SENTRIUS_KEYCLOAK_VERSION=1.1.47
4-
SENTRIUS_AGENT_VERSION=1.1.34
5-
SENTRIUS_AI_AGENT_VERSION=1.1.64
6-
LLMPROXY_VERSION=1.0.46
7-
LAUNCHER_VERSION=1.0.51
8-
AGENTPROXY_VERSION=1.0.66
1+
SENTRIUS_VERSION=1.1.233
2+
SENTRIUS_SSH_VERSION=1.1.36
3+
SENTRIUS_KEYCLOAK_VERSION=1.1.48
4+
SENTRIUS_AGENT_VERSION=1.1.35
5+
SENTRIUS_AI_AGENT_VERSION=1.1.85
6+
LLMPROXY_VERSION=1.0.49
7+
LAUNCHER_VERSION=1.0.55
8+
AGENTPROXY_VERSION=1.0.67

.local.env.bak

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.193
2-
SENTRIUS_SSH_VERSION=1.1.35
3-
SENTRIUS_KEYCLOAK_VERSION=1.1.47
4-
SENTRIUS_AGENT_VERSION=1.1.34
5-
SENTRIUS_AI_AGENT_VERSION=1.1.64
6-
LLMPROXY_VERSION=1.0.46
7-
LAUNCHER_VERSION=1.0.51
8-
AGENTPROXY_VERSION=1.0.66
1+
SENTRIUS_VERSION=1.1.233
2+
SENTRIUS_SSH_VERSION=1.1.36
3+
SENTRIUS_KEYCLOAK_VERSION=1.1.48
4+
SENTRIUS_AGENT_VERSION=1.1.35
5+
SENTRIUS_AI_AGENT_VERSION=1.1.85
6+
LLMPROXY_VERSION=1.0.49
7+
LAUNCHER_VERSION=1.0.55
8+
AGENTPROXY_VERSION=1.0.67

agent-launcher/src/main/java/io/sentrius/agent/launcher/api/AgentLauncherController.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import lombok.extern.slf4j.Slf4j;
1313
import org.apache.http.HttpStatus;
1414
import org.springframework.http.ResponseEntity;
15-
import org.springframework.web.bind.annotation.DeleteMapping;
1615
import org.springframework.web.bind.annotation.GetMapping;
1716
import org.springframework.web.bind.annotation.PostMapping;
1817
import org.springframework.web.bind.annotation.RequestBody;
@@ -50,8 +49,7 @@ public ResponseEntity<?> createPod(
5049
return ResponseEntity.status(HttpStatus.SC_UNAUTHORIZED).body("Invalid Keycloak token");
5150
}
5251

53-
var clientId = agent.getAgentName();
54-
podLauncherService.launchAgentPod(clientId, agent.getAgentCallbackUrl());
52+
podLauncherService.launchAgentPod(agent);
5553

5654
return ResponseEntity.ok(Map.of("status", "success"));
5755
}

agent-launcher/src/main/java/io/sentrius/agent/launcher/service/PodLauncherService.java

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import io.kubernetes.client.custom.IntOrString;
44
import io.kubernetes.client.custom.Quantity;
55
import io.kubernetes.client.openapi.ApiClient;
6+
import io.kubernetes.client.openapi.ApiException;
67
import io.kubernetes.client.openapi.apis.CoreV1Api;
78
import io.kubernetes.client.openapi.models.*;
89
import io.kubernetes.client.util.Config;
10+
import io.sentrius.sso.core.dto.AgentRegistrationDTO;
911
import lombok.extern.slf4j.Slf4j;
1012
import org.springframework.beans.factory.annotation.Value;
1113
import org.springframework.stereotype.Service;
@@ -116,7 +118,7 @@ public void deleteAgentById(String agentId) throws Exception {
116118
}
117119

118120

119-
public V1Pod launchAgentPod(String agentId, String callbackUrl) throws Exception {
121+
public V1Pod launchAgentPod(AgentRegistrationDTO agent) throws Exception {
120122
var myAgentRegistry = "";
121123
if (agentRegistry != null ) {
122124
if ("local".equalsIgnoreCase(agentRegistry)) {
@@ -125,6 +127,22 @@ public V1Pod launchAgentPod(String agentId, String callbackUrl) throws Exception
125127
myAgentRegistry += "/";
126128
}
127129
}
130+
String agentId = agent.getAgentName();
131+
String callbackUrl = agent.getAgentCallbackUrl();
132+
String agentType = agent.getAgentType();
133+
String agentFile= "chat-helper.yaml";
134+
// TODO This should be pluggable
135+
switch(agentType){
136+
case "chat":
137+
agentFile = "chat-helper.yaml";
138+
break;
139+
case "atpl-helper":
140+
agentFile = "chat-atpl-helper.yaml";
141+
break;
142+
case "default":
143+
default:
144+
agentFile = "chat-helper.yaml";
145+
}
128146

129147
var constructedCallbackUrl = buildAgentCallbackUrl(agentId);
130148

@@ -142,7 +160,8 @@ public V1Pod launchAgentPod(String agentId, String callbackUrl) throws Exception
142160
.imagePullPolicy("IfNotPresent")
143161

144162
.args(List.of("--spring.config.location=file:/config/agent.properties",
145-
"--agent.namePrefix=" + agentId, "--agent.ai.config=/config/chat-helper.yaml", "--agent.listen.websocket=true",
163+
"--agent.namePrefix=" + agentId, "--agent.ai.config=/config/" + agentFile, "--agent.listen" +
164+
".websocket=true",
146165
"--agent.callback.url=" + constructedCallbackUrl
147166
))
148167
.resources(new V1ResourceRequirements()
@@ -169,24 +188,34 @@ public V1Pod launchAgentPod(String agentId, String callbackUrl) throws Exception
169188

170189
var createdPod = coreV1Api.createNamespacedPod(agentNamespace, pod).execute();
171190

172-
// Create corresponding service for WebSocket routing
173-
V1Service service = new V1Service()
174-
.metadata(new V1ObjectMeta()
175-
.name("sentrius-agent-" + agentId)
176-
.labels(Map.of("agentId", agentId)))
177-
.spec(new V1ServiceSpec()
178-
.selector(Map.of("agentId", agentId))
179-
.ports(List.of(new V1ServicePort()
180-
.protocol("TCP")
181-
.port(8090)
182-
.targetPort(new IntOrString(8090))
183-
))
184-
.type("ClusterIP")
185-
);
186-
187-
log.info("Created service pod: {} and service {}", createdPod, service);
188-
coreV1Api.createNamespacedService(agentNamespace, service).execute();
189-
191+
try {
192+
// Create corresponding service for WebSocket routing
193+
V1Service service = new V1Service()
194+
.metadata(new V1ObjectMeta()
195+
.name("sentrius-agent-" + agentId)
196+
.labels(Map.of("agentId", agentId)))
197+
.spec(new V1ServiceSpec()
198+
.selector(Map.of("agentId", agentId))
199+
.ports(List.of(new V1ServicePort()
200+
.protocol("TCP")
201+
.port(8090)
202+
.targetPort(new IntOrString(8090))
203+
))
204+
.type("ClusterIP")
205+
);
206+
207+
log.info("Created service pod: {} and service {}", createdPod, service);
208+
coreV1Api.createNamespacedService(agentNamespace, service).execute();
209+
210+
}catch(ApiException e){
211+
if (e.getCode() == 409){
212+
log.info("Service for agent {} already exists, skipping creation", agentId);
213+
}
214+
else{
215+
throw e;
216+
}
217+
}
190218
return createdPod;
191219
}
220+
192221
}

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/ChatAgent.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ public void onApplicationEvent(final ApplicationReadyEvent event) {
135135
}
136136
}
137137

138+
try {
139+
verbRegistry.scanEndpoints(agentExecution);
140+
} catch (ZtatException e) {
141+
throw new RuntimeException(e);
142+
} catch (JsonProcessingException e) {
143+
throw new RuntimeException(e);
144+
}
145+
138146
while(running) {
139147

140148
log.info("Agent Registered...");

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/PromptBuilder.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ public PromptBuilder(VerbRegistry verbRegistry, AgentConfig agentConfig) {
2525
this.agentConfig = agentConfig;
2626
}
2727

28+
public String buildPrompt(){
29+
return buildPrompt(true);
30+
}
31+
2832
/**
2933
* Builds a prompt string that includes roles, context, instructions, and available verbs.
3034
*
3135
* @return A formatted prompt string.
3236
*/
33-
public String buildPrompt() {
37+
public String buildPrompt(boolean applyInstructions)
38+
{
3439
StringBuilder prompt = new StringBuilder();
3540

3641
// Append roles to the prompt
@@ -39,32 +44,34 @@ public String buildPrompt() {
3944
// Append context to the prompt
4045
prompt.append("Context: ").append(agentConfig.getContext()).append("\n\n");
4146

42-
// Append instructions for using the JSON format
43-
prompt.append("Instructions: ").append("Respond using this JSON format. Only use verbs provided in " +
44-
"Available Verbs. Formulate a complete plan with all possible steps.:\n" +
45-
"\n" +
46-
"{\n" +
47-
" \"plan\": [\n" +
48-
" {\n" +
49-
" \"verb\": \"list_open_terminals\",\n" +
50-
" \"params\": {}\n" +
51-
" },\n" +
52-
" {\n" +
53-
" \"verb\": \"send_terminal_command\",\n" +
54-
" \"params\": {}\n" +
55-
" }\n" +
56-
" ]\n" +
57-
"}\n" );
47+
if (applyInstructions) {
48+
// Append instructions for using the JSON format
49+
prompt.append("Instructions: ").append("Respond using this JSON format. Only use verbs provided in " +
50+
"Available Verbs. Formulate a complete plan with all possible steps.:\n" +
51+
"\n" +
52+
"{\n" +
53+
" \"plan\": [\n" +
54+
" {\n" +
55+
" \"verb\": \"list_open_terminals\",\n" +
56+
" \"params\": {}\n" +
57+
" },\n" +
58+
" {\n" +
59+
" \"verb\": \"send_terminal_command\",\n" +
60+
" \"params\": {}\n" +
61+
" }\n" +
62+
" ]\n" +
63+
"}\n");
5864

59-
// Append the list of available verbs
60-
prompt.append("Available Verbs:\n");
65+
// Append the list of available verbs
66+
prompt.append("Available Verbs:\n");
6167

62-
// Iterate through the verbs in the registry and append their details
63-
verbRegistry.getVerbs().forEach((name, verb) -> {
64-
prompt.append("- ").append(name);
65-
prompt.append(" (").append(buildMethodSignature(verb.getMethod())).append(") - ");
66-
prompt.append(verb.getDescription()).append("\n");
67-
});
68+
// Iterate through the verbs in the registry and append their details
69+
verbRegistry.getVerbs().forEach((name, verb) -> {
70+
prompt.append("- ").append(name);
71+
prompt.append(" (").append(buildMethodSignature(verb.getMethod())).append(") - ");
72+
prompt.append(verb.getDescription()).append("\n");
73+
});
74+
}
6875

6976
return prompt.toString();
7077
}

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/RegisteredAgent.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.HashMap;
44
import java.util.Map;
5-
import java.util.UUID;
65
import java.util.concurrent.TimeUnit;
76
import com.fasterxml.jackson.databind.node.ArrayNode;
87
import io.sentrius.agent.analysis.agents.verbs.AgentVerbs;

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/agents/VerbRegistry.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentrius.agent.analysis.agents.agents;
22

3+
import com.fasterxml.jackson.core.JsonProcessingException;
34
import io.github.classgraph.ClassGraph;
45
import io.github.classgraph.ScanResult;
56
import io.sentrius.sso.core.dto.capabilities.EndpointDescriptor;
@@ -10,6 +11,7 @@
1011
import io.sentrius.sso.core.model.verbs.OutputInterpreterIfc;
1112
import io.sentrius.sso.core.model.verbs.Verb;
1213
import io.sentrius.sso.core.model.verbs.VerbResponse;
14+
import io.sentrius.sso.core.services.agents.AgentClientService;
1315
import io.sentrius.sso.core.services.agents.ZeroTrustClientService;
1416
import io.sentrius.sso.core.services.capabilities.EndpointScanningService;
1517
import lombok.RequiredArgsConstructor;
@@ -20,6 +22,7 @@
2022

2123
import java.lang.reflect.InvocationTargetException;
2224
import java.lang.reflect.Method;
25+
import java.util.ArrayList;
2326
import java.util.HashMap;
2427
import java.util.List;
2528
import java.util.Map;
@@ -34,6 +37,8 @@ public class VerbRegistry {
3437
private final ApplicationContext applicationContext;
3538

3639
private final ZeroTrustClientService zeroTrustClientService;
40+
41+
private final AgentClientService agentClientService;
3742

3843
private final EndpointScanningService endpointScanningService;
3944

@@ -42,6 +47,26 @@ public class VerbRegistry {
4247

4348
private final AgentEndpointDiscoveryService agentEndpointDiscoveryService;
4449

50+
private List<EndpointDescriptor> endpoints = new ArrayList<>();
51+
52+
public void scanEndpoints(AgentExecution execution) throws ZtatException, JsonProcessingException {
53+
synchronized (this) {
54+
var endpoints = agentClientService.getAvailableEndpoints(execution);
55+
log.info("Scanning endpoints for verbs...");
56+
var verbs = agentClientService.getAvailableVerbs(execution);
57+
58+
endpoints.forEach(x -> {
59+
log.info("Discovered endpoint: {}", x);
60+
});
61+
62+
this.endpoints.addAll(endpoints);
63+
64+
verbs.forEach(x -> {
65+
log.info("Discovered verb: {}", x);
66+
});
67+
}
68+
}
69+
4570
public void scanClasspath() {
4671
// Scan the classpath for classes with the @Verb annotation
4772
synchronized (this) {
@@ -83,6 +108,7 @@ public void scanClasspath() {
83108
}
84109
});
85110
}
111+
86112
}
87113
}
88114

@@ -173,6 +199,10 @@ public VerbResponse execute(AgentExecution agentExecution, VerbResponse priorRes
173199
}
174200
}
175201

202+
public List<EndpointDescriptor> getEndpoints() {
203+
return endpoints;
204+
}
205+
176206
public Map<String, AgentVerb> getVerbs() {
177207
return new HashMap<>(verbs);
178208
}
@@ -202,4 +232,5 @@ public List<EndpointDescriptor> getAiCallableVerbDescriptors() {
202232
})
203233
.collect(Collectors.toList());
204234
}
235+
205236
}

0 commit comments

Comments
 (0)