This document describes the LLM-guided scheduling and two-party approval features for the analytics and monitoring agents.
The analytics and monitoring agents have been enhanced with:
- LLM-Guided Scheduling: Agents consult an LLM to determine optimal timing for evaluations
- Chat Interface: WebSocket-based chat for querying status and requesting changes
- Two-Party Approval: Configuration changes require approval from a second user with ZTAT token
Add to application.properties:
# Enable LLM-guided scheduling for analytics agent
agents.analytics.enabled=true
agents.analytics.llm-guided=true
agents.analytics.name=analytics-agent
# Enable LLM-guided monitoring
agents.monitoring.enabled=true
agents.monitoring.llm-guided=true
agents.monitoring.name=monitoring-agent
# LLM guidance intervals (optional)
agents.analytics.llm-guidance-interval=300000 # 5 minutes
agents.monitoring.llm-guidance-interval=60000 # 1 minute# Enable chat for analytics agent
agents.analytics.chat.enabled=true
agent.listen.websocket=true
# Enable chat for monitoring agent
agents.monitoring.chat.enabled=trueLLM guidance requires OpenAI integration to be configured. Ensure you have:
- OpenAI API token configured in the system
- Integration security token for OpenAI in the database
When a scheduled task is triggered:
- Check LLM Availability: Determine if LLM guidance service is enabled
- Consult LLM: Send context about the evaluation to the LLM
- Receive Recommendation: LLM responds with a score (0.0 - 1.0)
- Make Decision: Run evaluation if score exceeds threshold
- Fallback: If LLM unavailable, run evaluation normally
// Without LLM guidance (old behavior)
@Scheduled(fixedRate = 300000)
public void evaluateAllAgentsAndUsers() {
performEvaluation();
}
// With LLM guidance (new behavior)
@Scheduled(fixedRate = 300000)
public void evaluateAllAgentsAndUsers() {
if (llmScheduler != null && llmScheduler.isEnabled()) {
llmScheduler.shouldRunTrustEvaluation().thenAccept(shouldRun -> {
if (shouldRun) {
performEvaluation();
}
});
} else {
performEvaluation(); // Fallback
}
}Different evaluations use different thresholds:
| Evaluation Type | Threshold | Rationale |
|---|---|---|
| Session Summarization | 0.4 | Should run frequently |
| Trust Evaluation | 0.5 | Balanced frequency |
| Automation Analysis | 0.6 | Can run less often |
| Memory Evaluation | 0.7 | Can be deferred |
| Endpoint Monitoring | 0.5 | Balanced health checks |
| Stability Evaluation | 0.6 | Can be optimized |
- Resource Optimization: Skip evaluations when not needed
- Dynamic Scheduling: Adjust based on system activity
- Intelligent Prioritization: Focus on what matters most
- Cost Reduction: Reduce unnecessary computation
Analytics Agent:
ws://[host]:[port]/api/v1/analytics/chat/subscribe?sessionId=[UUID]&chatGroupId=[groupId]&ztat=[token]
Monitoring Agent:
ws://[host]:[port]/api/v1/monitoring/chat/subscribe?sessionId=[UUID]&chatGroupId=[groupId]&ztat=[token]
Both agents use ZTAT (Zero Trust Access Token) with challenge-response:
- Client connects with ZTAT token in query parameters
- Server sends a challenge nonce
- Client signs the nonce and sends back signature + public key
- Server verifies the signature
- Connection is authenticated
Request:
{
"type": "get-status"
}Response:
Analytics Agent Status
======================
Agent Name: analytics-agent
Running: Yes
The analytics agent performs trust evaluation, session analysis, and automation suggestions.
Request:
{
"type": "request-config-change",
"changeType": "ENABLE_LLM_GUIDANCE",
"configKey": "llm.enabled",
"newValue": "true",
"reason": "Enable LLM guidance for better scheduling",
"requestedBy": "admin"
}Response:
Configuration change requested successfully.
Change ID: abc-123-def-456
Type: ENABLE_LLM_GUIDANCE
Status: PENDING_APPROVAL
This change requires approval from a second party with a valid ZTAT token.
Use {"type":"approve-config-change","changeId":"abc-123-def-456","approver":"supervisor","ztat":"token"} to approve.
Request:
{
"type": "approve-config-change",
"changeId": "abc-123-def-456",
"approver": "supervisor",
"ztat": "valid-ztat-token"
}Response:
Configuration change approved and applied successfully.
Change ID: abc-123-def-456
Type: ENABLE_LLM_GUIDANCE
Approved by: supervisor
Status: APPLIED
Request:
{
"type": "list-pending-changes"
}Response:
Pending Configuration Changes
================================
Change ID: abc-123-def-456
Type: UPDATE_THRESHOLD
Requested by: admin
Requested at: 2025-11-24T10:30:00Z
Reason: Adjust monitoring threshold for better accuracy
Request:
{
"type": "get-endpoint-health"
}Response:
Endpoint Health Information
===========================
Endpoint: http://localhost:8080/actuator/health
Status: HEALTHY
Last Check: 2025-11-24T10:30:00Z
Response Time: 150 ms
Error Rate: 0.50%
Request:
{
"type": "get-monitoring-config"
}Response:
Monitoring Configuration
========================
Endpoint: http://localhost:8080/actuator/health
Service Name: sentrius-api
Response Time Threshold: 1000 ms
Error Rate Threshold: 5.0%
AI Evaluation: Enabled
┌─────────────┐
│ User A │
│ Requests │
│ Change │
└──────┬──────┘
│
▼
┌─────────────────────┐
│ PENDING_APPROVAL │
│ Change stored │
│ Awaiting approval │
└──────┬──────────────┘
│
▼
┌─────────────┐
│ User B │
│ (Different)│
│ Approves │
│ with ZTAT │
└──────┬──────┘
│
▼
┌─────────────────────┐
│ ZTAT Validated │
│ Change APPROVED │
└──────┬──────────────┘
│
▼
┌─────────────────────┐
│ Change APPLIED │
│ Provenance logged │
└─────────────────────┘
- Different Users: Approver must be different from requester
- Valid ZTAT: Approval requires a valid ZTAT token
- Token Verification: ZTAT token is validated before applying change
- Audit Trail: All changes logged to provenance system
Analytics Agent:
ENABLE_LLM_GUIDANCEDISABLE_LLM_GUIDANCEUPDATE_HEARTBEAT_INTERVALENABLE_EVALUATIONDISABLE_EVALUATIONUPDATE_EVALUATION_THRESHOLDUPDATE_SCHEDULE
Monitoring Agent:
ENABLE_LLM_GUIDANCEDISABLE_LLM_GUIDANCEUPDATE_CHECK_INTERVALADD_ENDPOINTREMOVE_ENDPOINTUPDATE_THRESHOLDENABLE_NOTIFICATIONDISABLE_NOTIFICATION
# Test analytics agent
mvn test -pl analytics
# Test monitoring agent
mvn test -pl monitoring
# Test both
mvn test -pl analytics,monitoring- Start the agents with LLM and chat enabled
- Connect via WebSocket with valid ZTAT token
- Request a configuration change
- Approve from a different user with valid ZTAT
- Verify change is applied by checking agent status
- Check OpenAI integration is configured
- Verify
agents.*.llm-guided=trueis set - Check logs for LLM service errors
- Agents will continue to work without LLM (fail-safe)
- Ensure
agents.*.chat.enabled=trueis set - Ensure
agent.listen.websocket=trueis set - Verify ZTAT token is valid and not expired
- Check WebSocket endpoint is accessible
- Verify approver is different from requester
- Check ZTAT token is valid
- Ensure change is in PENDING_APPROVAL status
- Check logs for detailed error messages
┌────────────────────────────────────────────────────────────┐
│ Scheduled Task │
│ (Trust Eval, Endpoint Monitoring, etc.) │
└────────────┬───────────────────────────────────────────────┘
│
▼
┌─────────────┐
│ LLM Enabled?│
└──────┬──────┘
│ Yes
▼
┌────────────────────────────────┐
│ LLMGuidedSchedulerService │
│ - shouldRunTrustEvaluation() │
│ - shouldRunEndpointMonitoring()│
└────────────┬───────────────────┘
│
▼
┌────────────────────────────────┐
│ OpenAITwoPartyMonitorService │
│ - analyzeTerminalLogs() │
└────────────┬───────────────────┘
│
▼
┌─────────────┐
│ Score ≥ │
│ Threshold? │
└──────┬──────┘
│ Yes
▼
┌─────────────┐
│ Run │
│ Evaluation │
└─────────────┘
// 1. Connect to analytics agent
const ws = new WebSocket('ws://localhost:8080/api/v1/analytics/chat/subscribe?...');
// 2. Request change
ws.send(JSON.stringify({
type: 'request-config-change',
changeType: 'ENABLE_LLM_GUIDANCE',
configKey: 'llm.enabled',
newValue: 'true',
reason: 'Optimize scheduling with LLM',
requestedBy: 'admin'
}));
// 3. Another user approves
ws2.send(JSON.stringify({
type: 'approve-config-change',
changeId: 'abc-123',
approver: 'supervisor',
ztat: 'valid-token'
}));Potential improvements:
- Persistent storage for configuration changes
- Change rollback capability
- Scheduled changes (apply at specific time)
- Multi-step approval workflows
- Integration with external approval systems
- Real-time LLM guidance updates
- Custom thresholds per evaluation type
- Historical analytics on LLM decisions