Skip to content

Commit 8448952

Browse files
committed
intermediate commit
1 parent 043c7f4 commit 8448952

File tree

49 files changed

+2077
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2077
-491
lines changed

.local.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.233
1+
SENTRIUS_VERSION=1.1.246
22
SENTRIUS_SSH_VERSION=1.1.36
33
SENTRIUS_KEYCLOAK_VERSION=1.1.48
44
SENTRIUS_AGENT_VERSION=1.1.35
5-
SENTRIUS_AI_AGENT_VERSION=1.1.85
5+
SENTRIUS_AI_AGENT_VERSION=1.1.124
66
LLMPROXY_VERSION=1.0.49
7-
LAUNCHER_VERSION=1.0.55
8-
AGENTPROXY_VERSION=1.0.67
7+
LAUNCHER_VERSION=1.0.62
8+
AGENTPROXY_VERSION=1.0.69

.local.env.bak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.233
1+
SENTRIUS_VERSION=1.1.246
22
SENTRIUS_SSH_VERSION=1.1.36
33
SENTRIUS_KEYCLOAK_VERSION=1.1.48
44
SENTRIUS_AGENT_VERSION=1.1.35
5-
SENTRIUS_AI_AGENT_VERSION=1.1.85
5+
SENTRIUS_AI_AGENT_VERSION=1.1.124
66
LLMPROXY_VERSION=1.0.49
7-
LAUNCHER_VERSION=1.0.55
8-
AGENTPROXY_VERSION=1.0.67
7+
LAUNCHER_VERSION=1.0.62
8+
AGENTPROXY_VERSION=1.0.69

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ public ResponseEntity<String> deleteAgent(@RequestParam(name="agentId") String a
6060
podLauncherService.deleteAgentById(agentId);
6161
return ResponseEntity.ok("Shutdown triggered");
6262
} catch (Exception e) {
63-
e.printStackTrace();
6463
return ResponseEntity.status(500).body("Shutdown failed: " + e.getMessage());
6564
}
6665
}
6766

67+
@GetMapping("/status")
68+
public ResponseEntity<String> getAgentStatus(@RequestParam(name="agentId") String agentId) {
69+
try {
70+
return ResponseEntity.ok(podLauncherService.statusById(agentId) );
71+
} catch (Exception e) {
72+
return ResponseEntity.status(500).body("Status failed: " + e.getMessage());
73+
}
74+
}
75+
6876
}

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void deleteAgentById(String agentId) throws Exception {
102102
} catch (Exception ex) {
103103
log.warn("Service not found or already deleted: {}", ex.getMessage());
104104
}
105-
}else {
105+
} else {
106106
log.info("Not Deleting pod: {}", podName);
107107
}
108108

@@ -113,9 +113,49 @@ public void deleteAgentById(String agentId) throws Exception {
113113

114114

115115
}
116+
}
117+
118+
119+
public String statusById(String agentId) throws Exception {
120+
// Delete all pods with this agentId label
121+
var pods = coreV1Api.listNamespacedPod(
122+
agentNamespace
123+
).execute().getItems();
124+
125+
for (V1Pod pod : pods) {
126+
127+
var labels = pod.getMetadata().getLabels();
128+
var podName = pod.getMetadata().getName();
129+
130+
Matcher matcher = pattern.matcher(agentId);
131+
132+
if (matcher.matches() && labels != null && labels.containsKey("agentId")) {
133+
String name = matcher.group(1);
134+
135+
var value = labels.get("agentId");
136+
if (value.equals(name)) {
137+
// get pod status
138+
//
139+
V1PodStatus status = pod.getStatus();
140+
if (status == null) {
141+
log.warn("Pod {} has no status information", podName);
142+
return "Unknown";
143+
}
144+
return status.getPhase(); // e.g., "Running", "Pending", "Failed", "Succeeded"
145+
146+
}
147+
148+
149+
}
150+
151+
152+
}
153+
return "NotFound";
154+
}
155+
156+
116157

117158

118-
}
119159

120160

121161
public V1Pod launchAgentPod(AgentRegistrationDTO agent) throws Exception {

agent-proxy/src/main/java/io/sentrius/sso/config/AgentWebSocketProxyHandler.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,38 @@ public Mono<Void> handle(WebSocketSession clientSession) {
123123
})
124124
.as(clientSession::send)
125125
.doOnSuccess(aVoid -> log.info("agent -> client completed gracefully")) // Corrected for Mono
126-
.doOnError(e -> log.error("Error in agent -> client stream", e))
126+
.doOnError(e -> {
127+
log.error("Error in agent -> client stream", e);
128+
sessionManager.unregister(agentSession.getId());
129+
})
127130
.onErrorResume(e -> {
131+
sessionManager.unregister(agentSession.getId());
128132
log.error("Agent to client stream error, closing agent session.", e);
129133
return agentSession.close().then(Mono.empty());
130134
})
131135
.doFinally(sig -> log.info("Agent to client stream finalized: {}", sig));
132136

133137
return Mono.when(clientToAgent, agentToClient)
134-
.doOnTerminate(() -> log.info("WebSocket proxy connection terminated (client and agent streams completed/cancelled)"))
135-
.doOnError(e -> log.error("Overall proxy connection failed", e))
138+
.doOnTerminate(() -> {
139+
log.info("WebSocket proxy connection terminated (client and agent " +
140+
"streams completed/cancelled)");
141+
sessionManager.unregister(agentSession.getId());
142+
143+
})
144+
.doOnError(e -> {
145+
log.error("Overall proxy connection failed", e);
146+
sessionManager.unregister(agentSession.getId());
147+
148+
})
136149
.doFinally(sig -> {
137150
sessionManager.unregister(finalSessionId);
138151
log.info("WebSocket proxy stream closed completely: {}. Final session ID: {}", sig, finalSessionId);
139152
});
140153
}
141-
).doOnError(e -> log.error("Failed to establish proxy connection", e));
154+
).doOnError(e -> {
155+
log.error("Failed to establish proxy connection", e);
156+
sessionManager.unregister(finalSessionId);
157+
});
142158

