From developer-kit-java
Provides patterns for building declarative AI services in Java with LangChain4j: type-safe interfaces, annotations, memory management, tools for chatbots, agents, and conversational AI.
How this skill is triggered — by the user, by Claude, or both
Slash command
/developer-kit-java:langchain4j-ai-services-patternsThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill provides guidance for building declarative AI Services with LangChain4j using interface-based patterns, annotations for system and user messages, memory management, tools integration, and advanced AI application patterns that abstract away low-level LLM interactions.
This skill provides guidance for building declarative AI Services with LangChain4j using interface-based patterns, annotations for system and user messages, memory management, tools integration, and advanced AI application patterns that abstract away low-level LLM interactions.
LangChain4j AI Services define AI functionality using Java interfaces with annotations, providing type-safe, declarative AI with minimal boilerplate.
Use this skill when:
Follow these steps to create declarative AI Services with LangChain4j:
Create a Java interface with method signatures for AI interactions:
interface Assistant {
String chat(String userMessage);
}
Use @SystemMessage and @UserMessage annotations to define prompts:
interface CustomerSupportBot {
@SystemMessage("You are a helpful customer support agent for TechCorp")
String handleInquiry(String customerMessage);
@UserMessage("Analyze sentiment: {{it}}")
Sentiment analyzeSentiment(String feedback);
}
Use AiServices builder or create to instantiate the service:
// Simple creation
Assistant assistant = AiServices.create(Assistant.class, chatModel);
// Or with builder for advanced configuration
Assistant assistant = AiServices.builder(Assistant.class)
.chatModel(chatModel)
.build();
Add memory management using @MemoryId for multi-user scenarios:
interface MultiUserAssistant {
String chat(@MemoryId String userId, String userMessage);
}
Assistant assistant = AiServices.builder(MultiUserAssistant.class)
.chatModel(model)
.chatMemoryProvider(userId -> MessageWindowChatMemory.withMaxMessages(10))
.build();
Register tools using @Tool annotation to enable AI function execution:
class Calculator {
@Tool("Add two numbers") double add(double a, double b) { return a + b; }
}
interface MathGenius {
String ask(String question);
}
MathGenius mathGenius = AiServices.builder(MathGenius.class)
.chatModel(model)
.tools(new Calculator())
.build();
Test AI services with concrete validation patterns:
// 1. Test with sample inputs
String response = assistant.chat("Hello, how are you?");
assert response != null && !response.isEmpty();
// 2. Validate structured outputs with assertions
Sentiment result = bot.analyzeSentiment("Great product!");
assert result == Sentiment.POSITIVE;
// 3. Log tool calls with side effects for audit
MathGenius math = AiServices.builder(MathGenius.class)
.chatModel(model)
.tools(new Calculator())
.build();
// 4. Test memory isolation between users
String userA = assistant.chat("User A message", "session-a");
String userB = assistant.chat("User B message", "session-b");
assert !userA.equals(userB); // Verify memory isolation
See examples.md for comprehensive practical examples including:
Complete API documentation, annotations, interfaces, and configuration patterns are available in references.md.
<!-- Maven -->
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
<version>1.8.0</version>
</dependency>
// Gradle
implementation 'dev.langchain4j:langchain4j:1.8.0'
implementation 'dev.langchain4j:langchain4j-open-ai:1.8.0'
npx claudepluginhub giuseppe-trisciuoglio/developer-kit --plugin developer-kit-javaGenerates LangChain4j tool calling patterns: annotates methods with @Tool and @P, registers tools via AiServices, validates parameters, handles errors. For AI agents integrating external APIs.
Integrates Spring AI or LangChain4J into Spring Boot projects for AI features like chatbots, RAG, vector stores, streaming LLM responses, and tool calls.
Sets up Dokimos evaluation for LangChain4j apps and RAG pipelines with Q&A tasks, faithfulness, relevance, and retrieval checks.