@toolpack-sdk/agents 2.2.0 → 2.4.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.
@@ -1,5 +1,5 @@
1
- import { B as BaseAgentOptions, A as AgentInput, a as AgentResult } from './types-TB6yypig.js';
2
- import { B as BaseAgent } from './base-agent-nU8pr4nu.js';
1
+ import { B as BaseAgentOptions, A as AgentInput, a as AgentResult } from './types-C3EZvpe0.js';
2
+ import { B as BaseAgent } from './base-agent-C4fYjHPu.js';
3
3
  import { ModeConfig } from 'toolpack-sdk';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { B as BaseAgentOptions, A as AgentInput, a as AgentResult } from './types-TB6yypig.cjs';
2
- import { B as BaseAgent } from './base-agent-DPdK4Pnl.cjs';
1
+ import { B as BaseAgentOptions, A as AgentInput, a as AgentResult } from './types-C3EZvpe0.cjs';
2
+ import { B as BaseAgent } from './base-agent-Dqca3WLY.cjs';
3
3
  import { ModeConfig } from 'toolpack-sdk';
4
4
 
5
5
  /**
@@ -1,9 +1,9 @@
1
- import { A as AgentInput, i as InterceptorResult, I as Interceptor, f as AgentInstance, C as ChannelInterface, c as IAgentRegistry, g as InterceptorChainConfig, a as AgentResult } from '../types-TB6yypig.cjs';
2
- export { h as InterceptorContext, N as NextFunction, S as SKIP_SENTINEL, j as isSkipSentinel, s as skip } from '../types-TB6yypig.cjs';
1
+ import { A as AgentInput, k as InterceptorResult, I as Interceptor, g as AgentInstance, C as ChannelInterface, d as IAgentRegistry, i as InterceptorChainConfig, a as AgentResult } from '../types-C3EZvpe0.cjs';
2
+ export { j as InterceptorContext, N as NextFunction, S as SKIP_SENTINEL, l as isSkipSentinel, s as skip } from '../types-C3EZvpe0.cjs';
3
3
  import { Participant, ConversationStore, ConversationScope, StoredMessage } from 'toolpack-sdk';
4
- import { I as IntentClassification } from '../intent-classifier-agent-DxyfJWcm.cjs';
4
+ import { I as IntentClassification } from '../intent-classifier-agent-CPKmOVJx.cjs';
5
5
  import 'events';
6
- import '../base-agent-DPdK4Pnl.cjs';
6
+ import '../base-agent-Dqca3WLY.cjs';
7
7
  import '@toolpack-sdk/knowledge';
8
8
 
9
9
  /**
@@ -1,9 +1,9 @@
1
- import { A as AgentInput, i as InterceptorResult, I as Interceptor, f as AgentInstance, C as ChannelInterface, c as IAgentRegistry, g as InterceptorChainConfig, a as AgentResult } from '../types-TB6yypig.js';
2
- export { h as InterceptorContext, N as NextFunction, S as SKIP_SENTINEL, j as isSkipSentinel, s as skip } from '../types-TB6yypig.js';
1
+ import { A as AgentInput, k as InterceptorResult, I as Interceptor, g as AgentInstance, C as ChannelInterface, d as IAgentRegistry, i as InterceptorChainConfig, a as AgentResult } from '../types-C3EZvpe0.js';
2
+ export { j as InterceptorContext, N as NextFunction, S as SKIP_SENTINEL, l as isSkipSentinel, s as skip } from '../types-C3EZvpe0.js';
3
3
  import { Participant, ConversationStore, ConversationScope, StoredMessage } from 'toolpack-sdk';
4
- import { I as IntentClassification } from '../intent-classifier-agent-0JZDlhpk.js';
4
+ import { I as IntentClassification } from '../intent-classifier-agent-ACQSotfT.js';
5
5
  import 'events';
6
- import '../base-agent-nU8pr4nu.js';
6
+ import '../base-agent-C4fYjHPu.js';
7
7
  import '@toolpack-sdk/knowledge';
8
8
 
9
9
  /**
@@ -1,8 +1,8 @@
1
- import { C as ChannelInterface, e as AgentOutput, A as AgentInput, B as BaseAgentOptions } from '../types-TB6yypig.cjs';
1
+ import { C as ChannelInterface, f as AgentOutput, A as AgentInput, B as BaseAgentOptions } from '../types-C3EZvpe0.cjs';
2
2
  import { Chunk, QueryOptions, QueryResult, Knowledge } from '@toolpack-sdk/knowledge';
3
3
  import { Toolpack } from 'toolpack-sdk';
4
- import { B as BaseAgent } from '../base-agent-DPdK4Pnl.cjs';
5
- export { C as ContainsScorer, a as CustomScorer, E as EvalCase, b as EvalCaseResult, c as EvalDataset, d as EvalImprovement, e as EvalRegression, f as EvalReport, g as EvalRun, h as EvalRunner, i as EvalRunnerOptions, j as EvalScoredResult, k as EvalScoredRun, l as EvalScorer, m as EvalVerdict, n as ExactMatchScorer, L as LLMJudgeScorer, o as LLMJudgeScorerOptions, p as compareEvalRuns, q as formatEvalReport } from '../eval-report-BCGixIYd.cjs';
4
+ import { B as BaseAgent } from '../base-agent-Dqca3WLY.cjs';
5
+ export { C as ContainsScorer, a as CustomScorer, E as EvalCase, b as EvalCaseResult, c as EvalDataset, d as EvalImprovement, e as EvalRegression, f as EvalReport, g as EvalRun, h as EvalRunner, i as EvalRunnerOptions, j as EvalScoredResult, k as EvalScoredRun, l as EvalScorer, m as EvalVerdict, n as ExactMatchScorer, L as LLMJudgeScorer, o as LLMJudgeScorerOptions, p as compareEvalRuns, q as formatEvalReport } from '../eval-report-DV-wNcjW.cjs';
6
6
  import 'events';
7
7
 
8
8
  /**
@@ -1,8 +1,8 @@
1
- import { C as ChannelInterface, e as AgentOutput, A as AgentInput, B as BaseAgentOptions } from '../types-TB6yypig.js';
1
+ import { C as ChannelInterface, f as AgentOutput, A as AgentInput, B as BaseAgentOptions } from '../types-C3EZvpe0.js';
2
2
  import { Chunk, QueryOptions, QueryResult, Knowledge } from '@toolpack-sdk/knowledge';
3
3
  import { Toolpack } from 'toolpack-sdk';
4
- import { B as BaseAgent } from '../base-agent-nU8pr4nu.js';
5
- export { C as ContainsScorer, a as CustomScorer, E as EvalCase, b as EvalCaseResult, c as EvalDataset, d as EvalImprovement, e as EvalRegression, f as EvalReport, g as EvalRun, h as EvalRunner, i as EvalRunnerOptions, j as EvalScoredResult, k as EvalScoredRun, l as EvalScorer, m as EvalVerdict, n as ExactMatchScorer, L as LLMJudgeScorer, o as LLMJudgeScorerOptions, p as compareEvalRuns, q as formatEvalReport } from '../eval-report-CpdAMa2b.js';
4
+ import { B as BaseAgent } from '../base-agent-C4fYjHPu.js';
5
+ export { C as ContainsScorer, a as CustomScorer, E as EvalCase, b as EvalCaseResult, c as EvalDataset, d as EvalImprovement, e as EvalRegression, f as EvalReport, g as EvalRun, h as EvalRunner, i as EvalRunnerOptions, j as EvalScoredResult, k as EvalScoredRun, l as EvalScorer, m as EvalVerdict, n as ExactMatchScorer, L as LLMJudgeScorer, o as LLMJudgeScorerOptions, p as compareEvalRuns, q as formatEvalReport } from '../eval-report-CO98LRUC.js';
6
6
  import 'events';
7
7
 
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { Participant, ModeConfig, Toolpack } from 'toolpack-sdk';
1
+ import { Participant, ModeConfig, ToolpackInitConfig, Toolpack } from 'toolpack-sdk';
2
2
  import { EventEmitter } from 'events';
3
3
 
4
4
  /**
@@ -110,16 +110,14 @@ interface InterceptorChainConfig {
110
110
  /**
111
111
  * Options for constructing a BaseAgent.
112
112
  *
113
- * - `{ apiKey, provider?, model? }` — agent creates and owns its own Toolpack instance.
113
+ * - `ToolpackInitConfig` — agent creates and owns its own Toolpack instance using
114
+ * the supplied config. Accepts everything `Toolpack.init()` accepts: `apiKey`,
115
+ * `provider`, `model`, `customTools`, `tools`, `knowledge`, `customModes`, etc.
114
116
  * The instance is initialised lazily in `start()`.
115
117
  * - `{ toolpack }` — agent uses a shared Toolpack instance (e.g. passed from AgentRegistry
116
- * for multi-agent setups where API client and config are shared).
118
+ * for multi-agent setups where the API client and config are shared).
117
119
  */