143159

144160
} catch (Exception ex) {

agent-proxy/src/main/java/io/sentrius/sso/config/SecurityConfig.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ private ReactiveJwtAuthenticationConverter grantedAuthoritiesExtractor() {
5555

5656
converter.setJwtGrantedAuthoritiesConverter(jwt -> {
5757
Collection<GrantedAuthority> authorities = new JwtGrantedAuthoritiesConverter().convert(jwt);
58-
log.info("JWT Claims: {}", jwt.getClaims());
59-
60-
String username = jwt.getClaimAsString("preferred_username");
61-
String email = jwt.getClaimAsString("email");
6258

6359
return Flux.fromIterable(authorities);
6460
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ public class AgentVerb {
2424
@Builder.Default
2525
Class<? extends OutputInterpreterIfc> outputInterpreter = DefaultInterpreter.class;
2626
Class<? extends InputInterpreterIfc> inputInterpreter = DefaultInterpreter.class;
27+
28+
private String exampleJson = "";
2729
}

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.lang.reflect.Method;
44
import java.util.Arrays;
55
import java.util.stream.Collectors;
6+
import io.sentrius.agent.analysis.agents.verbs.ExampleFactory;
7+
import io.sentrius.sso.core.utils.JsonUtil;
68

79
/**
810
* The `PromptBuilder` class is responsible for constructing a prompt string
@@ -61,21 +63,50 @@ public String buildPrompt(boolean applyInstructions)
6163
" }\n" +
6264
" ]\n" +
6365
"}\n");
64-
66+
}
6567
// Append the list of available verbs
66-
prompt.append("Available Verbs:\n");
68+
prompt.append("Verb operations:\n");
6769

6870
// Iterate through the verbs in the registry and append their details
6971
verbRegistry.getVerbs().forEach((name, verb) -> {
7072
prompt.append("- ").append(name);
7173
prompt.append(" (").append(buildMethodSignature(verb.getMethod())).append(") - ");
7274
prompt.append(verb.getDescription()).append("\n");
75+
// Optionally generate example params based on arg1 class
76+
Class<?>[] paramTypes = verb.getMethod().getParameterTypes();
77+
78+
if (paramTypes.length > 1 && !paramTypes[1].equals(Void.class)) {
79+
var paramName = verb.getMethod().getParameters()[1].getName();
80+
Object example = ExampleFactory.createExample(paramName, paramTypes[1]); // create a stub from
81+
// your DTO
82+
try {
83+
if (verb.getExampleJson() != null && !verb.getExampleJson().isEmpty()) {
84+
prompt.append(" Example arg1: ").append(verb.getExampleJson()).append("\n");
85+
} else if (example != null) {
86+
// Serialize the example object to JSON
87+
String exampleJson = JsonUtil.MAPPER.writeValueAsString(example);
88+
prompt.append(" Example arg1: ").append(exampleJson).append("\n");
89+
}
90+
91+
} catch (Exception e) {
92+
prompt.append(" Example params: [unavailable due to serialization error]\n");
93+
}
94+
} else {
95+
prompt.append(" Example params: {}\n");
96+
}
7397
});
74-
}
7598

7699
return prompt.toString();
77100
}
78101

102+
public static String indent(String input, int spaces) {
103+
String indent = " ".repeat(spaces);
104+
return Arrays.stream(input.split("\n"))
105+
.map(line -> indent + line)
106+
.collect(Collectors.joining("\n"));
107+
}
108+
109+
79110
/**
80111
* Builds a method signature string for a given method.
81112
*
@@ -84,6 +115,8 @@ public String buildPrompt(boolean applyInstructions)
84115
*/
85116
private String buildMethodSignature(Method method) {
86117
return Arrays.stream(method.getParameters())
118+
.filter( p -> !p.getType().getSimpleName().equalsIgnoreCase("TokenDTO") &&
119+
!p.getType().getSimpleName().equalsIgnoreCase("AgentExecution"))
87120
.map(p -> p.getName() + ": " + p.getType().getSimpleName())
88121
.collect(Collectors.joining(", "));
89122
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void scanClasspath() {
9393
.name(name)
9494
.description(annotation.description())
9595
.method(method)
96+
.exampleJson(annotation.exampleJson())
9697
.requiresTokenManagement(annotation.requiresTokenManagement())
9798
.returnType(annotation.returnType())
9899
.outputInterpreter(annotation.outputInterpreter())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.sentrius.agent.analysis.agents.interpreters;
2+
3+
import java.util.Map;
4+
import io.sentrius.sso.core.dto.agents.AgentContextDTO;
5+
import io.sentrius.sso.core.model.verbs.InputInterpreterIfc;
6+
import io.sentrius.sso.core.utils.JsonUtil;
7+
8+
9+
public class AgentContextInterpreter implements InputInterpreterIfc<AgentContextDTO> {
10+
@Override
11+
public AgentContextDTO interpret(Map<String,Object> input) throws Exception {
12+
Object agentContextObj = input.get("agentContext");
13+
Object arg1Obj = input.get("arg1");
14+
15+
if (agentContextObj != null) {
16+
return JsonUtil.MAPPER.convertValue(agentContextObj, AgentContextDTO.class);
17+
} else if (arg1Obj != null) {
18+
return JsonUtil.MAPPER.convertValue(arg1Obj, AgentContextDTO.class);
19+
}
20+
return null;
21+
}
22+
}

0 commit comments

Comments
 (0)