Class EasyAgent
Unlike a regular AI assistant (which answers a single question),
an EasyAgent receives a complex task and breaks it into steps,
calling your service methods in the right order, using the result of
each step to decide what to do next.
Quick Start
// Your existing Jakarta EE services — no changes needed
@Stateless InventoryService inventoryService;
@Stateless PaymentService paymentService;
@Stateless OrderService orderService;
EasyAgent agent = EasyAI.agent()
.withServices(inventoryService, paymentService, orderService)
.withMaxSteps(10)
.withPlanningPrompt(true)
.withStepListener(step ->
log.info("[AGENT] Step {}: {}({}) -> {}",
step.stepNumber(), step.toolName(),
step.arguments(), step.result()))
.build();
String result = agent.execute(
"Order 2 laptops for user U123, apply loyalty credit, " +
"use fallback warehouse WH-EU if out of stock."
);
What the agent does autonomously
- Receives the task description
- Plans which service methods to call and in what order
- Executes each step, passing results forward
- Adapts the plan if a step fails or returns unexpected data
- Returns a final natural-language summary when done
Safety
Always set withMaxSteps() to cap the number of tool calls.
Without a limit, a complex task could generate many sequential calls,
significantly increasing token usage and cost. The default is 10 steps.
Transactional note
EasyAgent does not manage transactions across steps. If the agent calls
payment.process() and then fails on the next step, the payment
will not be rolled back. Design your services to be idempotent or provide
compensating transactions where needed.
- See Also:
-
Method Summary
-
Method Details
-
execute
Executes the given task description.The agent will autonomously call your registered services in the correct order to complete the task, up to the configured
maxStepslimit.String result = agent.execute( "Poruči 2 laptopa za korisnika U123, iskoristi loyalty kredit, " + "dostavi na Beograd. Ako nema na lageru, uzmi iz magacina WH-EU." );- Parameters:
task- a natural-language description of the task to perform- Returns:
- a natural-language summary of what was done and the final outcome
-