118
- type BaseAgentOptions = {
119
- apiKey: string;
120
- provider?: string;
121
- model?: string;
122
- } | {
120
+ type BaseAgentOptions = ToolpackInitConfig | {
123
121
  toolpack: Toolpack;
124
122
  };
125
123
  /**
@@ -152,6 +150,53 @@ interface AgentDelegationConfig {
152
150
  */
153
151
  mode?: 'await' | 'forget';
154
152
  }
153
+ /**
154
+ * Definition of a single spawnable agent template.
155
+ * Templates are config objects — no subclassing required.
156
+ * The SDK instantiates an EphemeralAgent from this at spawn time.
157
+ */
158
+ interface AgentSpawnTemplate {
159
+ /** Unique name for this template; use `'self'` as a reserved name for self-replication. */
160
+ name: string;
161
+ /** Human-readable purpose shown to the LLM so it can pick the right template. */
162
+ description: string;
163
+ /**
164
+ * Factory that receives the task string and returns the system prompt for the
165
+ * spawned agent. Called once per spawn invocation.
166
+ */
167
+ systemPrompt: (task: string) => string;
168
+ /** Model override for spawned agents of this template. Inherits parent model when omitted. */
169
+ model?: string;
170
+ /**
171
+ * Allow the LLM to append extra instructions to this template's system prompt
172
+ * via the `systemPromptAddition` tool parameter. Defaults to `false`.
173
+ * Only enable this for templates where LLM-driven prompt customisation is safe.
174
+ */
175
+ allowPromptAddition?: boolean;
176
+ }
177
+ /**
178
+ * Configuration for AI-driven dynamic agent spawning.
179
+ * When enabled, a `spawn_agent` tool is injected into every `run()` call so
180
+ * the LLM can instantiate a one-off helper agent, get its result, and continue.
181
+ * Spawned agents are ephemeral: no channels, no registry entry, discarded after use.
182
+ */
183
+ interface AgentSpawnConfig {
184
+ /** Must be true for the spawn tool to be injected. */
185
+ enabled: boolean;
186
+ /**
187
+ * List of agent templates available for spawning.
188
+ * The LLM sees each template's name and description to decide which to use.
189
+ * Add a template with `name: 'self'` to opt in to self-replication — without
190
+ * it, the `spawn_agent` tool will not advertise or accept `"self"` as a target.
191
+ */
192
+ templates: AgentSpawnTemplate[];
193
+ /**
194
+ * Maximum recursive spawn depth (default: 3).
195
+ * When a spawned agent reaches this depth, the spawn tool is not injected —
196
+ * stopping the chain without throwing an error.
197
+ */
198
+ maxDepth?: number;
199
+ }
155
200
  /**
156
201
  * Input structure for agent invocation.
157
202
  * Channels normalize external events into this format.
@@ -427,6 +472,15 @@ interface IAgentRegistry {
427
472
  * @returns Number of asks cleaned up
428
473
  */
