langchain4j-tool-function-calling-patterns

Installation
Summary

Annotation-based and programmatic tool system for LangChain4j agents to execute external functions, APIs, and services.

  • Define tools using @Tool annotations with parameter descriptions via @P, automatically registered with AI services for LLM invocation
  • Supports static tool registration, dynamic tool provisioning based on context, concurrent execution, and immediate-return tools for quick responses
  • Includes error handling strategies, tool execution monitoring, memory context integration via @ToolMemoryId, and resilience patterns like circuit breakers
  • Covers multi-domain tool services, streaming with tool execution, and integration with databases, REST APIs, and external services
SKILL.md

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

Related skills

More from giuseppe-trisciuoglio/developer-kit

Installs
886
GitHub Stars
246
First Seen
Feb 3, 2026