toolpack-sdk 2.6.0 → 3.0.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
@@ -16,6 +16,7 @@ The TypeScript SDK for building production AI agents — 100+ built-in tools, 8
16
16
  - **Embeddings** — Vector generation for RAG applications (OpenAI, Gemini, Ollama)
17
17
  - **Workflow Engine** — AI-driven planning with plan-direct execution and parallel tool orchestration
18
18
  - **Mode System** — Built-in Agent and Chat modes, plus `createMode()` for custom modes with tool filtering
19
+ - **Rules** — Always-on behavioral constraints loaded from Markdown files, auto-discovered per mode and globally via `rulesDir`
19
20
  - **HITL Confirmation** — Human-in-the-loop approval for high-risk operations with configurable bypass rules
20
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
21
22
  - **100+ Built-in Tools** across 12 categories:
@@ -195,9 +196,11 @@ const mcpToolProject = await createMcpToolProject({
195
196
  const sdk = await Toolpack.init({
196
197
  provider: 'openai',
197
198
  tools: true,
198
- customTools: [mcpToolProject],
199
199
  });
200
200
 
201
+ // Use MCP tools via ModeConfig.customTools (per-agent or per-request):
202
+ // agent.mode = { ...myMode, customTools: [...mcpToolProject.tools] };
203
+
201
204
  // On shutdown/cold path:
202
205
  // await disconnectMcpToolProject(mcpToolProject);
203
206
  ```
@@ -343,6 +346,8 @@ sdk.cycleMode(); // Cycles through all registered modes
343
346
  | `blockAllTools` | boolean | `false` | If `true`, disables all tools (pure conversation) |
344
347
  | `baseContext` | object/false | `undefined` | Controls working directory and tool category injection |
345
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`) |
346
351
 
347
352
  ## Workflow Engine
348
353
 
@@ -534,11 +539,20 @@ const myToolProject = createToolProject({
534
539
  ],
535
540
  });
536
541
 
537
- // Register custom tools at init
542
+ // Attach custom tools to a mode — scoped to that agent, not global.
538
543
  const sdk = await Toolpack.init({
539
544
  provider: 'openai',
540
- tools: true, // Load built-in tools
541
- customTools: [myToolProject], // Add your custom tools
545
+ tools: true,
546
+ });
547
+
548
+ // Option A: set on your agent class
549
+ // agent.mode = { ...agentMode, customTools: [...myToolProject.tools] };
550
+
551
+ // Option B: pass inline per-request
552
+ const result = await sdk.generate({
553
+ messages: [{ role: 'user', content: 'Use my tool!' }],
554
+ model: 'gpt-4.1',
555
+ mode: { ...sdk.getMode()!, customTools: [...myToolProject.tools] },
542
556
  });
543
557
  ```
544
558
 
@@ -607,15 +621,17 @@ The skills system lets you define **reusable behavioral instructions** in `.skil
607
621
  ```typescript
608
622
  import { Toolpack, createSkillInterceptor, createSkillTools } from 'toolpack-sdk';
609
623
 
624
+ const skillTools = createSkillTools({ dir: '.toolpack/skills' });
625
+
610
626
  const toolpack = await Toolpack.init({
611
627
  provider: 'anthropic',
612
628
  interceptors: [
613
629
  createSkillInterceptor({ dir: '.toolpack/skills', maxSkills: 3, minScore: 0.3 }),
614
630
  ],
615
- customTools: [
616
- createSkillTools({ dir: '.toolpack/skills' }),
617
- ],
618
631
  });
632
+
633
+ // Attach skill tools per agent via ModeConfig.customTools:
634
+ // agent.mode = { ...agentMode, customTools: [...skillTools.tools] };
619
635
  ```
620
636
 
621
637
  Create a skill file at `.toolpack/skills/code-review.skill.md`:
@@ -1075,148 +1091,104 @@ export ANTHROPIC_API_KEY="sk-ant-..."
1075
1091
  export GOOGLE_GENERATIVE_AI_KEY="AIza..."
