alibaba/spring-ai-alibaba · error · IllegalArgumentException

model must be specified

Error message

model must be specified

What it means

SummarizationHook.Builder.build() requires a ChatModel: the hook needs it to generate conversation summaries. Building without a model throws this IllegalArgumentException, since summarization cannot function without an LLM.

Source

Thrown at spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/hook/summarization/SummarizationHook.java:361

		public Builder summaryPrefix(String prefix) {
			this.summaryPrefix = prefix;
			return this;
		}

		public Builder tokenCounter(TokenCounter counter) {
			this.tokenCounter = counter;
			return this;
		}

		public Builder keepFirstUserMessage(boolean keep) {
			this.keepFirstUserMessage = keep;
			return this;
		}

		public SummarizationHook build() {
			if (model == null) {
				throw new IllegalArgumentException("model must be specified");
			}
			return new SummarizationHook(this);
		}
	}
}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Provide a ChatModel: SummarizationHook.builder().model(chatModel).build().
  2. In tests, use a mock/stub ChatModel implementation if real inference is unnecessary.
  3. Guard hook construction so it is only attempted when a ChatModel bean is present.

Example fix

// before
SummarizationHook hook = SummarizationHook.builder().build();
// after
SummarizationHook hook = SummarizationHook.builder()
    .model(chatModel)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (chatModel == null) { throw new IllegalStateException("ChatModel required for SummarizationHook"); }
SummarizationHook hook = SummarizationHook.builder().model(chatModel).build();

Type guard

boolean canBuild(Model m) { return m != null; }

Try / catch

try { hook = builder.model(chatModel).build(); } catch (IllegalArgumentException e) { log.error("Summarization unavailable: {}", e.getMessage()); }

Prevention

When it happens

Trigger: Calling SummarizationHook.builder()...build() without calling .model(chatModel), or passing null to .model(...).

Common situations: In tests where no real model is wired and the builder call was dropped; refactors where the ChatModel bean became optional; copying example code and skipping the model line.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/4642537e2fdc41a9. Report an issue: GitHub.