429
474
  cleanupExpiredAsks(): number;
475
+ /** Returns true when all registered agents have no in-progress conversations. */
476
+ isAllIdle?(): boolean;
477
+ /**
478
+ * Schedule a graceful restart once all agents become idle, or after maxWaitMinutes
479
+ * (default 30) if idle is never reached. Idempotent — subsequent calls are no-ops.
480
+ */
481
+ scheduleRestart?(options?: {
482
+ maxWaitMinutes?: number;
483
+ }): void;
430
484
  }
431
485
 
432
- export { type AgentInput as A, type BaseAgentOptions as B, type ChannelInterface as C, type Interceptor as I, type NextFunction as N, type PendingAsk as P, SKIP_SENTINEL as S, type WorkflowStep as W, type AgentResult as a, type AgentDelegationConfig as b, type IAgentRegistry as c, type AgentRunOptions as d, type AgentOutput as e, type AgentInstance as f, type InterceptorChainConfig as g, type InterceptorContext as h, type InterceptorResult as i, isSkipSentinel as j, skip as s };
486
+ export { type AgentInput as A, type BaseAgentOptions as B, type ChannelInterface as C, type Interceptor as I, type NextFunction as N, type PendingAsk as P, SKIP_SENTINEL as S, type WorkflowStep as W, type AgentResult as a, type AgentDelegationConfig as b, type AgentSpawnConfig as c, type IAgentRegistry as d, type AgentRunOptions as e, type AgentOutput as f, type AgentInstance as g, type AgentSpawnTemplate as h, type InterceptorChainConfig as i, type InterceptorContext as j, type InterceptorResult as k, isSkipSentinel as l, skip as s };
@@ -1,4 +1,4 @@
1
- import { Participant, ModeConfig, Toolpack } from 'toolpack-sdk';
1
+ import { Participant, ModeConfig, ToolpackInitConfig, Toolpack } from 'toolpack-sdk';
2
2
  import { EventEmitter } from 'events';
