New advertisers: 50% off your first month with code FIRSTMONTHSee slots
giuseppe-trisciuoglio avatar

Langchain4j Tool Function Calling Patterns

Java tool-calling patterns for LangChain4j that register methods with AiServices and handle execution failures.

skills.sh installs
3.9K
GitHub stars
372
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers @Tool and @P annotation usage, tool registration with AiServices.builder().tools(), and dynamic ToolProvider setups
  • Includes error handling hooks such as toolExecutionErrorHandler, hallucinatedToolNameStrategy, and toolArgumentsErrorHandler, plus concurrency and timeout options
  • Enforces safe failure behavior by returning user-friendly error strings instead of stack traces, and keeping credentials out of tool descriptions
  • Designed for Java developers building LLM-driven agents that call external APIs, databases, or business systems

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-tool-function-calling-patterns -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

LangChain4j Tool & Function Calling Patterns

Provides patterns for annotating methods as tools, configuring tool executors, registering tools with AI services, validating parameters, and handling tool execution errors in LangChain4j applications.

Overview

LangChain4j uses the @Tool annotation to expose Java methods as callable functions for AI agents. The AiServices builder registers tools with a chat model, enabling LLMs to perform actions beyond text generation: database queries, API calls, calculations, and business system integrations. Parameters use @P for descriptions that guide the LLM.

When to Use

  • Building AI agents that call external tools (weather, stocks, database queries)
  • Defining function specifications for LLM tool use (@Tool, @P annotations)
  • Registering and managing tool sets with AiServices.builder().tools()
  • Handling tool execution errors, timeouts, and hallucinated tool names
  • Implementing context-aware tools that inject user state via @ToolMemoryId
  • Configuring dynamic tool providers for large or conditional tool sets

Instructions

1. Annotate Methods with @Tool

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
AI Agents & LLM Apps, Java & JVM
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 95

Similar to Langchain4j Tool Function Calling Patterns

More AI Agents & LLM Apps