Annotation Interface EasyAIAssistant
Place this annotation on a Java interface. EasyAI will create an AI-powered implementation of that interface at runtime. The AI model will handle all method calls.
Basic Example
@EasyAIAssistant(systemMessage = "You are a helpful Java tutor")
public interface JavaTutor {
String ask(String question);
}
JavaTutor tutor = EasyAI.assistant(JavaTutor.class).build();
String answer = tutor.ask("What is a Stream in Java?");
With Tools (AI Calls Your Java Methods)
@EasyAIAssistant(systemMessage = "You are an e-commerce support bot")
public interface SupportBot {
String ask(String question);
}
// AI will call methods on orderService and userService automatically
SupportBot bot = EasyAI.assistant(SupportBot.class)
.withTools(orderService, userService)
.build();
With Jakarta EJB Beans as Tools
EJB beans (@Stateless, @Stateful, @Singleton) injected via
@Inject work as tools out of the box. Transactions, security, and interceptors
work normally because calls go through the EJB container proxy.
@Inject OrderService orderService; // @Stateless EJB proxy
@Inject CacheService cacheService; // @Singleton EJB proxy
SupportBot bot = EasyAI.assistant(SupportBot.class)
.withTools(orderService, cacheService) // just pass injected proxies
.build();
Combined With @EasyRAG (Document-Powered)
@EasyRAG(source = "classpath:employee-handbook.pdf")
@EasyAIAssistant(systemMessage = "Answer based on the employee handbook")
public interface HRBot {
String ask(String question);
}
CDI / Jakarta EE (Auto-Injectable, No build() Needed)
In a Jakarta EE container, annotated interfaces are automatically available for injection.
Use the tools() attribute to declare which CDI/EJB beans should be wired as tools
— the container resolves and injects them automatically:
@EasyAIAssistant(
systemMessage = "You are an e-commerce support bot",
tools = {OrderService.class, InventoryService.class}
)
public interface SupportBot {
String ask(String question);
}
// In your JSF bean / REST endpoint / EJB:
@Inject SupportBot bot; // tools are auto-wired from the CDI container
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionSystem message that defines the AI assistant's behavior and personality.Class<?>[]CDI/EJB bean classes to auto-wire as tools when this assistant is injected via@Inject.
-
Element Details
-
systemMessage
String systemMessageSystem message that defines the AI assistant's behavior and personality.This tells the AI who it is and how to behave. Examples:
- "You are a helpful customer support agent"
- "You are a code reviewer. Point out bugs and suggest improvements."
- "You are a translator. Translate all input to English."
Can be overridden at build time via
.withSystemMessage("...")- Returns:
- the system message, or empty string for none
- Default:
""
-
tools
Class<?>[] toolsCDI/EJB bean classes to auto-wire as tools when this assistant is injected via@Inject.The CDI extension resolves live instances of these classes from the container and registers their public methods as AI tools — equivalent to calling
.withTools(orderService, inventoryService)programmatically.Supported bean types:
- CDI managed beans (
@ApplicationScoped,@RequestScoped, etc.) - Jakarta EJB beans (
@Stateless,@Stateful,@Singleton) - Any class with a CDI-managed instance in the container
Example:
@EasyAIAssistant( systemMessage = "You are a sales assistant", tools = {OrderService.class, InventoryService.class, PricingService.class} ) public interface SalesBot { String ask(String question); } @Inject SalesBot bot; // all three services are wired automaticallyNote: this attribute is only used when the assistant is obtained via CDI
@Inject. When building manually withEasyAI.assistant(...).build(), use.withTools(service1, service2)on the builder instead.- Returns:
- tool bean classes to auto-wire, empty by default
- Default:
{}
- CDI managed beans (
-