eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

1. Overview

Modern web applications are increasingly integrating with Large Language Models (LLMs) to build solutions that go beyond simple question answering. To create AI agents capable of handling complex user requests, we often connect them to multiple Model Context Protocol (MCP) servers that provide them with specific capabilities via tools.

However, creating and running MCP servers can be overkill for lightweight and local automation tasks where we just need to expose a simple capability to a single agent.

Agent Skills is a specification that provides a structured way to locally define, package, and expose these capabilities to an AI agent.

In this tutorial, we’ll explore the Agent Skills capability in Spring AI. We’ll configure a custom skill and integrate it with a simple chatbot to summarize articles.

2. What are Agent Skills?

Agent Skills is an open specification for defining various capabilities that an AI agent can invoke. A skill is essentially a directory containing a SKILL.md file, which acts as its manifest, alongside any associated code like Python or Bash scripts, or additional resources that the skill relies on.

The SKILL.md file contains a frontmatter block with a name and description, followed by a set of natural language instructions that tell the agent how to use the skill.

When the agent receives a user request, it reads the descriptions of all available skills and decides if any is relevant. If yes, it then loads the relevant files into context and follows the instructions inside the matching skill to fulfill the request. And if no skill matches the request, the agent simply responds using its general capabilities without invoking any skill.

We’ll see an agent invoking our custom skill practically in action in the upcoming sections.

3. Setting up the Project

Before we dive into the implementation, we’ll need to include the necessary dependencies and configure our application correctly.

3.1. Dependencies

Let’s start by adding the necessary dependencies to our project’s pom.xml file:

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-model-openai</artifactId>
    <version>2.0.0</version>
</dependency>
<dependency>
    <groupId>org.springaicommunity</groupId>
    <artifactId>spring-ai-agent-utils</artifactId>
    <version>0.10.0</version>
</dependency>

Here, we first import Spring AI’s OpenAI starter dependency, which we’ll use to interact with a chat model. Support for agent skills is available in Spring AI 2 and later, so we need to make sure we’re using the correct version.

Next, we import the agent-utils dependency from the Spring AI community, which enables us to add the agent skills capability to our chat models.

3.2. Configuring a Chat Model

Next, let’s configure our OpenAI API key and chat model in the application.yaml file:

spring:
  ai:
    openai:
      api-key: ${OPENAI_API_KEY}
      chat:
        options:
          model: gpt-5.5

We use the ${} property placeholder to load the value of our API Key from an environment variable.

Additionally, we specify OpenAI’s GPT 5.5 model using the gpt-5.5 model ID. Alternatively, we can use a different chat model that supports the agent skills specification, as the specific AI model or provider is irrelevant for this demonstration.

With these two properties set, Spring AI automatically creates a bean of type ChatModel, allowing us to interact with the specified model.

4. Defining Our Custom Skill

Now let’s define a custom agent skill that can fetch an article from a URL and summarize it.

Agent skills follow a specific directory structure, so let’s set that up. We’ll start by creating an .openai/skills directory in our project’s root directory. We can define multiple subdirectories inside this, each representing a distinct agent skill.

Next, we’ll create an article-summarizer subdirectory to represent our custom skill inside .openai/skills and define our main SKILL.md file inside it:

---
name: article-summarizer
description: Summarizes articles into concise digests. Useful when user asks to summarize or get key points from an article.
---
# Article Summarizer
## Instructions
When summarizing an article:
1. If given a URL: Run `uv run scripts/fetch_article.py <url>` to retrieve the content.
2. Once content is available, extract the main thesis, few key points, and conclusion.
3. Structure the output as a TL;DR, key points, and a bottom line.

In the frontmatter block, we define the name and description of our skill. The description is especially important as the agent uses it to determine whether this skill is relevant for a given user request. Next, we define the instructions that tells the agent exactly what steps to follow when the skill is invoked, including which script to run and how to structure the final output.

Next, let’s create the fetch_article.py script inside a new scripts subdirectory that we reference in the instructions:

ARTICLE = """
... hardcoding sample article for demonstration
"""

print(ARTICLE)

Here, for our demonstration, we simply print a hardcoded article about MCP elicitations instead of actually making a web request. The AI model will run this script and read the standard output to get this article’s content regardless of the URL in the request .

Also, it’s important to note that we can define our scripts in any language of our choice. We just need to make sure that we pre-install the required runtimes for our agent to execute the necessary commands.

