AI / LangChain4j interview questions
How does LangChain4j implement the ReAct agent pattern and what are its limitations?
The ReAct (Reasoning + Acting) pattern in LangChain4j is implemented automatically by the AI Services framework whenever you register tools with a chat language model. There is no explicit ReAct class to instantiate — the pattern emerges from the interaction between the tool-equipped LLM and LangChain4j's tool execution loop.
The concrete mechanics inside LangChain4j's AI Services when tools are present:
- Tool schemas (name, description, parameter types) are serialized from your
@Toolannotated methods and included in every LLM request - If the LLM returns a tool call in its response, LangChain4j intercepts it, looks up the corresponding method, deserializes the arguments, and invokes the Java method via reflection
- The tool result is appended as a
ToolExecutionResultMessageto the conversation history - The LLM is called again with the updated history — it can reason about the result and either call another tool or produce a final text answer
- This loop continues until the LLM stops requesting tools (step 4's output is not a tool call)
Known limitations of the current implementation:
- No parallel tool execution — When the LLM requests multiple tools simultaneously (some models support this), LangChain4j executes them sequentially, not in parallel, which increases latency for multi-tool queries
- No configurable max iterations — There is no built-in loop guard. A misbehaving model or misconfigured tool could theoretically loop indefinitely. You must add your own application-level timeout
- Single agent only — LangChain4j does not natively orchestrate multi-agent workflows where agents delegate subtasks to other agents. Custom code is required for that pattern
- Tool schemas depend on model support — Tool calling requires a model that supports the function calling protocol. Older or smaller models may produce unreliable tool call JSON
More Related questions...