How API plugins work
Declarative agents use API plugins to communicate with APIs for reading and modifying data. Each time a user submits a prompt (1), the declarative agent evaluates the prompt to check for suitable functions to invoke (2). If it finds a function that matches the user's prompt, it authenticates if necessary (3a, 3b). Then, it builds the necessary API request, calls the API (3c), processes its response (3d) and builds a response for the user (6). The following diagram shows this process in more detail:
How does the agent know which function to invoke?
When you build an API plugin, you define its name, description and one or more functions. For each function, you specify a description. Declarative agent uses all this information to determine which function it should invoke. Each time a user submits a prompt to your declarative agent, it uses its underlying language model to evaluate the prompt against the available plugin and functions description to decide if there's a suitable function to invoke.
Once the agent selects a function to invoke, it matches the function to the operation in the API specification. Based on the API information, it constructs the API request and processes the API response.