Chapter 1: Why a harness?

A model reads text and writes text. It cannot run code, read files, or remember past calls. The harness adds those abilities. It does five jobs. It sends the prompt. It reads the reply. It runs the tools the model asks for. It returns the tool results. It decides when the run stops.

Figure 1.1. One harness run, with each of the five jobs labelled. Use Previous and Next to step through it. The count of 412 is the fake data from Chapter 4.

Example. Asked alone, a model can only guess whether checkout is slow. With a harness, the model calls a countErrors tool, reads the real count, and answers from that data.

Objectives: describe a model call, name the five harness jobs, and explain what the course builds.

Tool calling, step by step

A model is frozen after training. It cannot read today’s logs or call an API. Tool calling fixes this. The model asks for a tool, and the harness runs it. Figure 1.2 shows the six steps.

countErrorsa Java method in your appHarnessSpring AI, or your own loopDispatch tool callsfind the tool by name, run itGemmareads text, writes text, runs no codeChat requestIs checkout slow?Tool definitioncountErrorsnamedescriptioninput schemaChat responsecheckout has 412error eventsquestion + tooltool callrun412tool resultanswer123456
Figure 1.2. Tool calling in six steps. The model asks. The harness runs the tool. Redrawn from the Spring AI reference, AI Concepts, for the Log Incident Watcher.

The numbers in Figure 1.2 match these steps. Table 1.1 maps each one to a harness job.

  1. The request carries each tool definition: a name, a description, and an input schema.
  2. The model replies with a tool call: the tool name and the arguments.
  3. The harness finds the tool by name and runs it with those arguments.
  4. The tool returns its result to the harness.
  5. The harness sends the result back to the model.
  6. The model writes the final answer from the result.
StepHarness job
1Job 1: send the prompt and the tool list
2Job 2: read the reply
3 and 4Job 3: run the tool
5Job 4: return the tool result
6Job 5: no tool call in the reply, so stop

Table 1.1. Spring AI's six tool calling steps, mapped to the five harness jobs.

  • The model never runs code. Your app runs every tool.
  • Figure 1.2 shows one tool call. A real run can repeat steps 2 to 5. Job 5 decides when to stop. Chapter 6 adds limits to that decision.
  • Spring AI can do steps 3 to 5 for you. Chapter 4 uses that. Chapter 5 does them by hand.

Summary: A model only writes text. The harness sends the request, runs the tools, and decides when to stop.

docs