-
Notifications
You must be signed in to change notification settings - Fork 299
Description
Description
LangChain4j.toParts() throws a NullPointerException when processing an AiMessage with a null text field. This occurs in multi-agent setups where the LLM returns tool-call-only responses (no text content).
The toParts() method passes aiMessage.text() directly to Part.builder().text() without a null check. The AutoValue-generated Part.Builder.text() rejects null values, causing the NPE.
AiMessage.text() returning null is a known LangChain4j behavior for tool-call-only responses — see langchain4j#2686 and langchain4j#986.
Stack Trace
java.lang.NullPointerException
at com.google.adk.models.langchain4j.AutoValue_Part$Builder.text(AutoValue_Part.java)
at com.google.adk.models.langchain4j.LangChain4j.toParts(LangChain4j.java)
at com.google.adk.models.langchain4j.LangChain4j.lambda$generateContent$1(LangChain4j.java)
Steps to Reproduce
- Set up a router agent with sub-agents using the LangChain4j bridge
- Use an OpenAI-compatible provider (e.g., OpenRouter) as the LLM backend
- Send a query that triggers sub-agent delegation
- When the LLM response contains tool calls but no text,
toParts()crashes
The issue is intermittent (~1 in 10-20 requests) because it depends on whether the LLM includes a text field alongside tool calls.
Expected Behavior
Null text should be handled gracefully — skip the text part when aiMessage.text() is null, rather than crashing.
Affected Versions
0.7.0, 0.8.0, 0.9.0
Environment
- Java 21+
- LangChain4j with OpenRouter (OpenAI-compatible API)
- Multi-agent router with specialist sub-agents
- Cloud Run deployment