liveBook · Manning

Chapter 6: Activating tool-driven generation

What you will learn in chapter 6 of Spring AI in Action

The introduction explains why an LLM may need tools to obtain real-time information that training and RAG cannot supply.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why an LLM may need tools to obtain real-time information that training and RAG cannot supply.

Key terms: LLMs, RAG, tools, real-time information

6.1 Getting started with AI tools

Introduces tools as a way for supported LLMs to obtain data and take actions through application logic, with Spring AI providing a consistent way to apply them.

Key terms: RAG, tools, application logic, tool calling, AI providers, Spring AI

6.1.1 Developing a tools-enabled application

Builds a Spring AI application that answers current-time questions by making a Java time lookup available to an LLM as a tool.

Key terms: real-time information, tools, TimeTools, getCurrentTime(), @Tool, time zone, @Component, defaultTools(), ChatClient

6.1.2 Digging deeper

Explains how a tool-assisted answer is produced through a conversation between the application and the model, rather than by the model directly invoking an application endpoint.

Key terms: tools property, description property, parameters property, JSON schema, getCurrentTime, Spring AI, finish_reason, tool_calls, tool role, stop

6.2 Implementing tools

Introduces database-backed game complexity ratings as information a tool could provide to Board Game Buddy’s LLM.

Key terms: Board Game Buddy, complexity ranking, tool

6.2.1 Writing the tool’s foundations

The section builds the database, Java data model, and repository that a later tool will use to answer questions about game complexity.

Key terms: Spring Data JDBC, H2 in-memory database, DataSource, schema.sql, data.sql, Game table, Game record, slug, complexity, complexityEnum()

6.2.2 Defining the tool

This subsection defines a game complexity tool and explains how its annotations, repository lookup, and response help an LLM use it.

Key terms: GameTools, getGameComplexity(), @Tool, description attribute, gameTitle, @ToolParam, GameRepository, GameComplexityResponse, GameComplexity, placeholder Game

6.2.3 Putting the tool to work

This section shows how to make a game-complexity tool available to ChatClient and verify that it was called.

Key terms: GameTools, ChatClient, defaultTools(), tools(), @Tool, logger’s info() method, logs, game complexity tool

6.3 Enables functions as tools

This section shows how to define a Spring AI tool with a Java functional interface and register it with ChatClient by bean name.

Key terms: Function, Supplier, Consumer, apply(), @Description, @Component, GameComplexityRequest, Java record, @ToolParam, gameTools

6.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 5: Enabling conversational memory Chapter 7: Applying Model Context Protocol →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.