liveBook · Manning

Tool role

As explained in Spring AI in Action

A tool message is a message containing instructions for invoking external tools to perform an action or fetch additional context.

A tool message carries the result of an external tool invocation back to the LLM. It extends a conversation beyond the initial user request, giving the model additional context for its final answer. section 6.1.2 section 3.3

A tool-driven exchange proceeds as follows:

  • The LLM returns an assistant message containing a tool call rather than a completed answer. section 6.1.2
  • The application invokes the requested tool, such as getCurrentTime, and obtains its result. section 6.1.2
  • The application sends the original user message, assistant tool call, and tool message together for reconsideration. section 6.1.2
  • The LLM uses the tool content to produce a final assistant response with a stop finish reason. section 6.1.2

Current time lookup

For a question about the current time in Jal, New Mexico, the tool message contains the returned timestamp and identifies getCurrentTime through its tool_call_id. The LLM then answers with the localized time and date.

Figure 6.1 Tool invocation involves a multipart conversation between the application and the LLM.
figure

Trace the multipart conversation among the application, LLM, assistant tool call, and tool result. section 6.1.2

How Spring AI in Action covers it

How deep it goes
Defines the role and traces the multipart exchange, but stops short of implementing tool definitions or invocation code.
Examples
Demonstrates getCurrentTime returning a timestamp for a Jal, New Mexico, time query.
What it assumes
Assumes familiarity with user, system, and assistant messages while defining tool as another supported role.
What you can do after
Evaluate/understand how tool results become conversation context for a final LLM response.
How it connects
Connects user, system, assistant, and tool messages with tool calls, APIs, conversations, and Spring AI.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.