Skip to main content

Custom Modes

Create your own modes to define specific tool access and behavior patterns for the AI.

Creating a Custom Mode

Define a mode configuration object:

import { Toolpack, ModeConfig } from 'toolpack-sdk';

const readOnlyMode: ModeConfig = {
name: 'readonly',
displayName: 'Read Only',
description: 'Can read files but not modify anything',
systemPrompt: 'You are a helpful assistant that can read and analyze files but cannot modify them.',

// Tool access control
allowedToolCategories: ['filesystem', 'coding'],
blockedToolCategories: [],
allowedTools: [],
blockedTools: ['fs.write_file', 'fs.delete_file', 'fs.append_file'],
blockAllTools: false,

// Context injection
baseContext: {
includeWorkingDirectory: true,
includeToolCategories: true,
},
};

const toolpack = await Toolpack.init({
provider: 'openai',
tools: true,
customModes: [readOnlyMode],
defaultMode: 'readonly',
});

Mode Configuration Options

OptionTypeDescription
namestringUnique identifier
displayNamestringHuman-readable name
descriptionstringShort description
systemPromptstringSystem prompt injected into requests
allowedToolCategoriesstring[]Categories to allow (empty = all)
blockedToolCategoriesstring[]Categories to block
allowedToolsstring[]Specific tools to allow
blockedToolsstring[]Specific tools to block
blockAllToolsbooleanBlock all tools entirely
baseContextobjectContext injection settings
workflowobjectWorkflow configuration

Tool Categories

Use these category names in allowedToolCategories or blockedToolCategories:

CategoryTools
filesystemfs.read_file, fs.write_file, fs.list_dir, etc.
executionexec.run, exec.run_shell, exec.run_background, etc.
systemsystem.info, system.env, system.cwd, etc.
networkhttp.get, http.post, web.search, web.scrape, etc.
codingcoding.find_symbol, coding.get_imports, etc.
version-controlgit.status, git.diff, git.commit, etc.
diffdiff.create, diff.apply, diff.preview
databasedb.query, db.schema, db.tables, etc.
cloudcloud.deploy, cloud.status, cloud.list

Example Modes

Web Research Mode

Only allow web access, no local file operations:

const webResearchMode: ModeConfig = {
name: 'web-research',
displayName: 'Web Research',
description: 'Web search and scraping only',
systemPrompt: 'You are a research assistant. You can search and scrape the web, but cannot access local files or execute commands.',
allowedToolCategories: ['network'],
blockedToolCategories: [],
allowedTools: [],
blockedTools: [],
blockAllTools: false,
};

Code Review Mode

Read-only access to code analysis tools:

const codeReviewMode: ModeConfig = {
name: 'code-review',
displayName: 'Code Review',
description: 'Analyze code without modifications',
systemPrompt: 'You are a code reviewer. Analyze code quality, find issues, and suggest improvements. You cannot modify files.',
allowedToolCategories: ['filesystem', 'coding', 'version-control'],
blockedToolCategories: [],
allowedTools: [],
blockedTools: ['fs.write_file', 'fs.delete_file', 'fs.append_file', 'git.commit', 'git.add'],
blockAllTools: false,
};

Registering Modes at Runtime

You can register modes after initialization:

// Register a new mode after initialization
toolpack.registerMode({
name: 'minimal',
displayName: 'Minimal',
description: 'No tools at all',
systemPrompt: 'You are a simple chatbot with no tool access.',
allowedToolCategories: [],
blockedToolCategories: [],
allowedTools: [],
blockedTools: [],
blockAllTools: true,
});

// Switch to the new mode
toolpack.setMode('minimal');

Using the createMode Helper

The SDK provides a createMode helper for cleaner syntax:

import { createMode } from 'toolpack-sdk';

const myMode = createMode({
name: 'my-mode',
displayName: 'My Mode',
systemPrompt: 'Custom system prompt',
blockAllTools: true,
});

const toolpack = await Toolpack.init({
provider: 'openai',
customModes: [myMode],
defaultMode: 'my-mode',
});

Workflow Configuration in Modes

Modes can configure workflow behavior for planned execution:

const plannerMode: ModeConfig = {
name: 'planner',
displayName: 'Planner',
description: 'Plans before executing',
systemPrompt: 'You are a careful AI that plans before acting.',
allowedToolCategories: [],
blockedToolCategories: [],
allowedTools: [],
blockedTools: [],
blockAllTools: false,

workflow: {
planning: {
enabled: true,
requireApproval: false,
},
steps: {
enabled: true,
retryOnFailure: true,
allowDynamicSteps: true,
},
progress: { enabled: true },
},
};

See Workflows for more details on workflow configuration.

Best Practices

  • Clear naming - Use descriptive name and displayName values
  • Specific prompts - Tailor systemPrompt to the mode's purpose
  • Minimal permissions - Only allow tools needed for the mode's function
  • Test thoroughly - Verify tool restrictions work as expected
  • Document behavior - Use description to explain what the mode does