Agent skill

Langchain4j Tool Function Calling Patterns

by giuseppe-trisciuoglio in giuseppe-trisciuoglio/developer-kit

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…

MITAuto-check: notesAI & LLM Engineering

Install Langchain4j Tool Function Calling Patterns

skills CLI
$ npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-tool-function-calling-patterns -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install giuseppe-trisciuoglio/developer-kit langchain4j-tool-function-calling-patterns --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/giuseppe-trisciuoglio/developer-kit.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/developer-kit-java/skills/langchain4j-tool-function-calling-patterns .claude/skills/langchain4j-tool-function-calling-patterns && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
langchain4j-tool-function-calling-patterns
GitHub stars
356
Token cost
~2.4k tokens
SKILL.md length
707 words
Files
9 (incl. references)
Skills in repo
115
Repo updated
First seen
Licence
MIT

At a glance

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…

  • Works in 5 steps: Annotate Methods with @Tool → Register Tools with AiServices → Test Tool Invocation End-to-End → …
  • Building AI agents that call tools
  • SKILL.md covers Overview, When to Use, Instructions and Examples, plus 6 more sections
  • Needs API_KEY

What it does

Langchain4j Tool Function Calling Patterns is an agent skill from giuseppe-trisciuoglio/developer-kit. 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.

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 9 other files, including reference files (for example `references/advanced-features.md`, `references/core-patterns.md` and `references/error-handling.md`).

It sits in AI & LLM Engineering, covering Structured output and tool calling and Building AI agents. The repository describes itself as: Modular plugin marketplace for Claude Code and agentic CLIs, with validated, spec-driven skills, agents, commands, and workflows for Java, TypeScript, Python, PHP, AWS, and AI. The licence is MIT.

When your agent uses it

  • Building AI agents that call tools
  • Define function specifications
  • Manage tool responses
  • Integrate external APIs with LLM-driven applications

Example prompts

  • “Use the langchain4j-tool-function-calling-patterns skill to provide and generates LangChain4j tool and function calling patterns: annotates methods…”
  • “/langchain4j-tool-function-calling-patterns”

Requirements

  • A credential in API_KEY
  • Pre-approved tools (allowed-tools): Read, Write, Edit, Bash, Glob, Grep, WebFetch

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Annotate Methods with @Tool
  2. Register Tools with AiServices
  3. Test Tool Invocation End-to-End
  4. Handle Tool Execution Errors
  5. Optimize for Performance and Scale

What it can do on your machine

Read from SKILL.md and the folder at commit fe73fb3. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Bash
    • Glob
    • Grep
    • WebFetch

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are java).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • API_KEY

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Langchain4j Tool Function Calling Patterns loads about 2.4k tokens when it runs, and up to ~16k if it reads all its reference files. Until then it costs about 108 tokens; SKILL.md has 707 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~108
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~16k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Edit, Bash, Glob, Grep, WebFetch

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from giuseppe-trisciuoglio/developer-kit at commit fe73fb3, republished under its MIT licence (© giuseppe-trisciuoglio). 707 words, ~2,363 tokens.

Download SKILL.mdSave it as .claude/skills/langchain4j-tool-function-calling-patterns/SKILL.md (or your agent's skills folder). This skill also uses 8 other files; get the full folder from GitHub.
name
langchain4j-tool-function-calling-patterns
description
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.
allowed-tools
Read, Write, Edit, Bash, Glob, Grep, WebFetch

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 current weather for a city")
    public String getWeather(
            @P("City name") String city,
            @P("Temperature unit: celsius or fahrenheit") String unit) {
        return weatherService.getWeather(city, unit);
    }
}

Validate: Create an instance and confirm the class loads without errors.

2. Register Tools with AiServices

Use AiServices.builder() to register tool instances with the chat model.

java
MathAssistant assistant = AiServices.builder(MathAssistant.class)
    .chatModel(chatModel)
    .tools(new Calculator(), new WeatherTools(weatherService))
    .build();

Validate: Call assistant.chat("What is 2 + 2?") and verify the LLM responds without throwing.

3. Test Tool Invocation End-to-End

Send a prompt that triggers tool usage and verify the tool executes and its result is incorporated.

java
String response = assistant.chat("What is the weather in Rome?");
System.out.println(response);

Validate: Check logs for tool invocation and confirm the response uses the tool output.

