How to Create Custom Agent Tool Types
To create a custom agent tool type with Vault Java SDK:
-
Create a Tool Type Runtime Handler by implementing
AiToolTypeRuntimeHandler:@ExecuteAs(ExecuteAsUser.REQUEST_OWNER) @AiToolTypeRuntimeHandlerInfo(dynamicToolSpec = false) public class MyToolTypeRuntimeHandler implements AiToolTypeRuntimeHandler { @Override public AiToolTypeExecutionResponse onExecute(AiToolTypeExecuteContext context) { JsonService jsonService = ServiceLocator.locate(JsonService.class); RecordService recordService = ServiceLocator.locate(RecordService.class); // Create a new record and return the created ID Record newRecord = recordService.newRecord("tool_invocations__c"); String nameInput = context.getInput().getValue("name", JsonValueType.STRING); newRecord.setValue("name__v", nameInput); JsonObjectBuilder toolOutput = jsonService.newJsonObjectBuilder(); RecordBatchSaveRequest saveRequest = recordService.newRecordBatchSaveRequestBuilder() .withRecords(VaultCollections.asList(newRecord)) .build(); recordService.batchSaveRecords(saveRequest) .onSuccesses(successes -> { toolOutput.setValue("recordId", successes.get(0).getRecordId()); }) .rollbackOnErrors() .execute(); return context.newSuccessBuilder(AiToolTypeExecutionResponse.JsonResultBuilder.class) .withJson(toolOutput.build()) .build(); } } -
Create an
Aitooltyperuntimecoderecord referencing theAiToolTypeRuntimeHandler, and createAitooltyperuntimecodeMDL records:RECREATE Aitooltype my_custom_tool_type__c ( label('My Tool Type'), admin_configurable(true), description ('Sample tool to create a Tool Invocations record'), runtime_code('Aitooltyperuntimecode.com.veeva.vault.custom.context.MyToolTypeRuntimeHandler') );
Filtering Tool Availability with isExecutable
Section link for Filtering Tool Availability with isExecutableisExecutable is an optional default method on AiToolTypeRuntimeHandler. It fires during tool spec generation. Return true (the default) to include the tool in the LLM request, or false to exclude it from the list of tools available to the LLM.
Use isExecutable when a tool requires access to resources the current user may not have.
If your agent instructions reference a tool that may not always be available, write the instructions conditionally. For example, "If the tool find_course__c is in your tool list, use it to search for courses that match the user's request. If find_course__c is not in your tool list, tell the user that you cannot search the course catalog."
To access the initiating user, use RequestContext.
You can set tool_evaluation to REQUIRED on an Agent Action in the MDL or in the Vault UIisExecutable returns false for a required tool, the agent does not fail. Instead, it proceeds without requiring that specific tool.
@Override
public boolean isExecutable(AiToolTypeIsExecutableContext context) {
// Return false to exclude this tool from the LLM request.
// For example, check if the current user has access to required resources.
return true;
}AiToolTypeExecuteContext provides two additional methods for tool handlers that invoke agent actions asynchronously: getToolCall() and newAsyncExecutionBuilder(). To build a tool handler that invokes agent actions and processes their results, see Invoking Agent Actions from a Custom Tool Type.