Skip to main content

Chapter 8 : AI Agents Advanced

Event-Driven AI Workflows

  • Use pre-built Kafka based events Pre-configured for your Data
  • Use Configuration For Backend:
    • Kafka Events Producer, Consumer : Include ✅

Invoke Workflows

→ From Event Trigger, invoke AI Workflow via webhook or API call.

→ From Backend Event Consumer Service, invoke AI Workflow via WebClient API call.

- See file for details: `EmKafkaConsumerService.java`

Create Events From Workflows

→ In workflows, AI models connect to Kafka via Tools to create events.

- Use pre-built kafka event APIs and event templates pre-configured for your data.
- e.g. use tool like:
- `Tool Name: event_publish_product`

RAG and Semantic Cache

Agent Server is configured to use Redis - RAG, Semantic Cache If Backend Redis Enable Selected.

Agent Server Redis Configuration

  • Dependencies and application.properties are set for using Redis, docker image is redis-stack-server.

Loading and Storing Documents into vectorStore

  • This is manual effort. Please refer to below Spring AI doc pages:

  • Also initialize first vectorStore by uncommenting application.property:

    • spring.ai.vectorstore.redis.initialize-schema=true

Customize to Implement RAG and Semantic Cache

  • Customize Agent Server to implement them further.

RAG - Retrieval Augmented Generation

RAG Provides the LLM with knowledge context from matching documents in vectorStore.

Semantic Cache

Semantic Caching remembers previous answers to similar questions. And avoids expensive LLM calls by reusing responses for similar queries.

Advanced Agentic patterns

Try out advanced Agentic patterns after completing tutorial "Chapter 6 : AI Agents".

Getting Started Steps

In src\main\java\com\example\emagent\app\EmAgentSpringApp.java

  • Enable Run EmAgentExtra

The additional agentic patterns are called via:

  • src\main\java\com\example\emagent\app\EmAgentsExtra.java

In EmAgentsExtra.java:

Choose and Enable run flags for below patterns as required.

    boolean runEmAgentParallel = false;
boolean runEmAgentEvaluatorOptimizerFixed = false;
boolean runEmAgentEvaluatorOptimizer = false;
boolean runEmAgentOrchestratorWorkers = false;
boolean runEmAgentRouting = false;

NOTE: All Agents come with access to MCP Tools

Agentic Pattern Parallelization

  • AI Agent EmAgentParallel
  • Agentic System Workflows with agentic patterns Parallelization

Agentic Pattern Evaluator-Optimizer Fixed

  • AI Agent EmAgentEvaluatorOptimizerFixed
  • Agentic System Workflows with agentic patterns Evaluator-Optimizer
    • Fixed - means fixed number of evaluator loops.

Agentic Pattern Evaluator-Optimizer

  • AI Agent EmAgentEvaluatorOptimizer
  • Agentic System Workflows with agentic patterns Evaluator-Optimizer
    • There is no limit on number of evaluator loops. It is performed till satifying criteria.

Agentic Pattern Orchestrator-Workers

  • AI Agent EmAgentOrchestratorWorkers
  • Agentic System Workflows with agentic patterns Orchestrator-Workers

Agentic Pattern Routing

  • AI Agent EmAgentRouting
  • Agentic System Workflows with agentic patterns Routing