Anthropic Agent Skills Support in Spring AI
Large Language Models (LLMs) are rapidly evolving from simple text generators into intelligent agents capable of performing complex tasks. One of the latest advancements introduced by Anthropic is Agent Skills, which enables AI agents to use specialized capabilities and execute domain-specific actions more effectively. Spring AI provides an elegant framework for integrating Anthropic’s models and agentic capabilities into Spring Boot applications.
1. Overview
As organizations adopt Generative AI, there is a growing need to integrate Large Language Models (LLMs) into enterprise applications in a structured, maintainable, and scalable manner. Spring AI addresses this requirement by providing a consistent abstraction layer for interacting with various AI providers, while Anthropic Agent Skills extend agent capabilities through reusable and specialized functions. Together, they enable developers to build intelligent, tool-aware, and autonomous AI applications that can interact with external systems, retrieve knowledge, and execute business workflows.
1.1 Spring AI
Spring AI is a Spring ecosystem project that simplifies the integration of AI models such as Anthropic Claude, OpenAI GPT, and others into Java applications. It provides a consistent programming model and abstractions for working with AI capabilities, including Chat Models, Prompt Engineering, Function Calling, Tool Execution, Retrieval-Augmented Generation (RAG), and Agentic Workflows, enabling developers to build intelligent and scalable AI-powered applications using familiar Spring development patterns.
1.2 Anthropic Agent Skills
Anthropic Agent Skills introduce a structured way for AI agents to perform specialized tasks through reusable capabilities known as Skills. Instead of relying solely on prompt instructions, skills encapsulate business logic, domain expertise, and external integrations that can be dynamically invoked by the AI model. This approach improves reusability, maintainability, and reliability when building enterprise-grade AI systems. Common use cases include weather information retrieval, database querying, knowledge base lookups, ticket creation, email drafting, and workflow automation.
1.3 Traditional LLMs vs Agent Skills
While traditional Large Language Models can generate intelligent responses based on their training data, they are limited when it comes to accessing real-time information and executing external actions. Agent Skills address these limitations by allowing AI agents to dynamically invoke specialized tools and services. The following comparison highlights the key differences:
| Traditional LLM | Agent with Skills |
|---|---|
| Relies on training data | Can access real-time systems |
| May hallucinate external information | Retrieves actual data from tools and services |
| Limited to text generation | Can execute tools and business functions |
| Static knowledge | Dynamic and continuously updated knowledge |
2. Complete Spring Boot Code Example
2.1 Project Dependencies
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-anthropic</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
This Maven configuration adds the required dependencies for building a Spring Boot application that integrates with Anthropic AI models through Spring AI. The spring-ai-starter-model-anthropic dependency provides the necessary abstractions, client libraries, and auto-configuration support for connecting to Anthropic Claude models, while the spring-boot-starter-web dependency enables the creation of RESTful web services and APIs. Together, these dependencies allow developers to expose HTTP endpoints that can interact with Anthropic AI models using Spring AI’s simplified programming model.
2.2 Application Properties
Before configuring Spring AI, you must generate an API key from Anthropic to authenticate requests to Claude models. Sign in to the Anthropic Console, navigate to the API Keys section, and create a new API key. Store the generated key securely, as it grants access to your Anthropic account and usage quotas. To avoid exposing sensitive credentials in source code, configure the key as an environment variable named ANTHROPIC_API_KEY.
export ANTHROPIC_API_KEY=your_api_key_here
Once the environment variable is configured, Spring AI automatically resolves the value referenced by ${ANTHROPIC_API_KEY} and uses it to authenticate requests sent to Anthropic’s Claude models.
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
spring.ai.anthropic.chat.options.model=claude-sonnet-4
This configuration defines the connection settings for the Anthropic AI model used by the application. The spring.ai.anthropic.api-key property loads the API key from the environment, while spring.ai.anthropic.chat.options.model specifies the default Claude model, claude-sonnet-4, that Spring AI will use for chat interactions. Together, these properties enable the application to securely authenticate with Anthropic services and route requests to the configured AI model.
2.3 Weather Skill
The Weather Skill acts as a tool that the Anthropic agent can invoke whenever weather-related information is required.
package com.example.skills;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Service;
@Service
public class WeatherSkill {
@Tool(description = "Get weather information for a city")
public String getWeather(String city) {
return switch (city.toLowerCase()) {
case "mumbai" ->
"Mumbai: 31°C, Humid, Light Rain";
case "delhi" ->
"Delhi: 36°C, Sunny";
case "bangalore" ->
"Bangalore: 24°C, Cloudy";
default ->
"Weather data unavailable";
};
}
}
The WeatherSkill class defines a reusable AI tool that can be invoked by Anthropic Claude through Spring AI’s native tool-calling capabilities. The @Service annotation registers the class as a Spring-managed bean, making it available for dependency injection and tool registration. The @Tool annotation exposes the getWeather() method to the AI model and provides a description that helps Claude understand the tool’s purpose. When a user asks a weather-related question, Claude can automatically invoke this method, pass the appropriate city name as an argument, and receive the returned weather information. The method uses a Java switch expression to return predefined weather details for Mumbai, Delhi, and Bangalore, while returning a default message when weather data for a requested city is unavailable. This approach enables the AI model to access external business logic and generate responses based on real application data rather than relying solely on its internal knowledge.
2.4 Skill Tool Registration
package com.example.config;
import com.example.skills.WeatherSkill;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ToolConfiguration {
@Bean
public WeatherSkill weatherSkill() {
return new WeatherSkill();
}
}
The ToolConfiguration class is a Spring configuration class responsible for registering application components as managed beans within the Spring container. The @Configuration annotation indicates that the class contains bean definitions, while the @Bean annotation on the weatherSkill() method instructs Spring to create and manage an instance of the WeatherSkill class. By registering the skill as a bean, it becomes available for dependency injection and can be exposed to Spring AI as a tool that AI agents can invoke during execution. This configuration ensures that the weather-related functionality is centrally managed, reusable, and accessible throughout the application.
2.5 Agent Service
package com.example.service;
import com.example.skills.WeatherSkill;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Service;
@Service
public class AgentService {
private final ChatClient chatClient;
private final WeatherSkill weatherSkill;
public AgentService(
ChatClient.Builder builder,
WeatherSkill weatherSkill) {
this.chatClient = builder.build();
this.weatherSkill = weatherSkill;
}
public String askAgent(String question) {
return chatClient.prompt()
.user(question)
.tools(weatherSkill)
.call()
.content();
}
}
The AgentService class acts as the orchestration layer between the AI model and the application’s business skills. Rather than manually inspecting user requests and invoking skills through conditional logic, the service registers the WeatherSkill as a tool using Spring AI’s native tool-calling capabilities. When a user submits a question, the request is sent directly to the Claude model along with the available tool definitions. Claude can then decide whether the weather tool is required, invoke it automatically, receive the tool output, and incorporate the result into its final response. This approach represents true agentic behavior, where the AI model dynamically selects and executes tools as part of its reasoning process, resulting in a more scalable and maintainable architecture.
2.6 REST Controller
package com.example.controller;
import com.example.service.AgentService;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/agent")
public class AgentController {
private final AgentService agentService;
public AgentController(AgentService agentService) {
this.agentService = agentService;
}
@GetMapping
public String ask(
@RequestParam String question) {
return agentService.askAgent(question);
}
}
The AgentController class exposes the AI agent functionality as a REST API endpoint using Spring Web. The @RestController annotation marks the class as a REST controller capable of handling HTTP requests, while @RequestMapping("/agent") defines the base URL path for all endpoints in the controller. The controller receives an instance of AgentService through constructor-based dependency injection and delegates all business logic to it. The @GetMapping method handles HTTP GET requests and accepts a user question through the @RequestParam parameter. When a request is received, the controller invokes the askAgent() method of the service layer and returns the AI-generated response directly to the client. This design follows the standard Spring architecture by keeping the controller focused on request handling while delegating agent orchestration and AI interactions to the service layer.
2.7 Main Application
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AnthropicSkillApplication {
public static void main(String[] args) {
SpringApplication.run(
AnthropicSkillApplication.class,
args
);
}
}
The AnthropicSkillApplication class serves as the entry point of the Spring Boot application. The @SpringBootApplication annotation enables auto-configuration, component scanning, and Spring Boot’s configuration support, allowing the framework to automatically discover and configure beans such as controllers, services, and AI-related components. The main() method invokes SpringApplication.run(), which bootstraps the Spring application context, initializes all configured components, and starts the embedded web server. Once the application is running, it becomes ready to accept HTTP requests and process AI-powered interactions through the registered agent services and skills.
2.8 Code Run and Output
After configuring the Anthropic API key and starting the Spring Boot application, the embedded web server launches and exposes the REST endpoint at /agent. Users can interact with the AI agent by sending HTTP GET requests with a question parameter. For example, a request to http://localhost:8080/agent?question=What is the weather in Mumbai? triggers the agent workflow, which first invokes the WeatherSkill and retrieves the output "Mumbai: 31°C, Humid, Light Rain". This weather information is then injected into the prompt and sent to the Anthropic Claude model through Spring AI. Based on the supplied context, Claude generates a natural language response such as "The current weather in Mumbai is approximately 31°C with humid conditions and light rain. If you are planning to go outside, carrying an umbrella would be a good idea.". This demonstrates how Spring AI and Anthropic Agent Skills work together to combine external business logic with AI reasoning, enabling the model to generate accurate and context-aware responses.
3. Conclusion
Anthropic Agent Skills significantly enhance the capabilities of AI-powered applications by introducing reusable and specialized functionalities that can be invoked dynamically during conversations. When combined with Spring AI, developers can build robust agentic applications using familiar Spring Boot patterns while leveraging the reasoning capabilities of Claude models. This combination enables intelligent task automation, structured tool execution, domain-specific reasoning, enterprise-grade AI agents, and maintainable, scalable architectures. As agentic AI continues to evolve, skill-based architectures are expected to become a fundamental design pattern for building reliable, production-ready AI systems within the Java and Spring ecosystem.




