@lleverage-ai/agent-sdk 0.0.13 → 0.0.14

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 DELETED
@@ -1,373 +0,0 @@
1
- # @lleverage-ai/agent-sdk
2
-
3
- A TypeScript framework for building AI agents using the Vercel AI SDK v6.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- bun add @lleverage-ai/agent-sdk ai zod
9
- ```
10
-
11
- You'll also need at least one AI provider:
12
-
13
- ```bash
14
- bun add @ai-sdk/anthropic # or @ai-sdk/openai
15
- ```
16
-
17
- ## Quick Start
18
-
19
- ```typescript
20
- import { createAgent } from "@lleverage-ai/agent-sdk";
21
- import { anthropic } from "@ai-sdk/anthropic";
22
- import { tool } from "ai";
23
- import { z } from "zod";
24
-
25
- const agent = createAgent({
26
- model: anthropic("claude-sonnet-4-20250514"),
27
- systemPrompt: "You are a friendly assistant.",
28
- tools: {
29
- greet: tool({
30
- description: "Greet a person by name",
31
- inputSchema: z.object({
32
- name: z.string().describe("The name of the person to greet"),
33
- }),
34
- execute: async ({ name }) => `Hello, ${name}!`,
35
- }),
36
- },
37
- });
38
-
39
- const result = await agent.generate({
40
- prompt: "Say hello to Alice",
41
- });
42
-
43
- console.log(result.text);
44
- ```
45
-
46
- ## Core Concepts
47
-
48
- ### Agents
49
-
50
- Agents combine a language model with tools, plugins, and hooks. Core tools for filesystem operations and task tracking are automatically included.
51
-
52
- ```typescript
53
- const agent = createAgent({
54
- model: anthropic("claude-sonnet-4-20250514"),
55
- systemPrompt: "You are a helpful assistant.",
56
- maxSteps: 10,
57
- tools: { /* custom tools */ },
58
- plugins: [ /* plugins */ ],
59
- });
60
-
61
- // Disable specific core tools if needed
62
- const safeAgent = createAgent({
63
- model,
64
- disabledCoreTools: ["bash", "write"],
65
- });
66
- ```
67
-
68
- **Core tools included:** `read`, `write`, `edit`, `glob`, `grep`, `todo_write`, `bash` (requires backend with `enableBash: true`), `skill` (when skills are configured), `search_tools` (when enabled), `call_tool` (proxy mode only)
69
-
70
- ### Tools
71
-
72
- Tools use the AI SDK's `tool()` function with `inputSchema`:
73
-
74
- ```typescript
75
- import { tool } from "ai";
76
- import { z } from "zod";
77
-
78
- const calculator = tool({
79
- description: "Perform basic math operations",
80
- inputSchema: z.object({
81
- operation: z.enum(["add", "subtract", "multiply", "divide"]),
82
- a: z.number(),
83
- b: z.number(),
84
- }),
85
- execute: async ({ operation, a, b }) => {
86
- switch (operation) {
87
- case "add": return a + b;
88
- case "subtract": return a - b;
89
- case "multiply": return a * b;
90
- case "divide": return a / b;
91
- }
92
- },
93
- });
94
-
95
- const agent = createAgent({
96
- model,
97
- tools: { calculator },
98
- });
99
- ```
100
-
101
- ### Plugins
102
-
103
- Plugins bundle tools, skills, and hooks. Plugin tools are exposed with MCP naming: `mcp__<plugin>__<tool>`.
104
-
105
- ```typescript
106
- import { definePlugin } from "@lleverage-ai/agent-sdk";
107
-
108
- const myPlugin = definePlugin({
109
- name: "my-plugin",
110
- description: "A collection of useful tools",
111
- tools: {
112
- myTool: tool({
113
- description: "Does something useful",
114
- inputSchema: z.object({ input: z.string() }),
115
- execute: async ({ input }) => `Result: ${input}`,
116
- }),
117
- },
118
- });
119
-
120
- const agent = createAgent({
121
- model,
122
- plugins: [myPlugin],
123
- });
124
- // Plugin tool available as: mcp__my-plugin__myTool
125
- ```
126
-
127
- ### Skills
128
-
129
- Skills provide contextual instructions that guide agent behavior following the [Agent Skills specification](https://agentskills.io/specification). They support both programmatic (TypeScript) and file-based (SKILL.md) formats.
130
-
131
- **Programmatic skills:**
132
- ```typescript
133
- import { defineSkill } from "@lleverage-ai/agent-sdk";
134
-
135
- const dataPlugin = definePlugin({
136
- name: "data-explorer",
137
- tools: { getSchema, queryData, createChart },
138
- skills: [
139
- defineSkill({
140
- name: "data-exploration",
141
- description: "Query and visualize data",
142
- instructions: `You have access to data exploration tools.
143
- Available tables: products, users, sales.
144
- Always use getSchema first to see column types.`,
145
- }),
146
- ],
147
- });
148
- ```
149
-
150
- **File-based skills:**
151
- ```typescript
152
- import { loadSkillsFromDirectories } from "@lleverage-ai/agent-sdk";
153
-
154
- // Load skills from SKILL.md files
155
- const { skills } = await loadSkillsFromDirectories(["/path/to/skills"]);
156
-
157
- // Agent auto-creates registry and skill tool
158
- const agent = createAgent({ model, skills });
159
- ```
160
-
161
- See [Skills Documentation](./docs/skills.md) for complete details on the skills system and Agent Skills spec compliance.
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
- The default prompt builder is cache-friendly: it avoids per-turn dynamic context sections by default so repeated generations in the same thread can reuse provider prompt caches more effectively.
168
-
169
- **Using the default builder:**
170
- ```typescript
171
- const agent = createAgent({
172
- model,
173
- // No systemPrompt = uses default prompt builder
174
- tools: { read, write, bash },
175
- });
176
- // Automatically generates:
177
- // "You are a helpful AI assistant.
178
- //
179
- // # Available Tools
180
- // - **read**: Read files
181
- // - **write**: Write files
182
- // - **bash**: Execute commands
183
- //
184
- // # Capabilities
185
- // - Execute shell commands (bash)
186
- // - Read and write files to the filesystem"
187
- ```
188
-
189
- **Customizing the prompt:**
190
- ```typescript
191
- import { createDefaultPromptBuilder } from "@lleverage-ai/agent-sdk";
192
-
193
- const builder = createDefaultPromptBuilder()
194
- .register({
195
- name: "project-context",
196
- priority: 95,
197
- render: () => "You are working on a TypeScript project.",
198
- });
199
-
200
- const agent = createAgent({
201
- model,
202
- promptBuilder: builder,
203
- tools,
204
- });
205
- ```
206
-
207
- **Static prompts still work:**
208
- ```typescript
209
- const agent = createAgent({
210
- model,
211
- systemPrompt: "You are a helpful assistant.",
212
- tools,
213
- });
214
- ```
215
-
216
- See [Prompt Builder Documentation](./docs/prompt-builder.md) for complete details on dynamic prompts, components, and customization.
217
-
218
- ### Hooks
219
-
220
- Hooks allow you to observe and react to agent lifecycle events:
221
-
222
- ```typescript
223
- import { createAgent, createToolHook } from "@lleverage-ai/agent-sdk";
224
-
225
- const agent = createAgent({
226
- model,
227
- hooks: {
228
- // Simple observation hook (void return is fine)
229
- PreGenerate: [async ({ options }) => {
230
- console.log("Starting generation...");
231
- }],
232
-
233
- // Use createToolHook helper for tool-specific hooks
234
- PostToolUse: [
235
- createToolHook(async ({ tool_name, tool_response }) => {
236
- console.log("Tool completed:", tool_name);
237
- }, { matcher: "search_*" }), // Only match tools starting with "search_"
238
- ],
239
- },
240
- });
241
- ```
242
-
243
- **Available hooks:**
244
- - `PreGenerate`, `PostGenerate`, `PostGenerateFailure` — Generation lifecycle
245
- - `PreToolUse`, `PostToolUse`, `PostToolUseFailure` — Tool execution lifecycle
246
- - `MCPConnectionFailed`, `MCPConnectionRestored` — MCP server connection lifecycle
247
- - `Custom` — Plugin-defined custom events (see below)
248
-
249
- **Hook utilities:** `createRetryHooks`, `createRateLimitHooks`, `createLoggingHooks`, `createGuardrailsHooks`, `createSecretsFilterHooks`, `createToolHook`
250
-
251
- **Plugin hooks:** Plugins can define hooks in their configuration, which are automatically merged into the agent's hook registration:
252
-
253
- ```typescript
254
- const myPlugin = definePlugin({
255
- name: "my-plugin",
256
- tools: { /* ... */ },
257
- hooks: {
258
- PostToolUse: [async ({ tool_name }) => {
259
- console.log("Tool used:", tool_name);
260
- }],
261
- },
262
- });
263
- ```
264
-
265
- **Custom hooks:** Plugins can define their own lifecycle events via `Custom` hooks and `invokeCustomHook()`:
266
-
267
- ```typescript
268
- import { invokeCustomHook, TEAM_HOOKS } from "@lleverage-ai/agent-sdk";
269
-
270
- // Subscribe to custom events
271
- const agent = createAgent({
272
- model,
273
- hooks: {
274
- Custom: {
275
- [TEAM_HOOKS.TeammateSpawned]: [async (input) => {
276
- console.log("Teammate spawned:", input.payload);
277
- }],
278
- },
279
- },
280
- });
281
- ```
282
-
283
- ### Background Tasks
284
-
285
- 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.
286
-
287
- ```typescript
288
- const agent = createAgent({
289
- model,
290
- subagents: [researcherSubagent],
291
-
292
- // These are the defaults:
293
- waitForBackgroundTasks: true,
294
-
295
- // Customize follow-up prompt formatting
296
- formatTaskCompletion: (task) => `Task ${task.id} done: ${task.result}`,
297
- formatTaskFailure: (task) => `Task ${task.id} failed: ${task.error}`,
298
- });
299
-
300
- // generate() returns only after all background tasks are processed
301
- const result = await agent.generate({ prompt: "Research this in the background" });
302
- ```
303
-
304
- ### Agent Teams
305
-
306
- Multi-agent coordination where the primary agent becomes a team lead:
307
-
308
- ```typescript
309
- import {
310
- createAgent,
311
- createAgentTeamsPlugin,
312
- InMemoryTeamCoordinator,
313
- } from "@lleverage-ai/agent-sdk";
314
-
315
- const teamsPlugin = createAgentTeamsPlugin({
316
- teammates: [
317
- {
318
- id: "researcher",
319
- name: "Researcher",
320
- description: "Researches topics",
321
- create: ({ model }) => createAgent({ model, systemPrompt: "You research topics." }),
322
- },
323
- ],
324
- coordinator: new InMemoryTeamCoordinator(),
325
- });
326
-
327
- const agent = createAgent({
328
- model,
329
- plugins: [teamsPlugin],
330
- });
331
- ```
332
-
333
- 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.
334
-
335
- See [Subagents & Teams](./docs/subagents.md) for full details.
336
-
337
- ### Streaming
338
-
339
- Agents support streaming responses for real-time output:
340
-
341
- ```typescript
342
- for await (const part of agent.stream({ prompt: "Tell me a story" })) {
343
- if (part.type === "text-delta") {
344
- process.stdout.write(part.text);
345
- }
346
- }
347
-
348
- // Next.js API route
349
- export async function POST(req: Request) {
350
- const { messages } = await req.json();
351
- return agent.streamResponse({ messages });
352
- }
353
- ```
354
-
355
- ## Documentation
356
-
357
- - [Prompt Builder](./docs/prompt-builder.md) — Dynamic, context-aware system prompts
358
- - [Skills System](./docs/skills.md) — Progressive disclosure with Agent Skills spec compliance
359
- - [Tool Loading Strategies](./docs/tool-loading.md) — Eager, deferred discovery, and proxy tool loading
360
- - [Security & Production](./docs/security.md) — Security policies, guardrails, and secrets filtering
361
- - [Subagents](./docs/subagents.md) — Task delegation and background tasks
362
- - [MCP Integration](./docs/mcp.md) — Model Context Protocol tools and servers
363
- - [Backends](./docs/backends.md) — Filesystem and execution backends
364
- - [Middleware](./docs/middleware.md) — Logging, caching, retry, and guardrails
365
- - [Observability](./docs/observability.md) — Logging, metrics, and tracing
366
- - [Persistence](./docs/persistence.md) — Memory and checkpointing
367
- - [Context Compaction](./docs/context-compaction.md) — Automatic context management
368
- - [Error Handling](./docs/errors.md) — Typed errors and recovery
369
- - [API Reference](./docs/api-reference.md) — Complete API documentation
370
-
371
- ## License
372
-
373
- MIT