toolpack-sdk 2.7.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ The TypeScript SDK for building production AI agents — 100+ built-in tools, 8
19
19
  - **Rules** — Always-on behavioral constraints loaded from Markdown files, auto-discovered per mode and globally via `rulesDir`
20
20
  - **HITL Confirmation** — Human-in-the-loop approval for high-risk operations with configurable bypass rules
21
21
  - **Extensible at Every Layer** — Every built-in component is a plug-in point: custom tools (`ToolDefinition`), custom channels (`BaseChannel`), custom provider adapters (`ProviderAdapter`), custom agents (`BaseAgent`), custom modes (`createMode()`), and custom interceptors — all using the same interfaces as the built-ins
22
- - **100+ Built-in Tools** across 12 categories:
22
+ - **100+ Built-in Tools** across 15 categories:
23
23
  - **MCP Client & Server** — consume external MCP servers via `createMcpToolProject()`, or expose Toolpack as an MCP server via `sdk.startMcpServer()` with static/JWT/custom auth, search mode, and agent exposure.
24
24
 
25
25
  | Category | Tools | Description |
@@ -196,9 +196,11 @@ const mcpToolProject = await createMcpToolProject({
196
196
  const sdk = await Toolpack.init({
197
197
  provider: 'openai',
198
198
  tools: true,
199
- customTools: [mcpToolProject],
200
199
  });
201
200
 
201
+ // Use MCP tools via ModeConfig.customTools (per-agent or per-request):
202
+ // agent.mode = { ...myMode, customTools: [...mcpToolProject.tools] };
203
+
202
204
  // On shutdown/cold path:
203
205
  // await disconnectMcpToolProject(mcpToolProject);
204
206
  ```
@@ -344,6 +346,8 @@ sdk.cycleMode(); // Cycles through all registered modes
344
346
  | `blockAllTools` | boolean | `false` | If `true`, disables all tools (pure conversation) |
345
347
  | `baseContext` | object/false | `undefined` | Controls working directory and tool category injection |
346
348
  | `workflow` | WorkflowConfig | `undefined` | Planning, execution mode, and progress configuration |
349
+ | `customTools` | ToolDefinition[] | `[]` | Agent-specific tools — never shared across agents |
350
+ | `toolsConfig` | Partial\<ToolsConfig\> | `{}` | Per-agent tool behavior overrides (merged over global `toolsConfig`) |
347
351
 
348
352
  ## Workflow Engine
349
353
 
@@ -501,7 +505,7 @@ client.on('tool:failed', (event) => { /* ... */ });
501
505
 
502
506
  ## Custom Tools
503
507
 
504
- In addition to the 100+ built-in tools, you can create and register your own custom tool projects using `createToolProject()`:
508
+ In addition to the 100+ built-in tools, you can create and register your own custom tool projects using `createToolProject()`. Built-in tool categories used for mode filtering include `filesystem`, `coding`, `version-control`, `http`, `web`, `github`, `slack`, `execution`, `system`, and others — there is no combined `network` category.
505
509
 
506
510
  ```typescript
507
511
  import { Toolpack, createToolProject } from 'toolpack-sdk';
@@ -535,12 +539,25 @@ const myToolProject = createToolProject({
535
539
  ],
536
540
  });
537
541
 
538
- // Register custom tools at init
542
+ // Attach custom tools to a mode — scoped to that agent, not global.
543
+ // To replace built-ins by name at init time, pass toolOverrides: [myToolProject].
539
544
  const sdk = await Toolpack.init({
540
545
  provider: 'openai',
541
- tools: true, // Load built-in tools
542
- customTools: [myToolProject], // Add your custom tools
546
+ tools: true,
547
+ });
548
+
549
+ // Option A: set on your agent class
550
+ // agent.mode = { ...agentMode, customTools: [...myToolProject.tools] };
551
+
552
+ // Option B: pass inline per-request
553
+ const result = await sdk.generate({
554
+ messages: [{ role: 'user', content: 'Use my tool!' }],
555
+ model: 'gpt-4.1',
556
+ mode: { ...sdk.getMode()!, customTools: [...myToolProject.tools] },
543
557
  });
558
+
559
+ // Option C: load projects at runtime (rebuilds the tool search index once)
560
+ await sdk.loadToolProjects([myToolProject]);
544
561
  ```
545
562
 
546
563
  ### Tool Project Structure
@@ -593,11 +610,12 @@ const response = await toolpack.chat('How do I configure authentication?');
593
610
 
594
611
  - **Multiple Providers**: In-memory (`MemoryProvider`) or persistent SQLite (`PersistentKnowledgeProvider`)
595
612
  - **Multiple Embedders**: OpenAI, Ollama (local), or custom embedders
596
- - **Multiple Sources**: Markdown, JSON, SQLite ingestion
613
+ - **Multiple Sources**: Markdown, text, web, API, JSON, SQLite, and more
597
614
  - **Progress Events**: Track embedding progress with `onEmbeddingProgress`
598
615
  - **Metadata Filtering**: Query with filters like `{ hasCode: true, category: 'api' }`
616
+ - **Incremental updates**: `ingest()`, `delete()`, and `deleteWhere()` for per-item lifecycle
599
617
 
600
- See the [Knowledge package README](./packages/toolpack-knowledge/README.md) for full documentation.
618
+ See the [Knowledge package README](../toolpack-knowledge/README.md) for full documentation.
601
619
 
602
620
  ## Skills
603
621
 
@@ -608,15 +626,17 @@ The skills system lets you define **reusable behavioral instructions** in `.skil
608
626
  ```typescript
609
627
  import { Toolpack, createSkillInterceptor, createSkillTools } from 'toolpack-sdk';
610
628
 
629
+ const skillTools = createSkillTools({ dir: '.toolpack/skills' });
630
+
611
631
  const toolpack = await Toolpack.init({
612
632
  provider: 'anthropic',
613
633
  interceptors: [
614
634
  createSkillInterceptor({ dir: '.toolpack/skills', maxSkills: 3, minScore: 0.3 }),
615
635
  ],
616
- customTools: [
617
- createSkillTools({ dir: '.toolpack/skills' }),
618
- ],
619
636
  });
637
+
638
+ // Attach skill tools per agent via ModeConfig.customTools:
639
+ // agent.mode = { ...agentMode, customTools: [...skillTools.tools] };
620
640
  ```
621
641
 
622
642
  Create a skill file at `.toolpack/skills/code-review.skill.md`:
@@ -1076,148 +1096,104 @@ export ANTHROPIC_API_KEY="sk-ant-..."
1076
1096
  export GOOGLE_GENERATIVE_AI_KEY="AIza..."
1077
1097
  export OPENROUTER_API_KEY="sk-or-..."
1078
1098
 
1079
- # SDK logging (override prefer toolpack.config.json instead)
1099
+ # SDK logging (override programmatic config)
1080
1100
  export TOOLPACK_SDK_LOG_FILE="./toolpack.log" # Log file path (also enables logging)
1081
- export TOOLPACK_SDK_LOG_LEVEL="debug" # Log level override (error, warn, info, debug, trace)
1101
+ export TOOLPACK_SDK_LOG_LEVEL="debug" # Log level (error, warn, info, debug, trace)
1102
+ export TOOLPACK_SDK_LOG_ENABLED="true" # Enable/disable logging
1103
+ export TOOLPACK_SDK_LOG_CONSOLE="true" # Mirror log output to console
1082
1104
  ```
1083
1105
 
1084
- ## Configuration Architecture
1085
-
1086
- Toolpack uses a hierarchical configuration system that separates build-time (SDK) and runtime (CLI) configurations.
1087
-
1088
- ### Configuration Layers
1089
-
1090
- 1. **Workspace Local (Highest Priority)**
1091
- - Location: `<workspace>/.toolpack/config/toolpack.config.json`
1092
- - Purpose: Project-specific overrides for the CLI tool.
1093
-
1094
- 2. **Global Default (CLI First Run)**
1095
- - Location: `~/.toolpack/config/toolpack.config.json`
1096
- - Purpose: Global default settings for the CLI tool across all projects. Created automatically on first run.
1097
-
1098
- 3. **Build Time / SDK Base**
1099
- - Location: `toolpack.config.json` in project root.
1100
- - Purpose: Static configuration used when bundling the SDK or running it directly in an app.
1101
-
1102
- ### Settings UI
1103
-
1104
- The CLI includes a settings screen to view the active configuration source and its location. Press `Ctrl+S` from the Home screen to access it.
1105
-
1106
- ### Configuration Sections
1106
+ ### Logging Configuration
1107
1107
 
1108
- The `toolpack.config.json` file supports several sections:
1108
+ Pass `logging` to `Toolpack.init()`:
1109
1109
 
1110
- #### Global Options
1111
-
1112
- | Option | Default | Description |
1113
- |--------|---------|-------------|
1114
- | `systemPrompt` | - | Override the base system prompt |
1115
- | `baseContext` | `true` | Agent context configuration (`{ includeWorkingDirectory, includeToolCategories, custom }` or `false`) |
1116
- | `modeOverrides` | `{}` | Mode-specific system prompt and toolSearch overrides |
1117
-
1118
- #### Logging Configuration
1119
-
1120
- Create a `toolpack.config.json` in your project root:
1121
-
1122
- ```json
1123
- {
1124
- "logging": {
1125
- "enabled": true,
1126
- "filePath": "./toolpack.log",
1127
- "level": "info"
1128
- }
1129
- }
1110
+ ```typescript
1111
+ const sdk = await Toolpack.init({
1112
+ provider: 'anthropic',
1113
+ logging: {
1114
+ enabled: true,
1115
+ filePath: './toolpack.log',
1116
+ level: 'debug',
1117
+ console: false,
1118
+ },
1119
+ });
1130
1120
  ```
1131
1121
 
1132
- | Option | Default | Description |
1133
- |--------|---------|-------------|
1134
- | `enabled` | `false` | Enable file logging |
1135
- | `filePath` | `toolpack-sdk.log` | Log file path (relative to CWD) |
1136
- | `level` | `info` | Log level (`error`, `warn`, `info`, `debug`, `trace`) |
1122
+ | Option | Type | Default | Description |
1123
+ |--------|------|---------|-------------|
1124
+ | `enabled` | boolean | `false` | Enable file logging |
1125
+ | `filePath` | string | `toolpack-sdk.log` | Log file path (relative to CWD) |
1126
+ | `level` | string | `info` | Log level (`error`, `warn`, `info`, `debug`, `trace`) |
1127
+ | `console` | boolean | `false` | Mirror log output to console |
1128
+
1129
+ Environment variables override programmatic config (highest precedence).
1137
1130
 
1138
1131
  ### Tools Configuration
1139
1132
 
1140
- Create a `toolpack.config.json` in your project root:
1141
-
1142
- ```json
1143
- {
1144
- "tools": {
1145
- "enabled": true,
1146
- "autoExecute": true,
1147
- "maxToolRounds": 5,
1148
- "toolChoicePolicy": "auto",
1149
- "resultMaxChars": 20000,
1150
- "enabledTools": [],
1151
- "enabledToolCategories": [],
1152
- "additionalConfigurations": {
1153
- "webSearch": {
1154
- "tavilyApiKey": "tvly-...",
1155
- "braveApiKey": "BSA..."
1156
- }
1133
+ Pass `toolsConfig` to `Toolpack.init()` for global defaults, or set `ModeConfig.toolsConfig` for per-agent overrides:
1134
+
1135
+ ```typescript
1136
+ const sdk = await Toolpack.init({
1137
+ provider: 'anthropic',
1138
+ tools: true,
1139
+ toolsConfig: {
1140
+ autoExecute: true,
1141
+ maxToolRounds: 10,
1142
+ toolChoicePolicy: 'auto',
1143
+ resultMaxChars: 20000,
1144
+ additionalConfigurations: {
1145
+ webSearch: {
1146
+ tavilyApiKey: 'tvly-...',
1147
+ braveApiKey: 'BSA...',
1148
+ },
1157
1149
  },
1158
- "toolSearch": {
1159
- "enabled": false,
1160
- "alwaysLoadedTools": ["fs.read_file", "fs.write_file", "fs.list_dir"],
1161
- "alwaysLoadedCategories": [],
1162
- "searchResultLimit": 5,
1163
- "cacheDiscoveredTools": true
1164
- }
1165
- }
1166
- }
1150
+ toolSearch: {
1151
+ enabled: false,
1152
+ alwaysLoadedTools: ['fs.read_file', 'fs.write_file', 'fs.list_dir'],
1153
+ searchResultLimit: 5,
1154
+ cacheDiscoveredTools: true,
1155
+ },
1156
+ },
1157
+ });
1167
1158
  ```
1168
1159
 
1169
- #### Configuration Options
1170
-
1171
1160
  | Option | Type | Default | Description |
1172
1161
  |--------|------|---------|-------------|
1173
- | `enabled` | boolean | `true` | Enable/disable tool system |
1162
+ | `enabled` | boolean | `true` | Enable/disable the tool system entirely |
1174
1163
  | `autoExecute` | boolean | `true` | Auto-execute tool calls from AI |
1175
1164
  | `maxToolRounds` | number | `5` | Max tool execution rounds per request |
1176
1165
  | `toolChoicePolicy` | string | `"auto"` | `"auto"`, `"required"`, or `"required_for_actions"` |
1166
+ | `resultMaxChars` | number | `20000` | Max characters in a tool result |
1177
1167
  | `enabledTools` | string[] | `[]` | Whitelist specific tools (empty = all) |
1178
1168
  | `enabledToolCategories` | string[] | `[]` | Whitelist categories (empty = all) |
1179
1169
 
1180
1170
  ### HITL (Human-in-the-Loop) Configuration
1181
1171
 
1182
- Configure user confirmation for high-risk tool operations:
1183
-
1184
- ```json
1185
- {
1186
- "hitl": {
1187
- "enabled": true,
1188
- "confirmationMode": "all",
1189
- "bypass": {
1190
- "tools": ["fs.write_file"],
1191
- "categories": ["filesystem"],
1192
- "levels": ["medium"]
1193
- }
1194
- }
1195
- }
1172
+ Configure user confirmation for high-risk tool operations via `Toolpack.init()`:
1173
+
1174
+ ```typescript
1175
+ const sdk = await Toolpack.init({
1176
+ provider: 'anthropic',
1177
+ hitl: {
1178
+ enabled: true,
1179
+ confirmationMode: 'all',
1180
+ bypass: {
1181
+ tools: ['fs.write_file'],
1182
+ categories: ['filesystem'],
1183
+ levels: ['medium'],
1184
+ },
1185
+ },
1186
+ });
1196
1187
  ```
