langchain4j-tool-function-calling-patterns

Solid

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.

AI & Automation 278 stars 32 forks Updated 5 days ago MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
81
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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` Define a tool class with methods annotated `@Tool`. Provide a description as the first parameter. Use `@P` for each parameter description. ```java public class WeatherTools { private final WeatherService weatherService; public WeatherTools(WeatherService weatherService) { this.weatherService = weatherService; } @Tool("Get curr...

Details

Author
giuseppe-trisciuoglio
Repository
giuseppe-trisciuoglio/developer-kit
Created
7 months ago
Last Updated
5 days ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category