Skip to content

About

Two-agent (Diagnosis + Remediation) incident automation in Spring Boot with A2A-style task cards, scoped tool calls, approval gates, pgvector traces, and an eval harness.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

A2A Incident Diagnosis + Remediation Agents

A two-agent incident automation system on Spring Boot 3 + Spring AI 1.0.x.

A Diagnosis Agent parses synthetic incidents (with linked Airflow / Jenkins / payment-job logs) into structured A2A-style task cards. A Remediation Agent selects a scoped recovery action through a tool registry with policy-driven approval gates for high-risk operations. Every prompt, decision, tool call, and human override is persisted as an audit trace, and the whole pipeline is scored by an eval harness against a labelled gold + noise set.

Stack

Java 21 · Spring Boot 3.3.x · Spring AI 1.0.x (OpenAI) · Postgres 16 + pgvector · Flyway · JUnit 5 + Testcontainers · JMH · Docker Compose.

Architecture

HTTP POST /api/incidents
        │
        ▼
IncidentIngestionService ──► IncidentService (upsert)
        │                          │
        ▼                          ▼
TaskLifecycleService            AgentOrchestrator (@Async)
                                   │
                  ┌────────────────┴───────────────┐
                  ▼                                ▼
        DiagnosisAgent                    RemediationAgent
   (Deterministic | Spring AI RAG)              │
   PROMPT + DECISION traces             policy = ToolPolicyService.require()
                  │                              │
                  ▼                  ┌───────────┴────────────┐
        DIAGNOSED card               ▼                        ▼
                                 PENDING_APPROVAL    executeNow → MockRemediationTools
                                     │                        │
                                     ▼                        ▼
                            POST /api/approvals/{id}    TOOL_CALL trace
                                     │                        │
                                     └────► COMPLETED / FAILED
  • A2A protocol surface — POST /api/incidents (202), GET /api/tasks/{id}, GET /api/tasks/{id}/stream (Server-Sent Events with backfill for late subscribers), GET /api/tasks/{id}/trace, POST /api/approvals/{id}.
  • Two diagnosis modes — selected by a2a.agent.mode:
    • deterministic (default) — pattern-matches on archetype log signatures. Cheap, offline, no API key required. Used for tests and the eval baseline.
    • spring-ai — ChatClient + VectorStore (pgvector) RAG, JSON-only output. Requires OPENAI_API_KEY.
  • Approval gate is policy-driven — the tool_policies table (seeded by Flyway V2__seed_policies.sql) decides which tools require approval and which roles may approve. No hardcoded conditionals.
  • Trace types — PROMPT, DECISION, TOOL_CALL, HUMAN_OVERRIDE, persisted in traces, queryable via /trace.

Quickstart

# 1. Postgres + pgvector
docker compose up -d postgres

# 2. Run the app (deterministic mode — no API key needed)
export A2A_FIXTURES_LOAD=true     # seed gold + noise on startup (idempotent)
mvn spring-boot:run

# 3. In another shell, run the demo
./demo.sh

To use the Spring AI path:

export OPENAI_API_KEY=sk-...
export A2A_AGENT_MODE=spring-ai
mvn spring-boot:run

Eval

A2A_EVAL_RUN=true mvn spring-boot:run
# writes target/eval-report.json with the six spec metrics

Metrics computed (EvalReport):

metric meaning
rootCauseAccuracy Diagnosis Agent label vs gold archetype
toolSelectionAccuracy Recommended tool vs archetype's correctTool
remediationSuccessRate Actionable + correct tool + tool exists in policy table
falsePositiveAutomationRate Noise inputs that recommended any non-open_ticket tool
humanOverrideRate Share of incidents marked HIGH-risk + requiresApproval=true
p95DiagnosisLatencyNanos Cold-path p95 from the harness; JMH gives the canonical number

JMH benchmark (canonical p95 latency):

mvn -DskipTests test-compile
mvn exec:java -Dexec.classpathScope=test \
    -Dexec.mainClass=com.example.a2a.bench.DiagnosisLatencyBenchmark
# results → target/jmh-result.json

Tests

mvn test                          # unit tests (no Docker required)
mvn -Dtest='*IT' -Dapi.version=1.43 verify   # integration tests (Testcontainers + pgvector)

Note for Docker Desktop ≥ 4.30 / Docker Engine ≥ 25: the bundled docker-java client defaults to API version 1.32, which the modern daemon rejects. Pass -Dapi.version=1.43 (any value ≥ 1.40 works) so Testcontainers can negotiate. If DOCKER_HOST is unset, also export it explicitly, e.g. export DOCKER_HOST=unix:///var/run/docker.sock.

The integration suite spins up pgvector/pgvector:pg16 via Testcontainers and exercises:

  • low-risk incident ingestion → auto-execute → COMPLETED,
  • high-risk incident → halt at PENDING_APPROVAL → POST /api/approvals → COMPLETED,
  • full audit trail readable from /api/tasks/{id}/trace.

Environment variables

var default purpose
SPRING_DATASOURCE_URL jdbc:postgresql://localhost:5432/a2a DB URL
SPRING_AI_OPENAI_API_KEY empty required only when A2A_AGENT_MODE=spring-ai
A2A_AGENT_MODE deterministic deterministic | spring-ai
A2A_FIXTURES_LOAD false seed gold + noise on startup
A2A_EVAL_RUN false run eval harness on startup

Trade-offs (intentional, called out in code)

  • @Async orchestration uses Spring's default SimpleAsyncTaskExecutor — fine for a demo; production would swap in a bounded ThreadPoolTaskExecutor.
  • Mock tools — every MockRemediationTools method emits a literal (MOCK) marker so logs and traces are unmistakable. Real integrations (Jenkins API, Airflow REST, ServiceNow / Jira) are intentionally out of scope.
  • Eval harness measures diagnosis only, not full end-to-end task lifecycle. The deterministic agent + mock tools mean the only failure mode for remediation is missing policy rows, which is asserted directly. End-to-end ingestion is covered by the IT suite.
  • SSE backfill — late subscribers receive a single replay of the current task state on connect, then live deltas. Not full replay-from-zero.

Project layout

src/main/java/com/example/a2a
├── api/            REST controllers (Incident, Task, Approval)
├── agent/
│   ├── diagnosis/  DiagnosisAgent + Deterministic / SpringAi impls
│   └── remediation/MockRemediationTools, ToolPolicyService,
│                   ApprovalGateService, RemediationAgent
├── service/        IncidentService, TaskLifecycleService, TraceService,
│                   IncidentIngestionService, AgentOrchestrator
├── domain/         Records (Incident, TaskCard, ToolPolicy, …)
├── repository/     Spring Data JPA repos + entities
├── eval/           EvalHarness, EvalReport, EvalRunner
└── fixture/        IncidentFixtureFactory (Archetype enum), GoldSetLoader

About

Two-agent (Diagnosis + Remediation) incident automation in Spring Boot with A2A-style task cards, scoped tool calls, approval gates, pgvector traces, and an eval harness.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages