Documentation
Basics
Agentic Flows
Integrations
Tools Provider
Prompt Preprocessor
Generators
Custom Configuration
Publishing a Plugin
Text Embedding
Tokenization
API Reference
Model Info
Basics
Agentic Flows
Integrations
Tools Provider
Prompt Preprocessor
Generators
Custom Configuration
Publishing a Plugin
Text Embedding
Tokenization
API Reference
Model Info
Integrations
Single Tool
Plugin support is currently in private beta. Join the beta here.
To setup a tools provider, first create the a file toolsProvider.ts
in your plugin's src
directory:
import { tool, Tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
import { existsSync } from "fs";
import { writeFile } from "fs/promises";
import { join } from "path";
export async function toolsProvider(ctl: ToolsProviderController) {
const tools: Tool[] = [];
const createFileTool = tool({
// Name of the tool, this will be passed to the model. Aim for concise, descriptive names
name: `create_file`,
// Your description here, more details will help the model to understand when to use the tool
description: "Create a file with the given name and content.",
parameters: { file_name: z.string(), content: z.string() },
implementation: async ({ file_name, content }) => {
const filePath = join(ctl.getWorkingDirectory(), file_name);
if (existsSync(filePath)) {
return "Error: File already exists.";
}
await writeFile(filePath, content, "utf-8");
return "File created.";
},
});
tools.push(createFileTool);
return tools;
}
The above tools provider defines a single tool called create_file
that allows the model to create a file with a specified name and content inside the working directory. You can learn more about defining tools in Tool Definition.
Then register the tools provider in your plugin's index.ts
:
// ... other imports ...
import { toolsProvider } from "./toolsProvider";
export async function main(context: PluginContext) {
// ... other plugin setup code ...
// Register the tools provider.
context.withToolsProvider(toolsProvider); // <-- Register the tools provider
// ... other plugin setup code ...
}
Now, you can try to ask the LLM to create a file, and it should be able to do so using the tool you just created.
This page's source is available on GitHub