Want to turn your existing Java Spring Boot services into AI-powered microservices — without rewriting your entire codebase?
Meet ACPJava Agent Communication Protocol (ACP) — a lightweight, annotation-driven Java framework that lets you convert your Spring Boot classes into intelligent AI agents with zero boilerplate.ACPJava is pure java implementation of ACP protocol.
Whether you’re building multi-agent AI systems, LLM-powered APIs, or collaborative microservices, ACP makes it effortless to expose your services as discoverable, AI-ready endpoints using just @agent and @Action annotations.
Code for this article is here
Real-World Implementation: From Code to AI Agent
Let’s walk through a practical example that demonstrates the power of ACP. We’ll create a food preference service that can be accessed by AI systems.
Step 1: Creating Your First Agent
@Service
@Agent(groupName ="foodpreferences",
groupDescription = "Provide persons name and find out what they like")
@Slf4j
public class SimpleService {
@Action(description = "Get the favourite food of a person")
public String whatThisPersonFavFood(String name) {
if("vishal".equalsIgnoreCase(name))
return "Paneer Butter Masala";
else if ("vinod".equalsIgnoreCase(name))
return "Aloo Kofta";
else
return "Something delicious";
}
}
That’s it! With just two annotations, you’ve created an AI-accessible agent. No complex configurations, no middleware setup, no API documentation to write manually.
Step 2: Building Complex Multi-Action Agents
Real-world applications often require multiple related capabilities. Here’s how you can create a comprehensive car services agent:
@Service
@Agent(groupName ="carservices",
groupDescription = "All services related to cars and automobiles")
public class CarService {
@Action(description = "Compare two cars and provide recommendations")
public String compareCar(String car1, String car2) {
// Your comparison logic here
return car2 + " offers better value than " + car1;
}
@Action(description = "Purchase a car with cash for maximum discount")
public String buyCarWithCash(String carModel, int cashAmount) {
return "Successfully purchased " + carModel + " for $" + cashAmount;
}
@Action(description = "Finance a car purchase with flexible terms")
public String buyCarWithLoan(String carModel, int loanAmount, int downPayment) {
return "Financed " + carModel + " with $" + downPayment + " down";
}
}
The Magic: Auto-Generated Agent Manifests
Here’s where ACP really shines. When you start your application, it automatically generates a comprehensive manifest that describes all your agents and their capabilities:
The generated manifest includes detailed metadata about each agent, making it easy for AI systems to understand what services are available and how to use them.
Client Integration: Connecting AI to Your Services
The client-side implementation is equally elegant. Here’s how AI systems or other applications can discover and interact with your agents:
public class ACPClientExample {
public static void main(String[] args) {
ACPClient client = new ACPClient("http://localhost:7860");
// Discover available agents
List<AgentManifest> agents = client.listAgents(10, 0);
// Create a natural language request
Message message = new Message();
message.setRole(MessageRole.USER);
MessagePart part = new MessagePart();
part.setContent("What food does Vishal like?");
message.setParts(List.of(part));
// Execute the request
Run result = client.executeSync("foodpreferences", List.of(message));
// Output: "Paneer Butter Masala"
}
}
The Communication Flow: How It All Works Together
Understanding the complete communication flow helps appreciate the elegance of this system:
This sequence diagram illustrates how seamlessly requests flow from AI clients through the ACP layer to your existing business logic and back.
Top comments (0)