3
3
 
4
4
  /**
@@ -110,16 +110,14 @@ interface InterceptorChainConfig {
110
110
  /**
111
111
  * Options for constructing a BaseAgent.
112
112
  *
113
- * - `{ apiKey, provider?, model? }` — agent creates and owns its own Toolpack instance.
113
+ * - `ToolpackInitConfig` — agent creates and owns its own Toolpack instance using
114
+ * the supplied config. Accepts everything `Toolpack.init()` accepts: `apiKey`,
115
+ * `provider`, `model`, `customTools`, `tools`, `knowledge`, `customModes`, etc.
114
116
  * The instance is initialised lazily in `start()`.
115
117
  * - `{ toolpack }` — agent uses a shared Toolpack instance (e.g. passed from AgentRegistry
116
- * for multi-agent setups where API client and config are shared).
118
+ * for multi-agent setups where the API client and config are shared).
117
119
  */
118
- type BaseAgentOptions = {
119
- apiKey: string;
120
- provider?: string;
121
- model?: string;
122
- } | {
120
+ type BaseAgentOptions = ToolpackInitConfig | {
123
121
  toolpack: Toolpack;
124
122
  };
125
123
  /**
@@ -152,6 +150,53 @@ interface AgentDelegationConfig {
152
150
  */
153
151
  mode?: 'await' | 'forget';
154
152
  }