4. Handle Tool Execution Errors

Add error handlers to gracefully manage failures without exposing stack traces.

java
AiServices.builder(Assistant.class)
    .chatModel(chatModel)
    .tools(new ExternalServiceTools())
    .toolExecutionErrorHandler((request, exception) -> {
        logger.error("Tool '{}' failed: {}", request.name(), exception.getMessage());
        return "An error occurred while processing your request";
    })
    .hallucinatedToolNameStrategy(request ->
        ToolExecutionResultMessage.from(request,
            "Error: tool '" + request.name() + "' does not exist"))
    .toolArgumentsErrorHandler((error, context) ->
        ToolErrorHandlerResult.text("Invalid arguments: " + error.getMessage()))
    .build();

Validate: Trigger an error condition and confirm the LLM receives a safe error message.

5. Optimize for Performance and Scale

Enable concurrent tool execution and set timeouts for long-running tools.

java
AiServices.builder(Assistant.class)
    .chatModel(chatModel)
    .tools(new DbTools(), new HttpTools())
    .executeToolsConcurrently(Executors.newFixedThreadPool(5))
    .toolExecutionTimeout(Duration.ofSeconds(30))
    .build();

Validate: Run concurrent requests and confirm no thread contention or deadlocks.

Examples

Calculator Tool with Full Class
java
public class Calculator {
    @Tool("Perform basic arithmetic")
    public double calculate(
            @P("Expression like 2+2 or 10*5") String expression) {
        // Parse and evaluate expression
        return eval(expression);
    }
}

Assistant assistant = AiServices.builder(Assistant.class)
    .chatModel(ChatModel.builder()
        .apiKey(System.getenv("API_KEY"))
        .model("gpt-4o")
        .build())
    .tools(new Calculator())
    .build();
Immediate Return Tool (No LLM Response)
java
@Tool(value = "Send email notification", returnBehavior = ReturnBehavior.IMMEDIATELY)
public void sendEmail(@P("Recipient email address") String to,
                     @P("Email subject") String subject,
                     @P("Email body") String body) {
    emailService.send(to, subject, body);
}
Dynamic Tool Provider
java
ToolProvider provider = request -> {
    if (request.userContext().contains("admin")) {
        return List.of(new AdminTools());
    }
    return List.of(new UserTools());
};

AiServices.builder(Assistant.class)
    .chatModel(chatModel)
    .toolProvider(provider)
    .build();

Best Practices

  • Descriptive @Tool names: Use imperative verbs ("Get", "Send", "Calculate") with clear scope
  • Precise @P descriptions: Include format, constraints, and valid values — vague descriptions cause incorrect LLM calls
  • Safe error handling: Never expose stack traces; return user-friendly error strings
  • Timeout configuration: Always set .toolExecutionTimeout() for external service calls
  • Concurrent execution: Enable .executeToolsConcurrently() when tools are independent
  • Input validation: Validate parameters inside the tool method; return descriptive errors
  • Permission checks: Perform authorization inside the tool, not at the AI service level
  • Audit logging: Log tool name, parameters, and execution result for debugging and compliance
Show full SKILL.md (299 more words)Show less

Common Issues and Solutions

IssueSolution
LLM calls non-existent toolAdd .hallucinatedToolNameStrategy() returning a safe error message
Tools receive wrong parametersRefine @P descriptions; add .toolArgumentsErrorHandler()
Tool execution hangsSet .toolExecutionTimeout(Duration.ofSeconds(N))
Rate limit errors from external APIAdd retry logic or rate limiter inside the tool method
LLM ignores tool outputEnsure the tool returns a string the LLM can interpret

See references/error-handling.md for resilience patterns and references/core-patterns.md for parameter and return type details.

Quick Reference

Annotation / APIPurpose
@ToolMarks a method as a callable tool
@PDescribes a tool parameter for the LLM
@ToolMemoryIdInjects conversation/user ID into the tool
AiServices.builder()Creates AI service with registered tools
ReturnBehavior.IMMEDIATELYExecute tool without waiting for LLM response
ToolProviderDynamic tool provisioning based on context
executeToolsConcurrently()Run independent tool calls in parallel
toolExecutionTimeout()Timeout for individual tool calls

