Blog Post

SnapLogic Technical Blog
6 MIN READ

APIM Function Generator - Integrate Your APIM Services as Tools for LLMs

ChompooPanida's avatar
2 months ago

As large language models (LLMs) continue to evolve, they are becoming powerful enablers of intelligent automation, capable of interpreting natural language and performing actions through external tool calling. In SnapLogic, this capability is supported through LLM agent pipelines, where function definitions—whether created manually, built from Snaplogic pipelines , or derived from OpenAPI specifications—can be transformed into callable tools that LLMs use to interact with external systems.

SnapLogic’s API Management (APIM) plays a key role in this process. APIM offers a modern and flexible way to design, secure, and publish APIs directly within the Snaplogic platform. With support for service versioning, policy configuration, and a DeveloperHub for API discovery, APIM simplifies the management and reuse of APIs across various projects and use cases. Many users already rely on APIM to expose critical business logic through well-structured, reusable APIs that support a wide range of integrations and workflows.

However, connecting these APIs to LLM tool calling has traditionally involved significant manual effort, including:

  • Difficulty discovering APIM service versions and endpoints at the Snap level
  • Rewriting API descriptions and parameter definitions already defined in the APIM service
  • Configuring multiple Function Generator Snaps
  • Manually maintaining tool definitions to stay in sync with updates to the APIM service

The APIM Function Generator Snap addresses these challenges by automating the entire setup process. It connects directly to an APIM service version and generates a list of Snaplogic internal format of the function definitions using live metadata to use with the Tool Calling Snap and related downstream Snaps.

By removing the need for manual configuration and automatically reflecting any updates made to the APIM service, this Snap helps maintain consistency, reduce setup time, and simplify integration. It provides a fast and reliable way to turn an existing APIM service version into callable tools for LLMs, enabling more efficient automation.

APIM Function Generator Snap

Snap Properties

  • Project path: Select the project path that contains the target APIM service.
  • Service name: Choose the service name to use. Suggestions are provided based on the selected project path.
  • Version: Specify the version of the selected service. Suggestions are provided based on the selected service name.
  • Base URL: Specify the base URL used to call the API. Suggestions are provided based on the Plex selected in the APIM service version.
  • Preferred content type: Specify the desired content type for API calls.
  • Filter type: Determines how the APIs within the service version are selected.
  • Aggregate input: When enabled, all incoming documents are combined into a single list of function definitions.

Filter Type Options

The Snap supports three filter types for determining which APIs from the selected APIM service version are included in the function definitions:

  • Use all paths
    This option includes every available API path and method from the selected service version. It is the simplest way to expose the entire API set without additional filtering.
  • Tags
    This option allows you to specify one or more tags. Any API that includes at least one of the specified tags—whether at the endpoint, path, or method level—will be included in the generated function definitions. Tag-based filtering is useful for organizing APIs into meaningful groups. For example, you can create separate tool sets for different agents, such as billing, ticketing, analytics, or read-only access.
  • Paths and methods
    This option enables you to define specific paths and their associated HTTP methods. It offers precise control over which endpoints are exposed to the LLM agent. This filter type is especially valuable for enforcing permissions; for instance, by including only GET methods, you can restrict an agent to read-only operations.

This flexible configuration allows you to tailor the function definitions to match your use case, ensuring the right APIs are available for your LLM agent workflows.

Output of the Snap

The Snap outputs a list of tool definitions. Each tool definition includes: 

  • sl_tool_metadata:
    Contains essential metadata used by the Tool Calling Snap and downstream Snaps to route and invoke the correct API. It enables dynamic resolution of the URL path based on parameters from the LLM output. The
  • tool_type is set to APIM, and the metadata includes the service name, version name, endpoint name, tags(including endpoint tags, path tags, and method tags), and the full URL of the API.


  • json_schema: defines the expected structure of input parameters for the API. This schema guides the LLM in formatting its output correctly and allows the Tool Calling Snap to resolve the complete URL path for calling the API.

These fields are generated based on the live metadata from the APIM service version.

Example Use Case: Product Recommendation

To demonstrate how the APIM Function Generator Snap streamlines the integration of existing APIs into LLM workflows, consider a scenario based on a retail business use case. In this example, the SnapLogic APIM service named APIM Tool Demo, version v1, is used to expose APIs for a clothing store.

This service includes three endpoints:

  • /weather: A proxied external API used to retrieve real-time weather data.
  • /inventory: A SnapLogic pipeline task exposed as an API to access product data from the store’s database.
  • /users: Another SnapLogic task API that provides access to user-related information.

These APIs might already be powering external applications or internal tools. With the APIM Function Generator Snap, they can now be easily transformed into callable tools for LLMs—eliminating the need for separate specifications or manual configuration.

In this use case, the goal is to build an LLM agent capable of recommending clothing items based on the current weather. For example, the LLM may receive a prompt such as:

“Please recommend at most 3 items from the women’s clothing category in the store based on the current weather in Paris and provide the reason.”

To support this workflow, the /weather endpoint and some APIs in /inventory endpoint were tagged with recommendation in the APIM service. This tag is then used in the APIM Function Generator Snap to filter and include only the relevant APIs when generating tool definitions—making it easy to group related functionality.

Agent Driver Pipeline

System prompt: You are a friendly and helpful assistant that are equipped with some tools, please use your judge to decide whether to use the tools or not to answer questions from the user.

User prompt: Please recommend at most 3 items from the women’s clothing category in the store based on the current weather in Paris and provide the reason.

Agent Worker Pipeline 

Function generation

The APIM Function Generator is used for providing the tool definition to the Tool Calling Snap

Snap settings:

Output:

Tool Calling

The Tool Calling Snap sends tool definitions to the LLM and outputs tool calls with the full URL and headers resolved using parameters returned by the LLM. This output is then passed to the Router Snap to route each call to the appropriate downstream Snap.

Router

The Router Snap is useful when different endpoints require specific handling, such as different authentication methods, custom configurations, or when using multiple services or types of Function Generator Snaps. It leverages fields from sl_tool_metadata, such as the endpoint name, to route each tool call to the appropriate path.

Example route expression:

$.get("sl_tool_metadata").tool_type == "APIM" && 
$.get("sl_tool_metadata").service_name == "APIMToolsDemo" &&
$.get("sl_tool_metadata").endpoint_name == "weather"

Calling API

The API is called using the HTTP Client Snap. The request method and URL are dynamically configured using sl_tool_metadata. The appropriate account should be selected according to the policies defined in the APIM service.

With this setup, the LLM can respond to queries by utilizing the APIM tools. Below is the message history, demonstrating that the tool can be called successfully.

Final Result

Example pipelines

Conclusion

The APIM Function Generator Snap simplifies the integration of APIM services as tools for LLMs by automating function generation and keeping definitions in sync with live API metadata. This streamlined approach eliminates manual setup, supports flexible filtering, and transforms existing APIs into callable tools, enabling dynamic and metadata-driven automation within LLM workflows.

 

 

Updated 2 months ago
Version 1.0
No CommentsBe the first to comment