or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/io.quarkiverse.langchain4j/quarkus-langchain4j-core@1.5.x

docs

index.md
tile.json

tessl/maven-io-quarkiverse-langchain4j--quarkus-langchain4j-core

tessl install tessl/maven-io-quarkiverse-langchain4j--quarkus-langchain4j-core@1.5.0

Quarkus LangChain4j Core provides runtime integration for LangChain4j with the Quarkus framework, enabling declarative AI service creation through CDI annotations.

response-augmentation.mddocs/reference/

Response Augmentation

Response Augmentation allows transformation and enhancement of AI responses using custom augmenters for both regular and streaming responses. This experimental feature enables post-processing of AI outputs.

Capabilities

@ResponseAugmenter Annotation

Configure response augmentation on AiService methods or entire interfaces.

// Package: io.quarkiverse.langchain4j.response
/**
 * Configure response augmentation for AI service methods.
 * EXPERIMENTAL: API may change in future versions.
 */
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Experimental("Response augmentation is experimental and may change")
public @interface ResponseAugmenter {
    /**
     * AiResponseAugmenter implementation class.
     * CDI bean will be instantiated and used to augment responses.
     */
    Class<? extends AiResponseAugmenter<?>> value();
}

Usage Example:

import io.quarkiverse.langchain4j.RegisterAiService;
import io.quarkiverse.langchain4j.response.ResponseAugmenter;
import io.smallrye.mutiny.Multi;

@RegisterAiService
public interface Assistant {

    @ResponseAugmenter(FormatAugmenter.class)
    String chat(String message);

    @ResponseAugmenter(StreamingFormatAugmenter.class)
    Multi<String> chatStreaming(String message);
}

AiResponseAugmenter Interface

Generic interface for augmenting AI responses.

// Package: io.quarkiverse.langchain4j.response
/**
 * Interface for augmenting AI responses.
 * Supports both regular and streaming responses.
 * EXPERIMENTAL: API may change in future versions.
 *
 * @param <T> Response type
 */
@Experimental("Response augmentation is experimental and may change")
public interface AiResponseAugmenter<T> {

    /**
     * Augment a regular (non-streaming) response.
     * Default implementation returns response unchanged.
     *
     * @param response The original response from the AI model
     * @param params Parameters including user message, memory, and RAG context
     * @return The augmented response
     */
    default T augment(T response, ResponseAugmenterParams params) {
        return response;
    }

    /**
     * Augment a streaming response.
     * Default implementation returns stream unchanged.
     *
     * @param stream The original streaming response from the AI model
     * @param params Parameters including user message, memory, and RAG context
     * @return The augmented streaming response
     */
    default Multi<T> augment(Multi<T> stream, ResponseAugmenterParams params) {
        return stream;
    }
}

Implementation Example:

import io.quarkiverse.langchain4j.response.AiResponseAugmenter;
import io.quarkiverse.langchain4j.response.ResponseAugmenterParams;
import jakarta.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class MarkdownAugmenter implements AiResponseAugmenter<String> {

    @Override
    public String augment(String response, ResponseAugmenterParams params) {
        // Add markdown formatting
        return "**AI Response:**\n\n" + response + "\n\n---\nPowered by AI";
    }

    @Override
    public Multi<String> augment(Multi<String> stream, ResponseAugmenterParams params) {
        // Add markdown header and footer to streaming response
        return Multi.createFrom().concat(
            Multi.createFrom().item("**AI Response:**\n\n"),
            stream,
            Multi.createFrom().item("\n\n---\nPowered by AI")
        );
    }
}

Types

ResponseAugmenterParams

Record containing parameters available to response augmenters.

// Package: io.quarkiverse.langchain4j.response
/**
 * Parameters passed to response augmenters.
 * Provides access to original user message, chat memory, RAG results, and template variables.
 */
public record ResponseAugmenterParams(
    UserMessage userMessage,
    ChatMemory memory,
    AugmentationResult augmentationResult,
    String userMessageTemplate,
    Map<String, Object> variables
) {
    /**
     * @param userMessage The original user message
     * @param memory The chat memory (may be null)
     * @param augmentationResult RAG augmentation result (may be null)
     * @param userMessageTemplate Original message template before variable substitution
     * @param variables Template variables used in message
     */
}

Use Cases

Response augmentation is useful for:

  • Formatting: Add markdown, HTML, or other formatting to responses
  • Citations: Add source citations from RAG results
  • Metadata: Inject metadata like timestamps, model info, or token counts
  • Validation: Validate and clean up response content
  • Caching: Cache responses for reuse
  • Translation: Translate responses to different languages
  • Summarization: Create executive summaries of long responses
  • Filtering: Remove or redact sensitive content from responses