Software Development

How to use Function Calling in Spring AI to connect LLMs with internal APIs?

DE Asked by Derek Stone · 10-10-2025
0 upvotes 5,277 views 0 comments
The question

I want my LLM to be able to fetch real-time data from our internal inventory REST API. How do I register a Java function as a tool for the model in Spring AI? Is there a way to let the model decide when to call the function based on the user's prompt without manual intervention?

3 answers

0
RA
Answered on 13-10-2025

Function calling in Spring AI is handled by defining a java.util.function.Function as a @Bean. You then provide a description of what the function does using the @Description annotation or via the bean name. When you call the AI model, you pass the bean name in the PromptOptions. The framework automatically generates the JSON schema for the tool and sends it to the LLM. If the LLM determines it needs that data (e.g., "What is the stock for item X?"), it returns a tool call request, which Spring AI executes locally before sending the result back to the LLM.

0
KE
Answered on 15-10-2025

Does this support complex POJOs as input parameters, or am I limited to simple strings? I need to pass a structured filter object to my inventory service.

DE 17-10-2025

Kevin, it absolutely supports complex POJOs! Spring AI uses Jackson to serialize and deserialize the function arguments. As long as your input record or class has proper getters/setters or is a Java Record, the LLM will generate a JSON object matching that structure. Just make sure your parameter descriptions are very clear so the LLM knows exactly what values to put into each field of your object.

0
MO
Answered on 19-10-2025

It's essentially a way to give your AI "hands." It turns a static LLM into an agentic system that can interact with your existing Spring Boot services seamlessly.

RA 21-10-2025

Well put, Monica. It's the most powerful feature for enterprise apps where you need the AI to actually "do" things like update records or check live status.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session