prompt-toolkit
v1.0.0
Published
PromptKit is a lightweight toolkit for managing prompts in your LLM agents.
Downloads
81
Maintainers
Readme
PromptKit
PromptKit is a lightweight toolkit for managing prompts in your LLM agents.
- Load prompts from files into memory at application startup.
- Supports both plain text prompts and structured chat message formats.
- Inject variables dynamically into prompts using
{{variable}}syntax. Supports both global and prompt-specific variables. - Organize prompts in directories and subdirectories for better management.
Installation
npm install prompt-toolkitUsage
Basic Setup
import { PromptKit } from "prompt-toolkit";
// Create a PromptKit instance
const prompts = new PromptKit({
// OPTIONAL: global variables to inject into all prompts
variables: {
app: "Bastion",
ver: "10.0.0",
},
});Text Prompts
Create a text prompt file (e.g., prompts/system.md):
You are a helpful assistant for {{app}} version {{ver}}.const prompt = prompts.get("system");
// "You are a helpful assistant for Bastion version 10.0.0."
// Override variables per prompt
const customPrompt = prompts.get("system", { ver: "10.17.0" });
// "You are a helpful assistant for Bastion version 10.17.0."Chat Prompts
Create a chat prompt file (e.g., prompts/chat.json):
[
{
"role": "system",
"content": "You are a helpful assistant for {{app}}."
},
{
"role": "developer",
"content": "User's name is {{user}}."
}
]Or use YAML (e.g., prompts/chat.yaml):
- role: system
content: You are a helpful assistant for {{app}}.
- role: developer
content: User's name is {{user}}.const messages = prompts.get("chat", { user: "Alice" });
// [
// { role: "system", content: "You are a helpful assistant for Bastion." },
// { role: "developer", content: "User's name is Alice." }
// ]Directory Structure
Prompts can be organized in subdirectories:
prompts/
├── system.md
├── chat.json
└── nested/
└── skills.md
└── suggestions.mdprompts.get("system"); // From prompts/system.md
prompts.get("chat"); // From prompts/chat.json
prompts.get("nested/skills"); // From prompts/nested/skills.mdMethods
get(name, variables?)
Get a compiled prompt by name.
const prompt = prompts.get("system");
const customPrompt = prompts.get("system", { variable: "value" });Returns:
stringfor text promptsChatMessage[]for chat promptsundefinedif prompt doesn't exist
has(name)
Check if a prompt exists.
if (prompts.has("system")) {
const prompt = prompts.get("system");
}list()
List all available prompt names.
const names = prompts.list();
// [ "system", "chat", "nested/skills", "nested/suggestions" ]reload()
Reload all prompts and update the in-memory cache.
prompts.reload();Variable Substitution
Variables use the {{variableName}} syntax:
// Template: "Hello {{name}}, welcome to {{product}}!"
prompts.get("welcome", { name: "Alice", product: "Omnic" });
// "Hello Alice, welcome to Omnic!"Unmatched variables remain as-is in the output.