Constraints and Warnings

  • Sensitive data: Never pass API keys, passwords, or credentials in @Tool or @P descriptions
  • Side effects: Tools that modify data should warn in their description; AI models may call them multiple times
  • Large tool sets: Excessive tools confuse LLM models — use ToolProvider for conditional registration
  • Blocking operations: Tools should not perform long synchronous I/O without timeout configuration
  • Stack trace exposure: Always route exceptions through error handlers that return safe strings
  • Parameter precision: Vague @P descriptions directly cause incorrect tool calls — be specific about formats and constraints
  • Concurrent safety: Ensure tool classes are stateless or thread-safe when using executeToolsConcurrently()
  • langchain4j-ai-services-patterns — High-level AI service configuration
  • langchain4j-rag-implementation-patterns — RAG retrieval with tool integration
  • langchain4j-spring-boot-integration — Tool registration in Spring Boot applications

References

© giuseppe-trisciuoglio, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 8 other files (references) in plugins/developer-kit-java/skills/langchain4j-tool-function-calling-patterns of giuseppe-trisciuoglio/developer-kit.

  • SKILL.md
  • references/advanced-features.md
  • references/core-patterns.md
  • references/error-handling.md
  • references/examples.md
  • references/implementation-patterns.md
  • references/integration-examples.md
  • references/references.md
  • references/setup-configuration.md

Open the folder on GitHubat commit fe73fb3

Compare with similar skills

Langchain4j Tool Function Calling Patterns next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Langchain4j Tool Function Calling Patterns compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Langchain4j Tool Function Calling Patterns this skillgiuseppe-trisciuoglio/developer-kit356—~2.4kAutomated safety check: NotesMIT
Google Agents CLI Adk Codepifferologo/cloud-agents-cli1291 repos~768Automated safety check: PassApache-2.0
E2b Code Interpreteragent-sandbox/agent-sandbox218—~2.3kAutomated safety check: PassApache-2.0
Output Dev Agent Classgrowthxai/output442—~2.6kAutomated safety check: PassApache-2.0
Agents And MiddlewareVectorSpaceLab/AREX-Skill330—~1.2kAutomated safety check: PassMIT
Build Agentsvercel/vercel-plugin301—~1.4kAutomated safety check: PassCustom licence

Similar skills

  • Google Agents CLI Adk Code

    pifferologo/cloud-agents-cli

    This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management", or needs ADK (Agent…

    129 GitHub starsUsed in 1 repo~768 tokens
    AI & LLM EngineeringAuto-check passed
  • E2b Code Interpreter

    agent-sandbox/agent-sandbox

    Execute code in E2B sandboxes and integrate with LLMs for tool calling.

    218 GitHub stars~2.3k tokensUpdated 19 days ago
    AI & LLM EngineeringAuto-check passed
  • Output Dev Agent Class

    growthxai/output

    Use the Agent class for multi-step tool loops, conversation history, streaming progress, and reusable LLM agents.

    442 GitHub stars~2.6k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • Agents And Middleware

    VectorSpaceLab/AREX-Skill

    Work on the actively maintained LangChain v1 agent package: initchatmodel, createagent, structured output, tools, middleware, embeddings initialization, provider routing, and agent runtime…

    330 GitHub stars~1.2k tokensUpdated 1 mo ago
    AI & LLM EngineeringAuto-check passed
  • Build Agents

    vercel/vercel-plugin

    Official

    Default guidance for building AI agents. An agent skill from vercel/vercel-plugin.

    301 GitHub stars~1.4k tokensUpdated yesterday
    AI & LLM EngineeringAuto-check passed
  • AI Agent Builder

    claude-office-skills/skills

    Build AI agents with tools, memory, and multi-step reasoning - ChatGPT, Claude, Gemini integration patterns

    502 GitHub stars~3.1k tokensUpdated 8 mo ago
    AI & LLM EngineeringAuto-check passed

More from giuseppe-trisciuoglio/developer-kit

