@lleverage-ai/agent-sdk 0.0.3 → 0.0.4
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 +87 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +441 -36
- package/dist/agent.js.map +1 -1
- package/dist/hooks.d.ts +28 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +40 -0
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/apply.d.ts.map +1 -1
- package/dist/middleware/apply.js +8 -0
- package/dist/middleware/apply.js.map +1 -1
- package/dist/middleware/context.d.ts.map +1 -1
- package/dist/middleware/context.js +11 -0
- package/dist/middleware/context.js.map +1 -1
- package/dist/middleware/types.d.ts +8 -0
- package/dist/middleware/types.d.ts.map +1 -1
- package/dist/plugins/agent-teams/coordinator.d.ts +46 -0
- package/dist/plugins/agent-teams/coordinator.d.ts.map +1 -0
- package/dist/plugins/agent-teams/coordinator.js +255 -0
- package/dist/plugins/agent-teams/coordinator.js.map +1 -0
- package/dist/plugins/agent-teams/hooks.d.ts +29 -0
- package/dist/plugins/agent-teams/hooks.d.ts.map +1 -0
- package/dist/plugins/agent-teams/hooks.js +29 -0
- package/dist/plugins/agent-teams/hooks.js.map +1 -0
- package/dist/plugins/agent-teams/index.d.ts +59 -0
- package/dist/plugins/agent-teams/index.d.ts.map +1 -0
- package/dist/plugins/agent-teams/index.js +313 -0
- package/dist/plugins/agent-teams/index.js.map +1 -0
- package/dist/plugins/agent-teams/mermaid.d.ts +32 -0
- package/dist/plugins/agent-teams/mermaid.d.ts.map +1 -0
- package/dist/plugins/agent-teams/mermaid.js +66 -0
- package/dist/plugins/agent-teams/mermaid.js.map +1 -0
- package/dist/plugins/agent-teams/session-runner.d.ts +92 -0
- package/dist/plugins/agent-teams/session-runner.d.ts.map +1 -0
- package/dist/plugins/agent-teams/session-runner.js +166 -0
- package/dist/plugins/agent-teams/session-runner.js.map +1 -0
- package/dist/plugins/agent-teams/tools.d.ts +41 -0
- package/dist/plugins/agent-teams/tools.d.ts.map +1 -0
- package/dist/plugins/agent-teams/tools.js +289 -0
- package/dist/plugins/agent-teams/tools.js.map +1 -0
- package/dist/plugins/agent-teams/types.d.ts +164 -0
- package/dist/plugins/agent-teams/types.d.ts.map +1 -0
- package/dist/plugins/agent-teams/types.js +7 -0
- package/dist/plugins/agent-teams/types.js.map +1 -0
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +1 -0
- package/dist/plugins.js.map +1 -1
- package/dist/presets/production.d.ts.map +1 -1
- package/dist/presets/production.js +7 -7
- package/dist/presets/production.js.map +1 -1
- package/dist/task-manager.d.ts +15 -0
- package/dist/task-manager.d.ts.map +1 -1
- package/dist/task-manager.js +36 -0
- package/dist/task-manager.js.map +1 -1
- package/dist/testing/mock-agent.d.ts.map +1 -1
- package/dist/testing/mock-agent.js +6 -0
- package/dist/testing/mock-agent.js.map +1 -1
- package/dist/testing/recorder.d.ts.map +1 -1
- package/dist/testing/recorder.js +6 -0
- package/dist/testing/recorder.js.map +1 -1
- package/dist/tools/task.d.ts.map +1 -1
- package/dist/tools/task.js +6 -2
- package/dist/tools/task.js.map +1 -1
- package/dist/types.d.ts +103 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -242,9 +242,96 @@ const agent = createAgent({
|
|
|
242
242
|
- `PreGenerate`, `PostGenerate`, `PostGenerateFailure` — Generation lifecycle
|
|
243
243
|
- `PreToolUse`, `PostToolUse`, `PostToolUseFailure` — Tool execution lifecycle
|
|
244
244
|
- `MCPConnectionFailed`, `MCPConnectionRestored` — MCP server connection lifecycle
|
|
245
|
+
- `Custom` — Plugin-defined custom events (see below)
|
|
245
246
|
|
|
246
247
|
**Hook utilities:** `createRetryHooks`, `createRateLimitHooks`, `createLoggingHooks`, `createGuardrailsHooks`, `createSecretsFilterHooks`, `createToolHook`
|
|
247
248
|
|
|
249
|
+
**Plugin hooks:** Plugins can define hooks in their configuration, which are automatically merged into the agent's hook registration:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
const myPlugin = definePlugin({
|
|
253
|
+
name: "my-plugin",
|
|
254
|
+
tools: { /* ... */ },
|
|
255
|
+
hooks: {
|
|
256
|
+
PostToolUse: [async ({ tool_name }) => {
|
|
257
|
+
console.log("Tool used:", tool_name);
|
|
258
|
+
}],
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Custom hooks:** Plugins can define their own lifecycle events via `Custom` hooks and `invokeCustomHook()`:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { invokeCustomHook, TEAM_HOOKS } from "@lleverage-ai/agent-sdk";
|
|
267
|
+
|
|
268
|
+
// Subscribe to custom events
|
|
269
|
+
const agent = createAgent({
|
|
270
|
+
model,
|
|
271
|
+
hooks: {
|
|
272
|
+
Custom: {
|
|
273
|
+
[TEAM_HOOKS.TeammateSpawned]: [async (input) => {
|
|
274
|
+
console.log("Teammate spawned:", input.payload);
|
|
275
|
+
}],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Background Tasks
|
|
282
|
+
|
|
283
|
+
Background tasks (bash commands and subagents) are automatically handled. When `generate()`, `stream()`, `streamResponse()`, or `streamDataResponse()` spawns a background task, the agent waits for completion and triggers follow-up generations to process results.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
const agent = createAgent({
|
|
287
|
+
model,
|
|
288
|
+
subagents: [researcherSubagent],
|
|
289
|
+
|
|
290
|
+
// These are the defaults:
|
|
291
|
+
waitForBackgroundTasks: true,
|
|
292
|
+
|
|
293
|
+
// Customize follow-up prompt formatting
|
|
294
|
+
formatTaskCompletion: (task) => `Task ${task.id} done: ${task.result}`,
|
|
295
|
+
formatTaskFailure: (task) => `Task ${task.id} failed: ${task.error}`,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// generate() returns only after all background tasks are processed
|
|
299
|
+
const result = await agent.generate({ prompt: "Research this in the background" });
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Agent Teams
|
|
303
|
+
|
|
304
|
+
Multi-agent coordination where the primary agent becomes a team lead:
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import {
|
|
308
|
+
createAgent,
|
|
309
|
+
createAgentTeamsPlugin,
|
|
310
|
+
InMemoryTeamCoordinator,
|
|
311
|
+
} from "@lleverage-ai/agent-sdk";
|
|
312
|
+
|
|
313
|
+
const teamsPlugin = createAgentTeamsPlugin({
|
|
314
|
+
teammates: [
|
|
315
|
+
{
|
|
316
|
+
id: "researcher",
|
|
317
|
+
name: "Researcher",
|
|
318
|
+
description: "Researches topics",
|
|
319
|
+
create: ({ model }) => createAgent({ model, systemPrompt: "You research topics." }),
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
coordinator: new InMemoryTeamCoordinator(),
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const agent = createAgent({
|
|
326
|
+
model,
|
|
327
|
+
plugins: [teamsPlugin],
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
The agent gets a `start_team` tool. When called, it gains team management tools (`team_spawn`, `team_message`, `team_task_create`, etc.) at runtime. Teammates run in background sessions and communicate via mailboxes.
|
|
332
|
+
|
|
333
|
+
See [Subagents & Teams](./docs/subagents.md) for full details.
|
|
334
|
+
|
|
248
335
|
### Streaming
|
|
249
336
|
|
|
250
337
|
Agents support streaming responses for real-time output:
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA2DH,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EAyBb,MAAM,YAAY,CAAC;AA6pBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,CA2jFxD"}
|