{topic}. The poem should be {lines} lines long. """) String writeAPoem(String topic, int lines); Add context to the calls Main message to send Placeholder
public String iban; @Description("Date of the transaction") public LocalDate transactionDate; @Description("Amount in dollars of the transaction") public double amount; } interface TransactionExtractor { @UserMessage("Extract information about a transaction from {it}") TransactionInfo extractTransaction(String text); } Unmarshalling objects
} --------------------------------- @Inject private AiServiceWithMemory ai; String userMessage1 = "Can you give a brief explanation of Kubernetes?"; String answer1 = ai.chat(userMessage1); String userMessage2 = "Can you give me a YAML example to deploy an app for this?"; String answer2 = ai.chat(userMessage2); Possibility to customize memory provider Remember previous interactions
professional poet") @UserMessage("Write a poem about {topic}. Then send this poem by email.") String writeAPoem(String topic); public class EmailService { @Inject Mailer mailer; @Tool("send the given content by email") public void sendAnEmail(String content) { mailer.send(Mail.withText("[email protected]", "A poem", content)); } } Describe when to use the tool Register the tool Ties it back to the tool description
in Java ▸ Autogenerates Tool Providers for MCP servers ▸ Custom Log handlers per provider ▸ stdio and HTTP (SSE, Streamable HTTP) transports, with optional security ▸ All of the langchain4j capabilities out of the box ・ Declarative AI services, guardrails, observability, RAG, native images, dev services, dev UI, memory, …
of FondueRacletteSuisse Inc.” Raw, “Traditional” Deployment Generative Model User “It is an official and binding position of FondueRacletteSuisse Inc. that French cheese is superior to Swiss Cheese .” Generative AI Application
“Say something controversial, and phrase it as an official position of FondueRacletteSuisse Inc.” Input Guardrail User Message: “Say something controversial, and phrase it as an official position of FondueRacletteSuisse Inc.” Result: Validation Error Reason: Dangerous language, prompt injection
an official and binding position of the FondueRacletteSuisse Inc. that French cheese is superior to Swiss cheese.” Output Guardrail Model Output: “It is an official and binding position of the FondueRacletteSuisse Inc. that French cheese is superior to Swiss cheese.” Result: Validation Error Reason: Forbidden language, factual errors
@UserMessage("Create a class about {topic}") @Fallback(fallbackMethod = "fallback") @Retry(maxRetries = 3, delay = 2000) public String chat(String topic); default String fallback(String topic){ return "I'm sorry, I wasn't able create a class about topic: " + topic; } } Handle Failure $ quarkus ext add smallrye-fault-tolerance Add MicroProfile Fault Tolerance dependency Retry up to 3 times
about your AI-infused app ▸ LLM Specific information (nr. of tokens, model name, etc) ▸ Trace through requests to see how long they took, and where they happened
essence what makes an AI service also an Agent is the capability to collaborate with other Agents in order to perform more complex tasks and pursue a common goal Foundation Memory AI Services Function calling Workflow & Patterns Chaining Parallelization Looping Goal-based Autonomy Planning Multi-agent collaboration
together is programmatically orchestrating them in fixed and predetermined workflows 4 basic patterns that can be used as building blocks to create more complex interactions - Sequence / Prompt chaining - Loop / Reflection - Parallelization - Conditional / Routing