1197
1188
 
1198
1189
  | Option | Type | Default | Description |
1199
1190
  |--------|------|---------|-------------|
1200
- | `enabled` | boolean | `true` | Master switch for HITL confirmation |
1191
+ | `enabled` | boolean | `false` | Enable HITL. Auto-enabled when `onToolConfirm` is provided |
1201
1192
  | `confirmationMode` | string | `"all"` | `"off"`, `"high-only"`, or `"all"` |
1202
1193
  | `bypass.tools` | string[] | `[]` | Tool names to bypass (e.g., `["fs.write_file"]`) |
1203
1194
  | `bypass.categories` | string[] | `[]` | Categories to bypass (e.g., `["filesystem"]`) |
1204
1195
  | `bypass.levels` | string[] | `[]` | Risk levels to bypass (`["high"]` or `["medium"]`) |
1205
1196
 
1206
- **Programmatic API:**
1207
-
1208
- ```typescript
1209
- import { addBypassRule, removeBypassRule } from 'toolpack-sdk';
1210
-
1211
- // Add bypass rule
1212
- await addBypassRule({ type: 'tool', value: 'fs.delete_file' });
1213
-
1214
- // Remove bypass rule
1215
- await removeBypassRule({ type: 'tool', value: 'fs.delete_file' });
1216
-
1217
- // Reload config to apply changes
1218
- toolpack.reloadConfig();
1219
- ```
1220
-
1221
1197
  See the [HITL documentation](https://toolpacksdk.com/guides/hitl-confirmation) for detailed configuration options and best practices.
1222
1198
 
1223
1199
  #### Web Search Providers
@@ -1232,17 +1208,19 @@ The `web.search` tool supports multiple search backends with automatic fallback:
1232
1208
 
1233
1209
  When you have many tools (50+), enable tool search to reduce token usage. The AI discovers tools on-demand via a built-in `tool.search` meta-tool using BM25 ranking:
1234
1210
 
1235
- ```json
1236
- {
1237
- "tools": {
1238
- "toolSearch": {
1239
- "enabled": true,
1240
- "alwaysLoadedTools": ["fs.read_file", "fs.write_file", "web.search"],
1241
- "searchResultLimit": 5,
1242
- "cacheDiscoveredTools": true
1243
- }
1244
- }
1245
- }
1211
+ ```typescript
1212
+ const sdk = await Toolpack.init({
1213
+ provider: 'anthropic',
1214
+ tools: true,
1215
+ toolsConfig: {
1216
+ toolSearch: {
1217
+ enabled: true,
1218
+ alwaysLoadedTools: ['fs.read_file', 'fs.write_file', 'web.search'],
1219
+ searchResultLimit: 5,
1220
+ cacheDiscoveredTools: true,
1221
+ },
1222
+ },
1223
+ });
1246
1224
  ```
1247
1225
 
1248
1226
  ## API Reference
@@ -1252,6 +1230,12 @@ When you have many tools (50+), enable tool search to reduce token usage. The AI
1252
1230
  ```typescript
1253
1231
  import { Toolpack } from 'toolpack-sdk';
1254
1232
 
1233
+ // ToolpackInitConfig — fields removed in v3.0.0:
1234
+ // customTools → use ModeConfig.customTools per agent instead
1235
+ // modeOverrides → configure modes directly via registerMode()
1236
+ // configPath → configuration is now passed inline to Toolpack.init()
1237
+ //
1238
+ // Fields: logging, hitl, toolsConfig, toolOverrides (v3.1.0)
1255
1239
  const sdk = await Toolpack.init(config: ToolpackInitConfig): Promise<Toolpack>
1256
1240
 
1257
1241
  // Completions (routes through workflow engine if mode has workflow enabled)
@@ -1271,6 +1255,12 @@ sdk.getModes(): ModeConfig[]
1271
1255
  sdk.cycleMode(): ModeConfig
1272
1256
  sdk.registerMode(mode: ModeConfig): void
1273
1257
 
1258
+ // Tool projects
1259
+ await sdk.loadToolProject(project: ToolProject): Promise<void>
1260
+ await sdk.loadToolProjects(projects: ToolProject[]): Promise<void>
1261
+ sdk.searchTools(query: string, category?: string)
1262
+ sdk.getRegisteredToolNames(): string[]
1263
+
1274
1264
  // Internal access
1275
1265
  sdk.getClient(): AIClient
1276
1266
  sdk.getWorkflowExecutor(): WorkflowExecutor