DEV Community

Luvie
Luvie

Posted on

Building a Production-Ready AI Agent

Building a Production-Ready AI Agent in Pure Java: The License Compatibility Checker for Telex.imIntroduction: From Idea to Integration 🚀As part of the HNG Stage 3 Backend task, I designed and built a specialized AI agent for the Telex.im platform. My goal was to create something genuinely useful for developers: a License Compatibility Checker Agent. This agent goes beyond simple Q&A, offering on-demand license compatibility checks, detailed information, and proactive educational content—all built from scratch in Java 17+ without relying on external frameworks like Spring.This post walks through the architectural choices, the core logic (including the "clock system"), and the successful integration with the Telex A2A (Agent-to-Agent) protocol.🏗️ Architectural Design: Layered JavaTo meet the requirements for clean, maintainable, and testable code, I chose a simple Layered Architecture inspired by the classic Model-View-Controller (MVC) pattern, substituting the "View" with a dedicated formatting layer.LayerFilesPurposeMainLicenseCompatibilityAgent.javaServer setup, thread pooling, and endpoint registration (using com.sun.net.httpserver).Controllers*Controller.javaHandles HTTP requests (e.g., /v1/message, /health). Translates HTTP into service calls.Services*Service.javaContains all business logic (caching, API calls, scheduling, compatibility matrix).Utilities*Utils.java, LicenseExtractor.javaShared helpers: HTTP client, JSON parsing, NLP for query extraction, and Markdown formatting.Models*Info.javaSimple POJOs for data transfer (e.g., LicenseInfo, CompatibilityResult).Key Design Principle: Separation of ConcernsThe use of distinct classes like MessageProcessor and LicenseExtractor ensured that the agent could handle incoming JSON-RPC messages, extract complex natural language queries, fetch data from the LicenseService, and format the final Markdown response without any single class becoming bloated.💡 Core Functionality & Logic1. Data Source and Caching StrategyThe agent uses the GitHub Licenses API (https://api.github.com/licenses) as its primary, free data source.Caching: To adhere to best practices and conserve API bandwidth, the LicenseService implements an in-memory HashMap cache. When a license detail is requested (e.g., for MIT), it is fetched once from GitHub and stored. All subsequent requests for MIT are served instantly from the cache.2. The "Clock System" (Daily Posts) ⏰A core requirement was creating an agent that is both reactive (responds to users) and proactive (posts automatically).SchedulerService.java: This service uses a standard Java ScheduledExecutorService to execute a task every 24 hours.Proactive Content: The scheduled task calls the LicenseService to determine the "License of the Day" based on the day of the year (ensuring a different license is selected daily) and posts the result to a specified channel via an internal messaging mechanism.3. Compatibility LogicThe heart of the agent is in the LicenseService, which defines a pre-computed compatibility matrix based on established open-source license guidelines (e.g., GPL's Copyleft requirements). This simple logic ensures accurate and fast results for queries like: "Can I use MIT with GPL-3.0?"🔗 Integration with Telex.im (A2A Protocol)Integration was handled via three main public HTTP endpoints, ensuring full compliance with the Agent-to-Agent (A2A) JSON-RPC 2.0 standard.1. Agent Card Discovery (/.well-known/agent-card)This is the handshake for Telex. The AgentCardController serves a static agent-card.json file that clearly lists the agent's capabilities (license-compatibility-check, daily-license-insights) and skills.2. Message Handling (/v1/message)This is the main interaction point. The MessageController is responsible for:Receiving the JSON-RPC request.Extracting the user's plain text message.Calling the MessageProcessor to determine the intent (compatibility check, info request, or list request).Returning a valid JSON-RPC result object with the final Markdown-formatted response.3. Health Check (/health)A simple endpoint used by the platform for monitoring, ensuring the server is up and responsive.

Top comments (0)