153
+ /**
154
+ * Definition of a single spawnable agent template.
155
+ * Templates are config objects — no subclassing required.
156
+ * The SDK instantiates an EphemeralAgent from this at spawn time.
157
+ */
158
+ interface AgentSpawnTemplate {
159
+ /** Unique name for this template; use `'self'` as a reserved name for self-replication. */
160
+ name: string;
161
+ /** Human-readable purpose shown to the LLM so it can pick the right template. */
162
+ description: string;
163
+ /**
164
+ * Factory that receives the task string and returns the system prompt for the
165
+ * spawned agent. Called once per spawn invocation.
166
+ */
167
+ systemPrompt: (task: string) => string;
168
+ /** Model override for spawned agents of this template. Inherits parent model when omitted. */
169
+ model?: string;
170
+ /**
171
+ * Allow the LLM to append extra instructions to this template's system prompt
172
+ * via the `systemPromptAddition` tool parameter. Defaults to `false`.
173
+ * Only enable this for templates where LLM-driven prompt customisation is safe.
174
+ */
175
+ allowPromptAddition?: boolean;
176
+ }
177
+ /**
178
+ * Configuration for AI-driven dynamic agent spawning.
179
+ * When enabled, a `spawn_agent` tool is injected into every `run()` call so
180
+ * the LLM can instantiate a one-off helper agent, get its result, and continue.
181
+ * Spawned agents are ephemeral: no channels, no registry entry, discarded after use.
182
+ */
183
+ interface AgentSpawnConfig {
184
+ /** Must be true for the spawn tool to be injected. */
185
+ enabled: boolean;
186
+ /**
187
+ * List of agent templates available for spawning.
188
+ * The LLM sees each template's name and description to decide which to use.
189
+ * Add a template with `name: 'self'` to opt in to self-replication — without
190
+ * it, the `spawn_agent` tool will not advertise or accept `"self"` as a target.
191
+ */
192
+ templates: AgentSpawnTemplate[];
193
+ /**
194
+ * Maximum recursive spawn depth (default: 3).
195
+ * When a spawned agent reaches this depth, the spawn tool is not injected —
196
+ * stopping the chain without throwing an error.
197
+ */
198
+ maxDepth?: number;
199
+ }
155
200
  /**
156
201
  * Input structure for agent invocation.
157
202
  * Channels normalize external events into this format.
@@ -427,6 +472,15 @@ interface IAgentRegistry {
427
472
  * @returns Number of asks cleaned up
428
473
  */
429
474
  cleanupExpiredAsks(): number;
475
+ /** Returns true when all registered agents have no in-progress conversations. */
476
+ isAllIdle?(): boolean;
477
+ /**
478
+ * Schedule a graceful restart once all agents become idle, or after maxWaitMinutes
479
+ * (default 30) if idle is never reached. Idempotent — subsequent calls are no-ops.
480
+ */
481
+ scheduleRestart?(options?: {
482
+ maxWaitMinutes?: number;
483
+ }): void;
430
484
  }
431
485
 
432
- export { type AgentInput as A, type BaseAgentOptions as B, type ChannelInterface as C, type Interceptor as I, type NextFunction as N, type PendingAsk as P, SKIP_SENTINEL as S, type WorkflowStep as W, type AgentResult as a, type AgentDelegationConfig as b, type IAgentRegistry as c, type AgentRunOptions as d, type AgentOutput as e, type AgentInstance as f, type InterceptorChainConfig as g, type InterceptorContext as h, type InterceptorResult as i, isSkipSentinel as j, skip as s };
486
+ export { type AgentInput as A, type BaseAgentOptions as B, type ChannelInterface as C, type Interceptor as I, type NextFunction as N, type PendingAsk as P, SKIP_SENTINEL as S, type WorkflowStep as W, type AgentResult as a, type AgentDelegationConfig as b, type AgentSpawnConfig as c, type IAgentRegistry as d, type AgentRunOptions as e, type AgentOutput as f, type AgentInstance as g, type AgentSpawnTemplate as h, type InterceptorChainConfig as i, type InterceptorContext as j, type InterceptorResult as k, isSkipSentinel as l, skip as s };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toolpack-sdk/agents",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "Production AI agents for Toolpack SDK — 8 channel integrations (Slack, Discord, Telegram, SMS, Email, Webhook, Scheduled, MCP), AgentMind persistent cognitive layer (goals, beliefs, reflections), interceptors, evals, and multi-agent coordination",
5
5
  "engines": {
6
6
  "node": ">=20"
@@ -89,11 +89,11 @@
89
89
  },
90
90
  "peerDependencies": {
91
91
  "@opentelemetry/api": "^1.x",
92
- "@toolpack-sdk/knowledge": "^2.2.0",
92
+ "@toolpack-sdk/knowledge": "^2.4.0",
93
93
  "better-sqlite3": "^12.6.2",
94
94
  "discord.js": "^14.x",
95
95
  "nodemailer": "^6.x",
96
- "toolpack-sdk": "^2.2.0",
96
+ "toolpack-sdk": "^2.4.0",
97
97
  "twilio": "^5.x"
98
98
  },
99
99
  "peerDependenciesMeta": {