All 115 skills in this repo
  • Nestjs Drizzle Crud Generator

    giuseppe-trisciuoglio/developer-kit

    Generates complete CRUD modules for NestJS applications with Drizzle ORM.

    356 GitHub stars~1.3k tokensUpdated 29 days ago
    Auto-check: notes
  • Spring Boot Actuator

    giuseppe-trisciuoglio/developer-kit

    Provides patterns to configure Spring Boot Actuator for production-grade monitoring, health probes, secured management endpoints, and Micrometer metrics across JVM services.

    356 GitHub stars~2.2k tokensUpdated 29 days ago
    Auto-check: notes
  • Spring Boot Crud Patterns

    giuseppe-trisciuoglio/developer-kit

    Provides and generates complete CRUD workflows for Spring Boot 3 services.

    356 GitHub stars~2.5k tokensUpdated 29 days ago
    Auto-check: notes
  • Spring Boot Security JWT

    giuseppe-trisciuoglio/developer-kit

    Provides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based…

    356 GitHub stars~3.9k tokensUpdated 29 days ago
    Auto-check: notes
  • AWS CLI Beast

    giuseppe-trisciuoglio/developer-kit

    Provides advanced AWS CLI patterns for managing EC2, Lambda, S3, DynamoDB, RDS, VPC, IAM, and CloudWatch.

    356 GitHub stars~1.7k tokensUpdated 29 days ago
    Auto-check: notes
  • PR Review Comments

    giuseppe-trisciuoglio/developer-kit

    Posts review findings from a JSON file as inline comments on a GitHub Pull Request, attaching each comment to its file and line.

    356 GitHub stars~1k tokensUpdated 29 days ago
    Auto-check: notes

Questions about Langchain4j Tool Function Calling Patterns

What does Langchain4j Tool Function Calling Patterns do?

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…. Langchain4j Tool Function Calling Patterns is an agent skill from giuseppe-trisciuoglio/developer-kit. 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.

When should I use Langchain4j Tool Function Calling Patterns?

Langchain4j Tool Function Calling Patterns fits situations like: building AI agents that call tools; define function specifications; manage tool responses; integrate external APIs with LLM-driven applications.

How do I install Langchain4j Tool Function Calling Patterns in Claude Code?

Run `npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-tool-function-calling-patterns -a claude-code`. Or copy the skill folder (plugins/developer-kit-java/skills/langchain4j-tool-function-calling-patterns in giuseppe-trisciuoglio/developer-kit) into .claude/skills/langchain4j-tool-function-calling-patterns in your project. Claude Code loads it when a task matches its description.

How do I install Langchain4j Tool Function Calling Patterns in Codex?

Run `npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-tool-function-calling-patterns -a codex`. Or copy the skill folder (plugins/developer-kit-java/skills/langchain4j-tool-function-calling-patterns in giuseppe-trisciuoglio/developer-kit) into .agents/skills/langchain4j-tool-function-calling-patterns in your project. Codex loads it when a task matches its description.

Can I use Langchain4j Tool Function Calling Patterns in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add giuseppe-trisciuoglio/developer-kit --skill langchain4j-tool-function-calling-patterns -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/langchain4j-tool-function-calling-patterns, .gemini/skills/langchain4j-tool-function-calling-patterns, .github/skills/langchain4j-tool-function-calling-patterns and .opencode/skills/langchain4j-tool-function-calling-patterns in your project.

What does Langchain4j Tool Function Calling Patterns need to run?

Going by SKILL.md and its folder, Langchain4j Tool Function Calling Patterns needs credentials named API_KEY. Our summary lists: A credential in API_KEY. Its frontmatter pre-approves these tools: Read, Write, Edit, Bash, Glob, Grep, WebFetch.

Does Langchain4j Tool Function Calling Patterns access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Langchain4j Tool Function Calling Patterns safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Langchain4j Tool Function Calling Patterns use?

Langchain4j Tool Function Calling Patterns is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Langchain4j Tool Function Calling Patterns use?

About 2.4k tokens (SKILL.md is roughly 9.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 14k tokens, read only when the agent opens those files.

What are the alternatives to Langchain4j Tool Function Calling Patterns?

Skills that share tags, products or a category with Langchain4j Tool Function Calling Patterns: Google Agents CLI Adk Code (pifferologo/cloud-agents-cli, 129 stars), E2b Code Interpreter (agent-sandbox/agent-sandbox, 218 stars), Output Dev Agent Class (growthxai/output, 442 stars) and Agents And Middleware (VectorSpaceLab/AREX-Skill, 330 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Langchain4j Tool Function Calling Patterns?

giuseppe-trisciuoglio (a GitHub user) maintains it in giuseppe-trisciuoglio/developer-kit, which has 356 GitHub stars. The repository holds 115 skills in this directory. The repository was last updated on September 10, 2026.

Source: giuseppe-trisciuoglio/developer-kit on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.