Configure API Tool
The API Tool in Ejento AI is designed to enhance the assistant’s ability to fetch real-time information from external APIs based on user queries. Instead of hardcoding API URLs, the assistant dynamically constructs the correct endpoint URL using predefined system instructions and retrieves relevant data.
How It Works
-
User Query Analysis: The assistant detects whether a user query requires fetching external data.
-
URL Construction: The assistant constructs the API request URL based on the query and available parameters.
-
Fetching Data: The assistant queries the API and retrieves relevant information.
-
Response Optimization: The assistant structures and presents the response in a user-friendly manner.
How to Write a Prompt for API Requests
When constructing system prompts for API requests, certain elements must always be included, while others are optional and can be added based on endpoint requirements.
Must-Have Elements:
These elements are mandatory for ensuring proper API integration:
- API Name and Version: Clearly specify which API and version the assistant should use to ensure compatibility.
Optional but Recommended Elements:
These elements enhance API calls but are not strictly necessary for every request:
-
Base URL: If a static base URL is used for multiple API calls, including it in the prompt ensures consistency.
-
Input for Headers: If the API requires authentication or special headers, the prompt should define how they are structured.
-
API-Specific Parameters to Construct URL: If certain parameters are crucial for retrieving relevant data, they should be included in the prompt dynamically, depending on user input.
By structuring system prompts this way, API calls remain efficient, flexible, and aligned with endpoint requirements.
Example: Clinical Trials API
For Clinical Trials API integration, the system prompt instructs the assistant on how to structure URLs and fetch data. Here is a simplified excerpt from the system prompt:
"You are using the Clinical Trials open API spec version 2.0.3 with the base URL https://clinicaltrials.gov/api/v2. Your task is to generate request URLs based on user queries and fetch the required data. Always limit results to 10 unless specified otherwise. Use relevant parameters such as query.cond for conditions, query.locn for locations, and filter.overallStatus for recruitment status."
This excerpt ensures that:
-
The assistant knows the correct API version and base URL.
-
It applies proper query parameters to retrieve only necessary data.
Configuring the API Tool
1. Go to the Tools section from the sidebar
2. Click on Add Tool
3. Type a name for your tool in the configure tool drawer
4. Select API from the Tool Type dropdown
5. Add the description for the tool here
6. Select "Other" Under API Selection
7. Add the system prompt here
8. Click on Create tool
9. The new API Tool has been created.
Next, Lets also add Authorization information for the Tool to be able to send authorized requests to the API
10. Click on Authorization in the Configure Tool Drawer
11. Add the Authorizatio Key Here i.e "Ocp-Apim-Subscription-Key"
12. Add the value for the key in authorization header
13. Click on Update tool
Enabling the API Tool for Assistant
1. Navigate to the assistants section from the sidebar
2. Search for your assistant from the list
3. Make sure "Advanced Reasoning" is turned on in the assistant drawer
4. Click on the three dots on your assistant from the list
5. Go to Tools from the dropdown
6. Search for the newly created tool here
7. Enable the tool for this assistant
8. Navigate back to your assistant and click on it to open the assistant drawer
9. Notice the API Tool being enabled for the assistant here
Best Practices for Writing System Prompts
-
Define Clear Query Parameters: Specify which API parameters the assistant should use to refine responses efficiently.
-
Limit Data Fetching: Implement constraints like pageSize=10 to prevent excessive data retrieval.
-
Specify Essential Fields in the Prompt: Ensure that system prompts instruct the assistant to request only the necessary fields from the API, improving performance.
-
Use Context-Sensitive Instructions: Adapt system instructions based on API capabilities, ensuring appropriate query modifications.
-
Ensure API Compatibility: Keep track of API version changes and update system instructions accordingly.