toolpack-sdk 2.7.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 +107 -128
- package/dist/index.cjs +161 -161
- package/dist/index.d.cts +257 -121
- package/dist/index.d.ts +257 -121
- package/dist/index.js +161 -161
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -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
|
|
|
@@ -535,11 +539,20 @@ const myToolProject = createToolProject({
|
|
|
535
539
|
],
|
|
536
540
|
});
|
|
537
541
|
|
|
538
|
-
//
|
|
542
|
+
// Attach custom tools to a mode — scoped to that agent, not global.
|
|
539
543
|
const sdk = await Toolpack.init({
|
|
540
544
|
provider: 'openai',
|
|
541
|
-
tools: true,
|
|
542
|
-
|
|
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] },
|
|
543
556
|
});
|
|
544
557
|
```
|
|
545
558
|
|
|
@@ -608,15 +621,17 @@ The skills system lets you define **reusable behavioral instructions** in `.skil
|
|
|
608
621
|
```typescript
|
|
609
622
|
import { Toolpack, createSkillInterceptor, createSkillTools } from 'toolpack-sdk';
|
|
610
623
|
|
|
624
|
+
const skillTools = createSkillTools({ dir: '.toolpack/skills' });
|
|
625
|
+
|
|
611
626
|
const toolpack = await Toolpack.init({
|
|
612
627
|
provider: 'anthropic',
|
|
613
628
|
interceptors: [
|
|
614
629
|
createSkillInterceptor({ dir: '.toolpack/skills', maxSkills: 3, minScore: 0.3 }),
|
|
615
630
|
],
|
|
616
|
-
customTools: [
|
|
617
|
-
createSkillTools({ dir: '.toolpack/skills' }),
|
|
618
|
-
],
|
|
619
631
|
});
|
|
632
|
+
|
|
633
|
+
// Attach skill tools per agent via ModeConfig.customTools:
|
|
634
|
+
// agent.mode = { ...agentMode, customTools: [...skillTools.tools] };
|
|
620
635
|
```
|
|
621
636
|
|
|
622
637
|
Create a skill file at `.toolpack/skills/code-review.skill.md`:
|
|
@@ -1076,148 +1091,104 @@ export ANTHROPIC_API_KEY="sk-ant-..."
|
|
|
1076
1091
|
export GOOGLE_GENERATIVE_AI_KEY="AIza..."
|
|
1077
1092
|
export OPENROUTER_API_KEY="sk-or-..."
|
|
1078
1093
|
|
|
1079
|
-
# SDK logging (override
|
|
1094
|
+
# SDK logging (override programmatic config)
|
|
1080
1095
|
export TOOLPACK_SDK_LOG_FILE="./toolpack.log" # Log file path (also enables logging)
|
|
1081
|
-
export TOOLPACK_SDK_LOG_LEVEL="debug" # Log level
|
|
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
|
|
1082
1099
|
```
|
|
1083
1100
|
|
|
1084
|
-
|
|
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
|
|
1107
|
-
|
|
1108
|
-
The `toolpack.config.json` file supports several sections:
|
|
1101
|
+
### Logging Configuration
|
|
1109
1102
|
|
|
1110
|
-
|
|
1103
|
+
Pass `logging` to `Toolpack.init()`:
|
|
1111
1104
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
```json
|
|
1123
|
-
{
|
|
1124
|
-
"logging": {
|
|
1125
|
-
"enabled": true,
|
|
1126
|
-
"filePath": "./toolpack.log",
|
|
1127
|
-
"level": "info"
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
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
|
+
});
|
|
1130
1115
|
```
|
|
1131
1116
|
|
|
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`) |
|
|
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).
|
|
1137
1125
|
|
|
1138
1126
|
### Tools Configuration
|
|
1139
1127
|
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
```
|
|
1143
|
-
{
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}
|
|
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
|
+
},
|
|
1157
1144
|
},
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
}
|
|
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
|
+
});
|
|
1167
1153
|
```
|
|
1168
1154
|
|
|
1169
|
-
#### Configuration Options
|
|
1170
|
-
|
|
1171
1155
|
| Option | Type | Default | Description |
|
|
1172
1156
|
|--------|------|---------|-------------|
|
|
1173
|
-
| `enabled` | boolean | `true` | Enable/disable tool system |
|
|
1157
|
+
| `enabled` | boolean | `true` | Enable/disable the tool system entirely |
|
|
1174
1158
|
| `autoExecute` | boolean | `true` | Auto-execute tool calls from AI |
|
|
1175
1159
|
| `maxToolRounds` | number | `5` | Max tool execution rounds per request |
|
|
1176
1160
|
| `toolChoicePolicy` | string | `"auto"` | `"auto"`, `"required"`, or `"required_for_actions"` |
|
|
1161
|
+
| `resultMaxChars` | number | `20000` | Max characters in a tool result |
|
|
1177
1162
|
| `enabledTools` | string[] | `[]` | Whitelist specific tools (empty = all) |
|
|
1178
1163
|
| `enabledToolCategories` | string[] | `[]` | Whitelist categories (empty = all) |
|
|
1179
1164
|
|
|
1180
1165
|
### HITL (Human-in-the-Loop) Configuration
|
|
1181
1166
|
|
|
1182
|
-
Configure user confirmation for high-risk tool operations
|
|
1183
|
-
|
|
1184
|
-
```
|
|
1185
|
-
{
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
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
|
+
});
|
|
1196
1182
|
```
|
|
1197
1183
|
|
|
1198
1184
|
| Option | Type | Default | Description |
|
|
1199
1185
|
|--------|------|---------|-------------|
|
|
1200
|
-
| `enabled` | boolean | `
|
|
1186
|
+
| `enabled` | boolean | `false` | Enable HITL. Auto-enabled when `onToolConfirm` is provided |
|
|
1201
1187
|
| `confirmationMode` | string | `"all"` | `"off"`, `"high-only"`, or `"all"` |
|
|
1202
1188
|
| `bypass.tools` | string[] | `[]` | Tool names to bypass (e.g., `["fs.write_file"]`) |
|
|
1203
1189
|
| `bypass.categories` | string[] | `[]` | Categories to bypass (e.g., `["filesystem"]`) |
|
|
1204
1190
|
| `bypass.levels` | string[] | `[]` | Risk levels to bypass (`["high"]` or `["medium"]`) |
|
|
1205
1191
|
|
|
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
1192
|
See the [HITL documentation](https://toolpacksdk.com/guides/hitl-confirmation) for detailed configuration options and best practices.
|
|
1222
1193
|
|
|
1223
1194
|
#### Web Search Providers
|
|
@@ -1232,17 +1203,19 @@ The `web.search` tool supports multiple search backends with automatic fallback:
|
|
|
1232
1203
|
|
|
1233
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:
|
|
1234
1205
|
|
|
1235
|
-
```
|
|
1236
|
-
{
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
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
|
+
});
|
|
1246
1219
|
```
|
|
1247
1220
|
|
|
1248
1221
|
## API Reference
|
|
@@ -1252,6 +1225,12 @@ When you have many tools (50+), enable tool search to reduce token usage. The AI
|
|
|
1252
1225
|
```typescript
|
|
1253
1226
|
import { Toolpack } from 'toolpack-sdk';
|
|
1254
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
|
|
1255
1234
|
const sdk = await Toolpack.init(config: ToolpackInitConfig): Promise<Toolpack>
|
|
1256
1235
|
|
|
1257
1236
|
// Completions (routes through workflow engine if mode has workflow enabled)
|