[Tools] Use AI Service
The Tools use ai service
and Tools use ai service legacy
operations are very useful if you want to create autonomous agents that can use tools whenever a prompt cannot be answered. The prerequisite for using Tools is to prepare a tools.config.json
file, which includes all the API information needed for the operation to successfully execute the API.
Input Fields
Module Configuration
This refers to the MuleSoft AI Chain LLM Configuration set up in the Getting Started section.
General Operation Fields
- Data: The prompt to be sent to the LLM along with the embedding store to respond to.
- Tool Config: Contains the full file path for the
tools.config.json
. Ensure the file path is accessible. You can also use a DataWeave expression for this field, e.g.,mule.home ++ "/apps/" ++ app.name ++ "/tools.config.json"
.
XML Configuration
Below is the XML configuration for this operation:
<ms-aichain:tools-use-ai-service
doc:name="Tools use ai service"
doc:id="910f744f-e359-4e39-afd1-3fb932c5fc53"
config-ref="MAC_AI_Llm_configuration"
data="#[payload.data]"
toolConfig='#[mule.home ++ "/apps/" ++ app.name ++ "/tools.config.json"]'
/>
Output Field for v0.2.0
This operation responds with a string
payload which needs to be converted into a json, this can be achieved with a Transform Message component with the following dataweave expression:
%dw 2.0
output application/json
---
read(payload,"application/json").
Output Field
This operation responds with a json
payload.
Tools.config.json
Following is an example of the tools.config.json
. You can name it as you like.
[
{
"action":"Execute POST requests for API endpoints.",
"url": "http://check-inventory-material.cloudhub.io/mmbe",
"name": "Check Inventory",
"method": "POST",
"headers": "Basic XXX",
"example-payload":"{
"materialNo": "paramValue"}",
"query": [
"Check inventory in SAP",
"Check Stock Overview",
"Show product availability for MULETEST0",
"Check the inventory for MULETEST0",
"Check Stock for 400-110"
],
"description": "Check inventory details for material in SAP by providing the materialNo as input for paramValue. Please use the materialNo and not materialNumber. This action applies whenever users' intent is 'Stock overview', 'product availability', 'Inventory', 'available stock'. Use the headers to perform the request."
},
{
"action":"Execute GET requests for API endpoints.",
"url": "https://anypoint.mulesoft.com/mocking/api/v1/sources/exchange/assets/612eb739-4266-4f4c-bf2f-29953c153d80/accounts-api/1.0.1/m/accounts",
"name": "Show accounts",
"method": "GET",
"headers": "",
"example-payload":"{}",
"query": [
"Get all accounts",
"Show all accounts from CRM"
],
"description": "Get all accounts from a CRM. This action applies whenever users' intent is 'CRM accounts', 'customers', 'customer accounts', 'accounts'. Use the headers to perform the request."
},
{
"action":"Execute GET requests for API endpoints.",
"url": "https://anypoint.mulesoft.com/mocking/api/v1/sources/exchange/assets/7b99cead-a984-497b-9e6c-c16a3b4dcb76/employee-api/1.0.1/m/employees",
"name": "Show Employees",
"method": "GET",
"headers": "",
"example-payload":"{}",
"query": [
"Get all employee information",
"Show employees for the country Switzerland",
"How many employees do we have",
"Show a list of all employees"
],
"description": "Get all information about all employees. This action applies whenever users' intent is 'employees', 'workforce'. Use the headers to perform the request."
}
]
The Tools array contains the API information as tools in the enclosing line items. Make sure to describe the fields as accurately as possible.
action
: This field currently supports only the following 2 options:Execute GET requests for API endpoints.
Execute POST requests for API endpoints.
url
: This field must contain a complete URL to the endpoint including the resource.name
: This field should describe the name of the action in natural language.method
: This field must contain the HTTP method for the endpoint. Currently onlyPOST
andGET
are supported.headers
: This field must contain the HTTP headers for authorization for the endpoint. Currently onlyBasic
Auth is supported.example-payload
: This field must contain the example payload.query
: This field must contain the example queries a user can ask for this action.description
: This field must contain the description on how to use the tool in this line item. This description should be detailed so the LLM is able to understand it.
Example Output not using Tools
This output has been converted to JSON.
{
"response": "The capital of Switzerland is Bern.",
"toolsUsed": false
}
- response: The response to the query!
- toolsUsed: Flag if tools were used.
Example Output of using Tools
This output has been converted to JSON.
{
"response": "The inventory check for material \"MULETEST0\" shows an available quantity of **1,650,738** units.",
"toolsUsed": true
}
- response: The response to the query!
- toolsUsed: Flag if tools were used.
Example Use Cases
This operation can be particularly useful in various scenarios, such as:
- Automating Routine Tasks: Create autonomous agents that handle routine tasks by calling appropriate APIs.
- Customer Support: Automate responses to common queries by integrating tools that provide necessary information.
- Inventory Management: Use tools to check inventory levels or order status based on user prompts.
- Employee Management: Retrieve employee information or manage employee-related tasks through API calls.
- Sales and Marketing: Access CRM data or manage leads and accounts efficiently using predefined tools.