feat(graph): add diagnosis real nodes

This commit is contained in:
zhuyongxin
2026-07-17 16:44:05 +08:00
parent 42ba204532
commit 1460dd1e99
57 changed files with 4380 additions and 710 deletions
@@ -0,0 +1,79 @@
package com.superbiz.agent.graph.diagnosis;
import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.RunnableConfig;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
class VerifiedInputNodeTest {
@Test
@SuppressWarnings("unchecked")
void projectsOnlyClaimsWithExactlyMatchedPassedBindings() throws Exception {
Map<String, Object> passedBinding = Map.of(
"tool_name", "query_metrics",
"source_invocation_id", 11L,
"raw_path", "$.alerts[0]",
"evidence_excerpt", "active=50 max=50");
Map<String, Object> failedBinding = Map.of(
"tool_name", "query_logs",
"source_invocation_id", 12L,
"raw_path", "$.logs[0]",
"evidence_excerpt", "suspected leak");
Map<String, Object> executorOutput = Map.of(
"answer_version", "executor_evidence_v2",
"claims", List.of(
Map.of("claim_id", "c1", "claim_text", "连接数达到上限",
"claim_type", "symptom", "support_level", "direct",
"evidence_bindings", List.of(passedBinding, failedBinding)),
Map.of("claim_id", "c2", "claim_text", "存在连接泄漏",
"claim_type", "root_cause", "support_level", "indirect",
"evidence_bindings", List.of(failedBinding))),
"hypotheses", List.of(Map.of("hypothesis_text", "must-not-leak")));
Map<String, Object> gatekeeper = Map.of(
"status", "fail",
"severity", "low_confid",
"checked_bindings", List.of(
Map.of("claim_id", "c1", "status", "pass",
"tool_name", "query_metrics",
"source_invocation_id", 11L,
"raw_path", "$.alerts[0]",
"matched_text", "active=50 max=50"),
Map.of("claim_id", "c1", "status", "fail",
"tool_name", "query_logs",
"source_invocation_id", 12L,
"raw_path", "$.logs[0]"),
Map.of("claim_id", "c3", "status", "pass",
"tool_name", "query_metrics",
"source_invocation_id", 99L,
"raw_path", "$.alerts[9]",
"matched_text", "unreferenced")));
VerifiedInputNode node = new VerifiedInputNode();
Map<String, Object> update = node.apply(new OverAllState(Map.of(
DiagnosisGraphState.EXECUTOR_OUTPUT, executorOutput,
DiagnosisGraphState.GATEKEEPER_RESULT, gatekeeper,
DiagnosisGraphState.EVIDENCE_RETRY_COUNT, 0)),
RunnableConfig.builder().threadId("run-verified").build()).get();
Map<String, Object> verifiedOutput = (Map<String, Object>) update.get(
DiagnosisGraphState.VERIFIED_EXECUTOR_OUTPUT);
List<Map<String, Object>> claims =
(List<Map<String, Object>>) verifiedOutput.get("claims");
assertEquals(List.of("c1"),
claims.stream().map(claim -> claim.get("claim_id")).toList());
assertEquals(List.of(passedBinding), claims.get(0).get("evidence_bindings"));
assertFalse(verifiedOutput.containsKey("hypotheses"));
List<Map<String, Object>> evidence =
(List<Map<String, Object>>) update.get(
DiagnosisGraphState.VERIFIED_EVIDENCE);
assertEquals(List.of("active=50 max=50"),
evidence.stream().map(item -> item.get("matched_text")).toList());
assertEquals(1, update.get(DiagnosisGraphState.VERIFIED_BINDING_COUNT));
}
}