1076
1092
  export OPENROUTER_API_KEY="sk-or-..."
1077
1093
 
1078
- # SDK logging (override prefer toolpack.config.json instead)
1094
+ # SDK logging (override programmatic config)
1079
1095
  export TOOLPACK_SDK_LOG_FILE="./toolpack.log" # Log file path (also enables logging)
1080
- export TOOLPACK_SDK_LOG_LEVEL="debug" # Log level override (error, warn, info, debug, trace)
1096
+ export TOOLPACK_SDK_LOG_LEVEL="debug" # Log level (error, warn, info, debug, trace)
1097
+ export TOOLPACK_SDK_LOG_ENABLED="true" # Enable/disable logging
1098
+ export TOOLPACK_SDK_LOG_CONSOLE="true" # Mirror log output to console
1081
1099
  ```
1082
1100
 
1083
- ## Configuration Architecture
1084
-
1085
- Toolpack uses a hierarchical configuration system that separates build-time (SDK) and runtime (CLI) configurations.
1086
-
1087
- ### Configuration Layers
1088
-
1089
- 1. **Workspace Local (Highest Priority)**
1090
- - Location: `<workspace>/.toolpack/config/toolpack.config.json`
1091
- - Purpose: Project-specific overrides for the CLI tool.
1092
-
1093
- 2. **Global Default (CLI First Run)**
1094
- - Location: `~/.toolpack/config/toolpack.config.json`
1095
- - Purpose: Global default settings for the CLI tool across all projects. Created automatically on first run.
1096
-
1097
- 3. **Build Time / SDK Base**
1098
- - Location: `toolpack.config.json` in project root.
1099
- - Purpose: Static configuration used when bundling the SDK or running it directly in an app.
1100
-
1101
- ### Settings UI
1102
-
1103
- 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.
1104
-
1105
- ### Configuration Sections
1106
-
1107
- The `toolpack.config.json` file supports several sections:
1101
+ ### Logging Configuration
1108
1102
 
1109
- #### Global Options
1103
+ Pass `logging` to `Toolpack.init()`:
1110
1104
 
1111
- | Option | Default | Description |
1112
- |--------|---------|-------------|
1113
- | `systemPrompt` | - | Override the base system prompt |
1114
- | `baseContext` | `true` | Agent context configuration (`{ includeWorkingDirectory, includeToolCategories, custom }` or `false`) |
1115
- | `modeOverrides` | `{}` | Mode-specific system prompt and toolSearch overrides |
1116
-
1117
- #### Logging Configuration
1118
-
1119
- Create a `toolpack.config.json` in your project root:
1120
-
1121
- ```json
1122
- {
1123
- "logging": {
1124
- "enabled": true,
1125
- "filePath": "./toolpack.log",
1126
- "level": "info"
1127
- }
1128
- }
1105
+ ```typescript
1106
+ const sdk = await Toolpack.init({
1107
+ provider: 'anthropic',
1108
+ logging: {
1109
+ enabled: true,
1110
+ filePath: './toolpack.log',
1111
+ level: 'debug',
1112
+ console: false,
1113
+ },
1114
+ });
1129
1115
  ```
1130
1116
 
1131
- | Option | Default | Description |
1132
- |--------|---------|-------------|
1133
- | `enabled` | `false` | Enable file logging |
1134
- | `filePath` | `toolpack-sdk.log` | Log file path (relative to CWD) |
1135
- | `level` | `info` | Log level (`error`, `warn`, `info`, `debug`, `trace`) |
1117
+ | Option | Type | Default | Description |
1118
+ |--------|------|---------|-------------|
1119
+ | `enabled` | boolean | `false` | Enable file logging |
1120
+ | `filePath` | string | `toolpack-sdk.log` | Log file path (relative to CWD) |
1121
+ | `level` | string | `info` | Log level (`error`, `warn`, `info`, `debug`, `trace`) |
1122
+ | `console` | boolean | `false` | Mirror log output to console |
1123
+
1124
+ Environment variables override programmatic config (highest precedence).
1136
1125
 
