intermediateTool Calling & Function Calling

What actually happens when an LLM 'calls a tool' — does the model execute code itself?

No — the model only ever outputs structured text saying 'call function X with these arguments.' Your application code intercepts that, actually executes the real function (a database query, an API call), and sends the result back to the model as a new message, which the model then uses to compose its final answer. The model never directly executes anything.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Why is tool calling considered safer/more useful than asking the LLM to just 'know' an answer?← Back to all Spring AI questions