NestJS Tool Calling: Exposing Service Methods to LLM Agents

Developers can let an LLM invoke NestJS code by decorating a service method with @Tool() and its parameters with @ToolParam(). The model only requests a function call, and the application itself executes the method and returns the result for the model to use in its answer. The guide uses a product catalog service as its example, with a checkStock method that reports inventory for a SKU and throws an error when the product is missing. The service is registered in a module and then listed in the agent's tools configuration, which gives the agent access to every tool-decorated method of that module's providers. The tutorial is part 2 of a series, and its examples were tested with NestJS 12, LangChain 1.x, Zod 4, nestjs-langchain 2.0 and Node 22.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in