1137
1126
  ### Tools Configuration
1138
1127
 
1139
- Create a `toolpack.config.json` in your project root:
1140
-
1141
- ```json
1142
- {
1143
- "tools": {
1144
- "enabled": true,
1145
- "autoExecute": true,
1146
- "maxToolRounds": 5,
1147
- "toolChoicePolicy": "auto",
1148
- "resultMaxChars": 20000,
1149
- "enabledTools": [],
1150
- "enabledToolCategories": [],
1151
- "additionalConfigurations": {
1152
- "webSearch": {
1153
- "tavilyApiKey": "tvly-...",
1154
- "braveApiKey": "BSA..."
1155
- }
1128
+ Pass `toolsConfig` to `Toolpack.init()` for global defaults, or set `ModeConfig.toolsConfig` for per-agent overrides:
1129
+
1130
+ ```typescript
1131
+ const sdk = await Toolpack.init({
1132
+ provider: 'anthropic',
1133
+ tools: true,
1134
+ toolsConfig: {
1135
+ autoExecute: true,
1136
+ maxToolRounds: 10,
1137
+ toolChoicePolicy: 'auto',
1138
+ resultMaxChars: 20000,
1139
+ additionalConfigurations: {
1140
+ webSearch: {
1141
+ tavilyApiKey: 'tvly-...',
1142
+ braveApiKey: 'BSA...',
1143
+ },
1156
1144
  },
1157
- "toolSearch": {
1158
- "enabled": false,
1159
- "alwaysLoadedTools": ["fs.read_file", "fs.write_file", "fs.list_dir"],
1160
- "alwaysLoadedCategories": [],
1161
- "searchResultLimit": 5,
1162
- "cacheDiscoveredTools": true
1163
- }
1164
- }
1165
- }
1145
+ toolSearch: {
1146
+ enabled: false,
1147
+ alwaysLoadedTools: ['fs.read_file', 'fs.write_file', 'fs.list_dir'],
1148
+ searchResultLimit: 5,
1149
+ cacheDiscoveredTools: true,
1150
+ },
1151
+ },
1152
+ });
1166
1153
  ```
1167
1154
 
1168
- #### Configuration Options
1169
-
1170
1155
  | Option | Type | Default | Description |
1171
1156
  |--------|------|---------|-------------|
1172
- | `enabled` | boolean | `true` | Enable/disable tool system |
1157
+ | `enabled` | boolean | `true` | Enable/disable the tool system entirely |
1173
1158
  | `autoExecute` | boolean | `true` | Auto-execute tool calls from AI |
1174
1159
  | `maxToolRounds` | number | `5` | Max tool execution rounds per request |
1175
1160
  | `toolChoicePolicy` | string | `"auto"` | `"auto"`, `"required"`, or `"required_for_actions"` |
1161
+ | `resultMaxChars` | number | `20000` | Max characters in a tool result |
1176
1162
  | `enabledTools` | string[] | `[]` | Whitelist specific tools (empty = all) |
1177
1163
  | `enabledToolCategories` | string[] | `[]` | Whitelist categories (empty = all) |
1178
1164
 
1179
1165
  ### HITL (Human-in-the-Loop) Configuration
1180
1166
 
1181
- Configure user confirmation for high-risk tool operations:
1182
-
1183
- ```json
1184
- {
1185
- "hitl": {
1186
- "enabled": true,
1187
- "confirmationMode": "all",
1188
- "bypass": {
1189
- "tools": ["fs.write_file"],
1190
- "categories": ["filesystem"],
1191
- "levels": ["medium"]
1192
- }
1193
- }
1194
- }
1167
+ Configure user confirmation for high-risk tool operations via `Toolpack.init()`:
1168
+
1169
+ ```typescript
1170
+ const sdk = await Toolpack.init({
1171
+ provider: 'anthropic',
1172
+ hitl: {
1173
+ enabled: true,
1174
+ confirmationMode: 'all',
1175
+ bypass: {
1176
+ tools: ['fs.write_file'],
1177
+ categories: ['filesystem'],
1178
+ levels: ['medium'],
1179
+ },
1180
+ },
1181
+ });
1195
1182
  ```
