Provides and generates LangChain4j tool and function calling patterns: annotates methods as tools with @Tool, configures tool executors, registers tools with AiServices, validates tool parameters, and handles tool execution errors. Use when building AI agents that call tools, define function specifications, manage tool responses, or integrate external APIs with LLM-driven applications.
LangChain4j Tool & Function Calling Patterns is a Java coding-guidance skill that provides and generates the patterns needed to give LLM-driven applications the ability to call tools. It solves the problem of correctly exposing Java methods as callable functions for AI agents using LangChain4j — annotating methods with @Tool and parameters with @P, registering tool sets through the AiServices builder, and handling the failure modes that come with LLM tool use, such as execution errors, malformed arguments, and hallucinated tool names.
The skill delivers a step-by-step workflow with validation checkpoints: annotate a tool class, register it with a chat model via AiServices.builder().tools(), test end-to-end that a prompt actually triggers the tool, add error handlers that return safe messages instead of leaking stack traces, and optimize for scale with concurrent execution and per-tool timeouts. Extensive reference files cover core patterns, implementation patterns, advanced features (context-aware tools via @ToolMemoryId, dynamic tool providers for large or conditional tool sets), setup and configuration, integration examples, error handling, and practical end-to-end examples including calculators, multi-domain tool selection, structured return types, and a database example that validates queries are read-only SELECT statements before executing.
It targets Java developers building AI agents and LLM integrations who want production-ready, defensively coded tool-calling patterns. Use cases include wiring external APIs (weather, stocks), database lookups, and calculations into an assistant, managing multiple tool domains, and hardening tool execution against timeouts and bad input. The examples read API keys from environment variables, following standard credential practice.
Java applications using the LangChain4j framework, specifically its @Tool and @P annotations and the AiServices builder for registering tools with a chat model.
You annotate methods with @Tool (with a description) and parameters with @P, then register tool instances via AiServices.builder().chatModel(...).tools(...).build().
It shows toolExecutionErrorHandler, toolArgumentsErrorHandler, and a hallucinatedToolNameStrategy so failures, invalid arguments, and non-existent tool names return safe messages to the LLM rather than exposing stack traces.
Yes. It documents executeToolsConcurrently with a thread pool and toolExecutionTimeout for long-running tools, with a validation step to confirm no thread contention or deadlocks.
Example chat models read the provider API key from an environment variable (System.getenv), which is standard credential practice with no hardcoded secrets.
Quick Setup:
.claude/skills/Repository
giuseppe-trisciuoglio/developer-kit