5. Creating a Simple Chatbot

With our configurations in place, let’s build a simple chatbot.

In Spring AI, the ChatClient class acts as the main entry point for interacting with our configured chat completion model. Let’s define its bean using the auto-configured ChatModel bean:

@Bean
ChatClient chatClient(ChatModel chatModel) {
    String skillsRootDirectory = ".openai/skills";
    return ChatClient
      .builder(chatModel)
      .defaultTools(
        SkillsTool.builder()
          .addSkillsDirectory(skillsRootDirectory)
          .build(),
        FileSystemTools.builder()
          .allowedDirectory(skillsRootDirectory)
          .build(),
        ShellTools.builder()
          .build()
      ).build();
}

In our bean definition, we first register our custom skills directory using SkillsTool, pointing it to the .openai/skills directory.

Secondly, we register FileSystemTools, which gives the agent the ability to read and write any files on the local filesystem. To restrict the tool’s operations to the configured skills directory, we use the allowedDirectory() method.

Finally, we register ShellTools, which allows the agent to execute shell commands, enabling it to run the Python script we’ve defined.

However, it’s important to note that ShellTools executes our scripts directly on the local machine without sandboxing. As such, we should carefully review the scripts we expose to our agent and consider containerizing our application to limit potential exposure.

Next, let’s inject the ChatClient bean in a controller class and expose a REST API:

@PostMapping("/chat")
ResponseEntity<ChatbotResponse> chat(@RequestBody ChatbotRequest chatbotRequest) {
    String answer = chatClient
      .prompt()
      .user(chatbotRequest.question)
      .call()
      .content();
    return ResponseEntity.ok(new ChatbotResponse(answer));
}

record ChatbotRequest(String question) {}

record ChatbotResponse(String answer) {}

Here, we simply pass the user’s question to the chatClient instance and return the LLM’s response. We’ll use this API endpoint to interact with our chatbot in the upcoming section.

6. Interacting With Our Chatbot

Now that we’ve built our implementation, let’s interact with our chatbot and test the agent skill capability.

We’ll use the HTTPie CLI to invoke the chatbot’s API endpoint:

http POST :8080/chat question="Can you summarize the following article: https://www.baeldung.com/sample-non-existing-article"

Here, we ask the chatbot to summarize a specific article by passing a URL in the question. We deliberately provide the URL of a non-existent article to verify that the chatbot summarizes the article we’ve hardcoded in our Python script.

Let’s see what we get as a response:

{
  "answer": "## TL;DR\nThis article explains how to implement MCP Elicitations in Spring AI, allowing MCP servers to request additional user information dynamically during tool execution.
    \n\n## Key Points\n- MCP Elicitations solve the problem of missing user information during MCP tool execution.
    \n- The tutorial demonstrates building an MCP server using Spring AI.
    \n- The MCP server exposes a tool that fetches author details and conditionally requests additional information.
    \n- The `elicit()` method is used to pause execution and gather required details from the user.
    \n- The article also demonstrates configuring an MCP client and integrating it with an Anthropic Claude model
    \n- Spring AI automatically creates MCP clients and tool callback providers from configuration.
    \n- An `@McpElicitation` handler is used on the client side to respond to elicitation requests.
    \n- The tutorial concludes with a working chatbot example and log outputs showing the complete elicitation flow.
    \n\n## Bottom Line\nMCP Elicitations enable interactive AI applications where tools can dynamically collect additional context from users during execution,
    making MCP-based systems more flexible and user-aware."
}

As we can see, the LLM summarizes our hardcoded article and the response is structured exactly as our skill’s instructions prescribed, with a TL;DR, a set of key points, and a bottom line.

Behind the scenes, the agent matched the user’s request to the article-summarizer skill based on its description, loaded the instructions into context using FileSystemTools, executed the fetch_article.py script via ShellTools to retrieve the article content, and then structured the response following the instructions in our SKILL.md file.

7. Conclusion

In this article, we’ve explored the concept of Agent Skills using Spring AI.

We started by understanding what Agent Skills are and how they help us in exposing reusable capabilities to an AI agent.

Then, we defined a custom article summarizer skill and wired it into a chatbot. Finally, we interacted with our chatbot to confirm that it correctly discovers and invokes our skill.

As always, all the code examples used in this article are available over on GitHub.

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)
guest
0 Comments
Oldest
Newest
Inline Feedbacks
View all comments