Tool use with LangChain4j and Ollama
This example shows LangChain4j tool calling against a local Ollama model.
A plain Java method annotated with @Tool becomes callable by the model, and LangChain4j runs the tool loop on behalf of the AI service. Small models call tools unreliably, so a larger model such as llama3.2 gives more consistent results.
Requirements
Steps for running this example in the shell
- Start Ollama and pull the model:
bash
ollama serve
ollama pull llama3.2:1b- Run the application:
bash
mvn compile exec:javaOutput
42