DEV Community

Anton Illarionov
Anton Illarionov

Posted on

Java + Spring AI + ODEI: Enterprise AI Agents with Constitutional Governance

Java + Spring AI + ODEI: Enterprise AI Agents with Constitutional Governance

Enterprise Java teams adopting AI need governance. ODEI provides it.

Spring AI Integration

@Service
public class ConstitutionalAgentService {

    private final RestTemplate restTemplate = new RestTemplate();
    private final String odeiToken;
    private final String odeiBase = "https://api.odei.ai/api/v2";

    public ConstitutionalAgentService(@Value("${odei.token}") String token) {
        this.odeiToken = token;
    }

    public boolean checkAction(String action, String severity) {
        HttpHeaders headers = new HttpHeaders();
        headers.setBearerAuth(odeiToken);
        headers.setContentType(MediaType.APPLICATION_JSON);

        Map<String, String> body = Map.of(
            "action", action,
            "severity", severity
        );

        ResponseEntity<Map> response = restTemplate.exchange(
            odeiBase + "/guardrail/check",
            HttpMethod.POST,
            new HttpEntity<>(body, headers),
            Map.class
        );

        return "APPROVED".equals(response.getBody().get("verdict"));
    }

    public void safeExecute(String action, Runnable fn) {
        if (checkAction(action, "medium")) {
            fn.run();
        } else {
            log.warn("Action blocked by constitutional guardrail: {}", action);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Spring Boot Configuration

# application.yml
odei:
  token: ${ODEI_API_KEY}
  base-url: https://api.odei.ai/api/v2

spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY}
Enter fullscreen mode Exit fullscreen mode

Why Enterprise Needs Constitutional AI

Enterprise autonomous agents face compliance requirements that most AI frameworks ignore:

  • Audit trails (every action logged)
  • Authorization chains (who approved this?)
  • Deduplication (no double-processing)
  • Constitutional alignment (regulatory compliance)

ODEI's 7-layer validation satisfies all four.

Production

ODEI in production since January 2026. 92% task success rate.

Top comments (0)