- Home
- Skills
- Giuseppe Trisciuoglio
- Developer Kit
- Langchain4j Tool Function Calling Patterns
langchain4j-tool-function-calling-patterns_skill
- Python
99
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill giuseppe-trisciuoglio/developer-kit --skill langchain4j-tool-function-calling-patterns- SKILL.md16.2 KB
Overview
This skill provides tool and function calling patterns for LangChain4j to build agentic Java applications. It shows how to define tools, register them with AiServices, handle execution errors, and integrate tools with memory and streaming. The content focuses on practical patterns for safe, observable, and maintainable tool use in production agents.
How this skill works
The skill describes how to annotate methods with @Tool and @P to expose executable functions to LLM-based agents, and how to register those tools via the AiServices builder or a dynamic ToolProvider. It covers parameter descriptions, complex types (records), memory integration via @ToolMemoryId, immediate-return tools, concurrent execution, and error handling hooks. Examples show monitoring tool executions, streaming integrations, and resilience patterns like retries and circuit breakers.
When to use it
- Building AI assistants that must call external APIs, databases, or services
- Creating multi-agent systems where agents need specialized, executable tools
- Implementing real-time or context-aware features (weather, stocks, user prefs)
- Integrating LLMs with existing business systems requiring validation and permissions
- Deploying production agents that require observability, error handling, and rate limiting
Best practices
- Give tools clear, actionable names and descriptive parameter docs
- Validate and sanitize all inputs before performing external actions
- Implement permission checks, audit logging, and rate limiting for security
- Use concurrent tool execution and caching for independent, high-latency calls
- Provide meaningful error handlers and circuit breakers for resilience
Example use cases
- Calculator tools for arithmetic and quick computations embedded in chat agents
- Weather and stock tools that fetch real-time data and return immediate results
- Database access tools for read/write operations with validation and audit logs
- Dynamic tool providers that expose domain-specific tools based on user messages
- Streaming assistants that emit partial responses and tool execution events for UI updates
FAQ
Annotate the method with @Tool and describe parameters with @P; register the tool object with AiServices builder.
How can I handle tool failures gracefully?
Provide a toolExecutionErrorHandler in AiServices builder to map exceptions to user-friendly messages and log details for debugging.
When should I use dynamic tool provisioning?
Use a ToolProvider when available tools depend on request context or user state, reducing prompt noise and improving safety.