@lleverage-ai/agent-sdk 0.0.2 → 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 +141 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +528 -41
- 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 +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -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/prompt-builder/components.d.ts +149 -0
- package/dist/prompt-builder/components.d.ts.map +1 -0
- package/dist/prompt-builder/components.js +252 -0
- package/dist/prompt-builder/components.js.map +1 -0
- package/dist/prompt-builder/index.d.ts +248 -0
- package/dist/prompt-builder/index.d.ts.map +1 -0
- package/dist/prompt-builder/index.js +165 -0
- package/dist/prompt-builder/index.js.map +1 -0
- 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 +178 -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
|
@@ -160,6 +160,59 @@ const agent = createAgent({ model, skills });
|
|
|
160
160
|
|
|
161
161
|
See [Skills Documentation](./docs/skills.md) for complete details on the skills system and Agent Skills spec compliance.
|
|
162
162
|
|
|
163
|
+
### Prompt Builder
|
|
164
|
+
|
|
165
|
+
Create dynamic, context-aware system prompts from composable components. Instead of static strings, prompts automatically include tools, skills, backend capabilities, and more.
|
|
166
|
+
|
|
167
|
+
**Using the default builder:**
|
|
168
|
+
```typescript
|
|
169
|
+
const agent = createAgent({
|
|
170
|
+
model,
|
|
171
|
+
// No systemPrompt = uses default prompt builder
|
|
172
|
+
tools: { read, write, bash },
|
|
173
|
+
});
|
|
174
|
+
// Automatically generates:
|
|
175
|
+
// "You are a helpful AI assistant.
|
|
176
|
+
//
|
|
177
|
+
// # Available Tools
|
|
178
|
+
// - **read**: Read files
|
|
179
|
+
// - **write**: Write files
|
|
180
|
+
// - **bash**: Execute commands
|
|
181
|
+
//
|
|
182
|
+
// # Capabilities
|
|
183
|
+
// - Execute shell commands (bash)
|
|
184
|
+
// - Read and write files to the filesystem"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Customizing the prompt:**
|
|
188
|
+
```typescript
|
|
189
|
+
import { createDefaultPromptBuilder } from "@lleverage-ai/agent-sdk";
|
|
190
|
+
|
|
191
|
+
const builder = createDefaultPromptBuilder()
|
|
192
|
+
.register({
|
|
193
|
+
name: "project-context",
|
|
194
|
+
priority: 95,
|
|
195
|
+
render: () => "You are working on a TypeScript project.",
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const agent = createAgent({
|
|
199
|
+
model,
|
|
200
|
+
promptBuilder: builder,
|
|
201
|
+
tools,
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Static prompts still work:**
|
|
206
|
+
```typescript
|
|
207
|
+
const agent = createAgent({
|
|
208
|
+
model,
|
|
209
|
+
systemPrompt: "You are a helpful assistant.",
|
|
210
|
+
tools,
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
See [Prompt Builder Documentation](./docs/prompt-builder.md) for complete details on dynamic prompts, components, and customization.
|
|
215
|
+
|
|
163
216
|
### Hooks
|
|
164
217
|
|
|
165
218
|
Hooks allow you to observe and react to agent lifecycle events:
|
|
@@ -189,9 +242,96 @@ const agent = createAgent({
|
|
|
189
242
|
- `PreGenerate`, `PostGenerate`, `PostGenerateFailure` — Generation lifecycle
|
|
190
243
|
- `PreToolUse`, `PostToolUse`, `PostToolUseFailure` — Tool execution lifecycle
|
|
191
244
|
- `MCPConnectionFailed`, `MCPConnectionRestored` — MCP server connection lifecycle
|
|
245
|
+
- `Custom` — Plugin-defined custom events (see below)
|
|
192
246
|
|
|
193
247
|
**Hook utilities:** `createRetryHooks`, `createRateLimitHooks`, `createLoggingHooks`, `createGuardrailsHooks`, `createSecretsFilterHooks`, `createToolHook`
|
|
194
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
|
+
|
|
195
335
|
### Streaming
|
|
196
336
|
|
|
197
337
|
Agents support streaming responses for real-time output:
|
|
@@ -212,6 +352,7 @@ export async function POST(req: Request) {
|
|
|
212
352
|
|
|
213
353
|
## Documentation
|
|
214
354
|
|
|
355
|
+
- [Prompt Builder](./docs/prompt-builder.md) — Dynamic, context-aware system prompts
|
|
215
356
|
- [Skills System](./docs/skills.md) — Progressive disclosure with Agent Skills spec compliance
|
|
216
357
|
- [Tool Loading Strategies](./docs/tool-loading.md) — Eager, lazy, and dynamic tool loading
|
|
217
358
|
- [Security & Production](./docs/security.md) — Security policies, guardrails, and secrets filtering
|
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"}
|