Companion examples for AI Agents with Java by Alex Soto Bueno, Markus Eisele, and Mario Fusco, published by O’Reilly Media.
Read the book on O’Reilly · Book organization
Explore agent coordination, memory, retrieval, tool use, communication protocols, security, and observability through Java and Quarkus examples.
Each project has its own pom.xml and dependencies. There is no root Maven build; run commands from the example’s directory.
| Directory | Topics and projects |
|---|---|
| ch03/chatmemory | Chat memory, persistent memory, and input/output guardrails |
| ch05 | Agentic workflows, supervisors, goal-oriented action planning (GOAP), and peer-to-peer coordination |
| ch07 | Retrieval-augmented generation (RAG), HTML transformation, query compression, and Presidio document transformation |
| ch08/current-time-tool | Tool calling, low-level tool execution, and dynamic tools |
| ch10 | Model Context Protocol (MCP) clients and servers, incident management, resources, and advanced server features |
| ch11 | Agent2Agent (A2A) clients and agents, human interaction, security, and replication |
| ch13 | Action policies, approval validation, context selection, audit events, and isolated Java execution |
| ch14/observability | Agent tracing and metrics with OpenTelemetry, Grafana, and LangSmith |
| ch77 | Embeddings, chunking, hybrid search, multimodal RAG, movie recommendations, and shopping question answering |
This index follows the source directories in this checkout. Use the book alongside each example for its explanation and context.
- JDK: Check the selected project’s
pom.xml. Projects target Java 17, 21, or 25; several require JDK 25 to compile. - Maven: Use
./mvnwwhere a wrapper is included, or an installed Maven where it is absent. On Windows, usemvnw.cmdfor projects with a wrapper. - Model access: Requirements vary by example, as described below.
- Additional services: Some projects need containers, databases, or other services. MCP clients that launch
npxalso need Node.js and npm.
Check which Java installation your build uses:
java -version
mvn --versionClone the source repository and run the Chapter 13 action-policy example with JDK 21 or later and Maven:
git clone https://github.com/ai-agents-with-java-book/ai-agents-with-java-book-src.git
cd ai-agents-with-java-book-src/ch13
mvn compile
java -cp target/classes org.acme.security.ActionPolicyExampleThe example evaluates proposed actions and prints:
DRAFT_REPLY: ALLOW / DRAFT_ONLY
REQUEST_REPLACEMENT: REQUIRE_APPROVAL / REVIEW_REPLACEMENT
EXPORT_CASES: DENY / OPERATION_NOT_GRANTED
OTHER_CASE: CASE_ACCESS_DENIED
See the Chapter 13 README for the other security examples and the separate container requirements for isolated execution.
From the repository root, use JDK 21 or later to build and run the current-time tool:
cd ch08/current-time-tool
./mvnw package
java -jar target/my-app-1.0-SNAPSHOT-jar-with-dependencies.jarThe application asks a model to answer a date-and-time question using the Java Clock tool. Its source is configured for the LangChain4j demo endpoint with the demo API key, so it needs network access and depends on that service’s availability.
Other standalone Java projects can contain several main classes. Select the class for the example you are following; do not assume every project’s packaged JAR launches every example.
There is no shared model configuration for the repository. Inspect the selected project’s Java model builder and, for Quarkus applications, src/main/resources/application.properties.
- Chat memory:
ch03/chatmemoryuses Ollama withqwen2.5:7b. Its default address ishttp://127.0.0.1:11434;OLLAMA_BASE_URLoverrides it. Make the model available in Ollama before running an example. - Chapter 5: Model providers read
OPENAI_API_KEY; alternative provider code also referencesCEREBRAS_API_KEY. - Demo-backed examples: Several RAG, tool, and MCP examples configure the LangChain4j demo endpoint directly in source.
- Observability:
ch14/observabilityrequiresOPENAI_API_KEY. The LangSmith profile also usesLANGSMITH_API_KEY, with optionalLANGSMITH_PROJECTandLANGSMITH_OTLP_ENDPOINTsettings.
From a Quarkus project directory, start development mode after configuring its required services:
./mvnw quarkus:devFor projects without a wrapper, such as ch14/observability, use:
mvn quarkus:devExamples using Quarkus Dev Services need a running compatible container engine. Check the project configuration for ports and service dependencies, especially when running an MCP or A2A client and server together.
Open an issue with the example directory, Java and Maven versions, command you ran, and relevant error output. Remove credentials from logs before sharing them.