1196
1183
 
1197
1184
  | Option | Type | Default | Description |
1198
1185
  |--------|------|---------|-------------|
1199
- | `enabled` | boolean | `true` | Master switch for HITL confirmation |
1186
+ | `enabled` | boolean | `false` | Enable HITL. Auto-enabled when `onToolConfirm` is provided |
1200
1187
  | `confirmationMode` | string | `"all"` | `"off"`, `"high-only"`, or `"all"` |
1201
1188
  | `bypass.tools` | string[] | `[]` | Tool names to bypass (e.g., `["fs.write_file"]`) |
1202
1189
  | `bypass.categories` | string[] | `[]` | Categories to bypass (e.g., `["filesystem"]`) |
1203
1190
  | `bypass.levels` | string[] | `[]` | Risk levels to bypass (`["high"]` or `["medium"]`) |
1204
1191
 
1205
- **Programmatic API:**
1206
-
1207
- ```typescript
1208
- import { addBypassRule, removeBypassRule } from 'toolpack-sdk';
1209
-
1210
- // Add bypass rule
1211
- await addBypassRule({ type: 'tool', value: 'fs.delete_file' });
1212
-
1213
- // Remove bypass rule
1214
- await removeBypassRule({ type: 'tool', value: 'fs.delete_file' });
1215
-
1216
- // Reload config to apply changes
1217
- toolpack.reloadConfig();
1218
- ```
1219
-
1220
1192
  See the [HITL documentation](https://toolpacksdk.com/guides/hitl-confirmation) for detailed configuration options and best practices.
1221
1193
 
1222
1194
  #### Web Search Providers
@@ -1231,17 +1203,19 @@ The `web.search` tool supports multiple search backends with automatic fallback:
1231
1203
 
1232
1204
  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:
1233
1205
 
1234
- ```json
1235
- {
1236
- "tools": {
1237
- "toolSearch": {
1238
- "enabled": true,
1239
- "alwaysLoadedTools": ["fs.read_file", "fs.write_file", "web.search"],
1240
- "searchResultLimit": 5,
1241
- "cacheDiscoveredTools": true
1242
- }
1243
- }
1244
- }
1206
+ ```typescript
1207
+ const sdk = await Toolpack.init({
1208
+ provider: 'anthropic',
1209
+ tools: true,
1210
+ toolsConfig: {
1211
+ toolSearch: {
1212
+ enabled: true,
1213
+ alwaysLoadedTools: ['fs.read_file', 'fs.write_file', 'web.search'],
1214
+ searchResultLimit: 5,
1215
+ cacheDiscoveredTools: true,
1216
+ },
1217
+ },
1218
+ });
1245
1219
  ```
1246
1220
 
1247
1221
  ## API Reference
@@ -1251,6 +1225,12 @@ When you have many tools (50+), enable tool search to reduce token usage. The AI
1251
1225
  ```typescript
1252
1226
  import { Toolpack } from 'toolpack-sdk';
1253
1227
 
1228
+ // ToolpackInitConfig — fields removed in v2.8:
1229
+ // customTools → use ModeConfig.customTools per agent instead
1230
+ // modeOverrides → configure modes directly via registerMode()
1231
+ // configPath → configuration is now passed inline to Toolpack.init()
1232
+ //
1233
+ // Fields added in v2.8: logging, hitl, toolsConfig
1254
1234
  const sdk = await Toolpack.init(config: ToolpackInitConfig): Promise<Toolpack>
1255
1235
 
1256
1236
  // Completions (routes through workflow engine if mode has workflow enabled)