@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.
Files changed (71) hide show
  1. package/README.md +87 -0
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +441 -36
  4. package/dist/agent.js.map +1 -1
  5. package/dist/hooks.d.ts +28 -1
  6. package/dist/hooks.d.ts.map +1 -1
  7. package/dist/hooks.js +40 -0
  8. package/dist/hooks.js.map +1 -1
  9. package/dist/index.d.ts +4 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/middleware/apply.d.ts.map +1 -1
  14. package/dist/middleware/apply.js +8 -0
  15. package/dist/middleware/apply.js.map +1 -1
  16. package/dist/middleware/context.d.ts.map +1 -1
  17. package/dist/middleware/context.js +11 -0
  18. package/dist/middleware/context.js.map +1 -1
  19. package/dist/middleware/types.d.ts +8 -0
  20. package/dist/middleware/types.d.ts.map +1 -1
  21. package/dist/plugins/agent-teams/coordinator.d.ts +46 -0
  22. package/dist/plugins/agent-teams/coordinator.d.ts.map +1 -0
  23. package/dist/plugins/agent-teams/coordinator.js +255 -0
  24. package/dist/plugins/agent-teams/coordinator.js.map +1 -0
  25. package/dist/plugins/agent-teams/hooks.d.ts +29 -0
  26. package/dist/plugins/agent-teams/hooks.d.ts.map +1 -0
  27. package/dist/plugins/agent-teams/hooks.js +29 -0
  28. package/dist/plugins/agent-teams/hooks.js.map +1 -0
  29. package/dist/plugins/agent-teams/index.d.ts +59 -0
  30. package/dist/plugins/agent-teams/index.d.ts.map +1 -0
  31. package/dist/plugins/agent-teams/index.js +313 -0
  32. package/dist/plugins/agent-teams/index.js.map +1 -0
  33. package/dist/plugins/agent-teams/mermaid.d.ts +32 -0
  34. package/dist/plugins/agent-teams/mermaid.d.ts.map +1 -0
  35. package/dist/plugins/agent-teams/mermaid.js +66 -0
  36. package/dist/plugins/agent-teams/mermaid.js.map +1 -0
  37. package/dist/plugins/agent-teams/session-runner.d.ts +92 -0
  38. package/dist/plugins/agent-teams/session-runner.d.ts.map +1 -0
  39. package/dist/plugins/agent-teams/session-runner.js +166 -0
  40. package/dist/plugins/agent-teams/session-runner.js.map +1 -0
  41. package/dist/plugins/agent-teams/tools.d.ts +41 -0
  42. package/dist/plugins/agent-teams/tools.d.ts.map +1 -0
  43. package/dist/plugins/agent-teams/tools.js +289 -0
  44. package/dist/plugins/agent-teams/tools.js.map +1 -0
  45. package/dist/plugins/agent-teams/types.d.ts +164 -0
  46. package/dist/plugins/agent-teams/types.d.ts.map +1 -0
  47. package/dist/plugins/agent-teams/types.js +7 -0
  48. package/dist/plugins/agent-teams/types.js.map +1 -0
  49. package/dist/plugins.d.ts.map +1 -1
  50. package/dist/plugins.js +1 -0
  51. package/dist/plugins.js.map +1 -1
  52. package/dist/presets/production.d.ts.map +1 -1
  53. package/dist/presets/production.js +7 -7
  54. package/dist/presets/production.js.map +1 -1
  55. package/dist/task-manager.d.ts +15 -0
  56. package/dist/task-manager.d.ts.map +1 -1
  57. package/dist/task-manager.js +36 -0
  58. package/dist/task-manager.js.map +1 -1
  59. package/dist/testing/mock-agent.d.ts.map +1 -1
  60. package/dist/testing/mock-agent.js +6 -0
  61. package/dist/testing/mock-agent.js.map +1 -1
  62. package/dist/testing/recorder.d.ts.map +1 -1
  63. package/dist/testing/recorder.js +6 -0
  64. package/dist/testing/recorder.js.map +1 -1
  65. package/dist/tools/task.d.ts.map +1 -1
  66. package/dist/tools/task.js +6 -2
  67. package/dist/tools/task.js.map +1 -1
  68. package/dist/types.d.ts +103 -3
  69. package/dist/types.d.ts.map +1 -1
  70. package/dist/types.js.map +1 -1
  71. 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:
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0DH,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EAyBb,MAAM,YAAY,CAAC;AA8lBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,CAgoExD"}
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"}