agent-lattice 0.9.12 → 0.9.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 +82 -11
- package/dist/index.d.ts +40 -32
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,6 +31,25 @@ for await (const message of agent.query("Say hello")) {
|
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
`createAgent()` includes a private workspace and the built-in file/shell tools
|
|
35
|
+
by default. Use `createBareAgent()` when your host wants to provide every prompt
|
|
36
|
+
and tool explicitly:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { createBareAgent, createBuiltinTools } from "agent-lattice";
|
|
40
|
+
|
|
41
|
+
const agent = createBareAgent({
|
|
42
|
+
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
43
|
+
baseURL: "https://api.deepseek.com/anthropic",
|
|
44
|
+
model: "deepseek-v4-flash",
|
|
45
|
+
systemPrompt: "You are a concise engineering assistant.",
|
|
46
|
+
tools: createBuiltinTools({
|
|
47
|
+
cwd: process.cwd(),
|
|
48
|
+
allowedDirectories: [process.cwd()],
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
34
53
|
Pass `{ stream: false }` to disable model streaming for a query:
|
|
35
54
|
|
|
36
55
|
```ts
|
|
@@ -208,6 +227,53 @@ const result = await agent.prompt("What is 2+2?");
|
|
|
208
227
|
console.log(result.result);
|
|
209
228
|
```
|
|
210
229
|
|
|
230
|
+
## Business Context For Tools
|
|
231
|
+
|
|
232
|
+
Pass host application data through `context`. The SDK gives that context to
|
|
233
|
+
tool handlers, but does not automatically put it into the model transcript. The
|
|
234
|
+
model sees the data only if a tool returns it.
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import { createBareAgent, tool } from "agent-lattice";
|
|
238
|
+
import { z } from "zod/v4";
|
|
239
|
+
|
|
240
|
+
type QcContext = {
|
|
241
|
+
patientRecordId: string;
|
|
242
|
+
scoringStandardId: string;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const readPatientRecordInput = z.object({});
|
|
246
|
+
const qcTool = tool<QcContext>();
|
|
247
|
+
|
|
248
|
+
const readPatientRecord = qcTool(
|
|
249
|
+
"read_patient_record",
|
|
250
|
+
"Read the current patient record",
|
|
251
|
+
readPatientRecordInput,
|
|
252
|
+
async (_input, { context }) => {
|
|
253
|
+
return {
|
|
254
|
+
content: JSON.stringify({
|
|
255
|
+
patientRecordId: context?.patientRecordId,
|
|
256
|
+
scoringStandardId: context?.scoringStandardId,
|
|
257
|
+
}),
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const agent = createBareAgent<QcContext>({
|
|
263
|
+
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
264
|
+
baseURL: "https://api.deepseek.com/anthropic",
|
|
265
|
+
model: "deepseek-v4-flash",
|
|
266
|
+
tools: [readPatientRecord],
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const result = await agent.prompt("Review the current patient record.", {
|
|
270
|
+
context: {
|
|
271
|
+
patientRecordId: "ocr_123",
|
|
272
|
+
scoringStandardId: "tumor-treatment-process-v1",
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
211
277
|
## Permission Callback
|
|
212
278
|
|
|
213
279
|
```ts
|
|
@@ -342,7 +408,7 @@ const mcp = await connectMCPStreamableHTTPServer("https://mcp.example.com/mcp",
|
|
|
342
408
|
`Agent` and `Team` satisfy the same `AgentLike` shape:
|
|
343
409
|
|
|
344
410
|
```ts
|
|
345
|
-
type AgentLike = {
|
|
411
|
+
type AgentLike<TContext = unknown> = {
|
|
346
412
|
query(prompt, options?): AsyncGenerator<SDKMessage | TeamRunnerMessage>;
|
|
347
413
|
prompt(prompt, options?): Promise<SDKResultMessage>;
|
|
348
414
|
};
|
|
@@ -596,7 +662,8 @@ sends a diagnostic follow-up to the upstream mailbox.
|
|
|
596
662
|
|
|
597
663
|
## Agent Workspace Tools
|
|
598
664
|
|
|
599
|
-
|
|
665
|
+
`createAgent()` includes a private workspace and these built-in tools by
|
|
666
|
+
default:
|
|
600
667
|
|
|
601
668
|
- `Read`
|
|
602
669
|
- `Write`
|
|
@@ -606,14 +673,18 @@ AgentLattice includes an opt-in set of workspace tools:
|
|
|
606
673
|
- `Grep`
|
|
607
674
|
- `Bash`
|
|
608
675
|
|
|
676
|
+
Use `createBuiltinTools()` or `createAgentWorkspaceTools()` when you want to
|
|
677
|
+
assemble the tool list yourself, especially with `createBareAgent()`:
|
|
678
|
+
|
|
609
679
|
```ts
|
|
610
|
-
import {
|
|
680
|
+
import { createBareAgent, createBuiltinTools } from "agent-lattice";
|
|
611
681
|
|
|
612
|
-
const agent =
|
|
682
|
+
const agent = createBareAgent({
|
|
613
683
|
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
614
684
|
baseURL: "https://api.deepseek.com/anthropic",
|
|
615
685
|
model: "deepseek-v4-flash",
|
|
616
|
-
|
|
686
|
+
systemPrompt: "Use the configured project directory for file work.",
|
|
687
|
+
tools: createBuiltinTools({
|
|
617
688
|
cwd: process.cwd(),
|
|
618
689
|
allowedDirectories: [process.cwd()],
|
|
619
690
|
}),
|
|
@@ -626,12 +697,12 @@ const agent = createAgent({
|
|
|
626
697
|
});
|
|
627
698
|
```
|
|
628
699
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
700
|
+
`Read`, `LS`, `Glob`, and `Grep` are read-only observation tools and are not
|
|
701
|
+
gated by workspace grants. `Write`, `Edit`, and obvious Bash writes are gated to
|
|
702
|
+
the configured workspace roots and task-scoped shared workspace grants, so
|
|
703
|
+
production hosts should pair write and shell access with a permission callback.
|
|
704
|
+
Shell redirects to `/dev/null` are treated as discard targets, not workspace
|
|
705
|
+
writes.
|
|
635
706
|
|
|
636
707
|
## Multi-turn Session
|
|
637
708
|
|
package/dist/index.d.ts
CHANGED
|
@@ -21,9 +21,9 @@ export type ToolResultBlock = {
|
|
|
21
21
|
};
|
|
22
22
|
export type ContentBlock = TextBlock | ImageBlock | DocumentBlock | ToolUseBlock | ToolResultBlock;
|
|
23
23
|
export type AgentLikeEvent = SDKMessage | TeamRunnerMessage;
|
|
24
|
-
export type AgentLike = {
|
|
25
|
-
query(prompt: string | ContentBlock[], options?: QueryOptions): AsyncGenerator<AgentLikeEvent>;
|
|
26
|
-
prompt(prompt: string | ContentBlock[], options?: QueryOptions): Promise<SDKResultMessage>;
|
|
24
|
+
export type AgentLike<TContext = unknown> = {
|
|
25
|
+
query(prompt: string | ContentBlock[], options?: QueryOptions<TContext>): AsyncGenerator<AgentLikeEvent>;
|
|
26
|
+
prompt(prompt: string | ContentBlock[], options?: QueryOptions<TContext>): Promise<SDKResultMessage>;
|
|
27
27
|
};
|
|
28
28
|
export type DelegateWaitMode = "result" | "accepted";
|
|
29
29
|
export type AgentRuntimeSource = {
|
|
@@ -36,7 +36,7 @@ export type AgentRuntimeSource = {
|
|
|
36
36
|
export type AgentRuntimeDelegateInput = {
|
|
37
37
|
name: string;
|
|
38
38
|
description?: string;
|
|
39
|
-
agent: AgentLike
|
|
39
|
+
agent: AgentLike<any>;
|
|
40
40
|
task: string;
|
|
41
41
|
wait?: DelegateWaitMode;
|
|
42
42
|
targetMailboxId?: string;
|
|
@@ -158,19 +158,21 @@ export interface ModelClient {
|
|
|
158
158
|
export type ToolResult = {
|
|
159
159
|
content: string | ContentBlock[];
|
|
160
160
|
};
|
|
161
|
-
export type
|
|
161
|
+
export type ToolExecutionContext<TContext = unknown> = {
|
|
162
162
|
signal?: AbortSignal;
|
|
163
163
|
toolUseId: string;
|
|
164
|
-
|
|
164
|
+
context?: TContext;
|
|
165
|
+
agentRuntime?: AgentRuntimeContext;
|
|
165
166
|
permissions?: RuntimePermissions;
|
|
166
|
-
}
|
|
167
|
-
export type
|
|
167
|
+
};
|
|
168
|
+
export type ToolHandler<TInput = unknown, TContext = unknown> = (input: TInput, context: ToolExecutionContext<TContext>) => Promise<ToolResult> | ToolResult;
|
|
169
|
+
export type ToolDefinition<TInput = unknown, TContext = unknown> = {
|
|
168
170
|
name: string;
|
|
169
171
|
description: string;
|
|
170
172
|
inputSchema: unknown;
|
|
171
173
|
jsonSchema: Record<string, unknown>;
|
|
172
174
|
parse(input: unknown): TInput;
|
|
173
|
-
handler: ToolHandler<TInput>;
|
|
175
|
+
handler: ToolHandler<TInput, TContext>;
|
|
174
176
|
};
|
|
175
177
|
export type SkillDefinition = {
|
|
176
178
|
name: string;
|
|
@@ -220,7 +222,7 @@ export type MCPStdioServerOptions = MCPToolsOptions & {
|
|
|
220
222
|
};
|
|
221
223
|
export type MCPStdioConnection = {
|
|
222
224
|
client: MCPClient;
|
|
223
|
-
tools: Array<ToolDefinition<any>>;
|
|
225
|
+
tools: Array<ToolDefinition<any, any>>;
|
|
224
226
|
close(): Promise<void>;
|
|
225
227
|
};
|
|
226
228
|
export type MCPStreamableHTTPServerOptions = MCPToolsOptions & {
|
|
@@ -242,7 +244,7 @@ export type TeamMemberDefinition = {
|
|
|
242
244
|
name: string;
|
|
243
245
|
role: TeamMemberRole;
|
|
244
246
|
focus?: string;
|
|
245
|
-
agent: AgentLike
|
|
247
|
+
agent: AgentLike<any>;
|
|
246
248
|
mailboxId?: string;
|
|
247
249
|
};
|
|
248
250
|
export type TeamMemberInput = TeamMemberDefinition;
|
|
@@ -294,18 +296,18 @@ export type SQLiteMailboxOptions = {
|
|
|
294
296
|
};
|
|
295
297
|
export type TeamOptions = {
|
|
296
298
|
name: string;
|
|
297
|
-
lead: Agent
|
|
299
|
+
lead: Agent<any>;
|
|
298
300
|
members: TeamMemberDefinition[];
|
|
299
301
|
mailbox?: TeamMailbox;
|
|
300
302
|
exposeLeadMailboxTools?: boolean;
|
|
301
303
|
};
|
|
302
304
|
export type Team = {
|
|
303
305
|
name: string;
|
|
304
|
-
lead: Agent
|
|
306
|
+
lead: Agent<any>;
|
|
305
307
|
members: TeamMemberDefinition[];
|
|
306
308
|
mailbox: TeamMailbox;
|
|
307
|
-
tools: Array<ToolDefinition<any>>;
|
|
308
|
-
memberTools: Record<string, Array<ToolDefinition<any>>>;
|
|
309
|
+
tools: Array<ToolDefinition<any, any>>;
|
|
310
|
+
memberTools: Record<string, Array<ToolDefinition<any, any>>>;
|
|
309
311
|
send(from: string, to: string, content: string, options?: TeamSendOptions): Promise<TeamMessage>;
|
|
310
312
|
drain(options?: TeamDrainOptions): Promise<TeamDrainResult>;
|
|
311
313
|
query(prompt: string | ContentBlock[], options?: QueryOptions): AsyncGenerator<TeamRunnerMessage>;
|
|
@@ -323,13 +325,13 @@ export type TeamDrainResult = {
|
|
|
323
325
|
};
|
|
324
326
|
export type TeamRunnerOptions = {
|
|
325
327
|
team?: Team;
|
|
326
|
-
root?: AgentLike
|
|
328
|
+
root?: AgentLike<any>;
|
|
327
329
|
mailbox?: TeamMailbox;
|
|
328
330
|
source?: AgentRuntimeSource;
|
|
329
331
|
maxDelegateDepth?: number;
|
|
330
332
|
};
|
|
331
333
|
export type TeamRunner = {
|
|
332
|
-
root: AgentLike
|
|
334
|
+
root: AgentLike<any>;
|
|
333
335
|
mailbox: TeamMailbox;
|
|
334
336
|
query(prompt: string | ContentBlock[], options?: QueryOptions): AsyncGenerator<TeamRunnerMessage>;
|
|
335
337
|
prompt(prompt: string | ContentBlock[], options?: QueryOptions): Promise<SDKResultMessage>;
|
|
@@ -350,7 +352,7 @@ export type AgentWorkspaceOptions = string | {
|
|
|
350
352
|
allowedDirectories?: string[];
|
|
351
353
|
bashTimeoutMs?: number;
|
|
352
354
|
};
|
|
353
|
-
export type AgentOptions = {
|
|
355
|
+
export type AgentOptions<TContext = unknown> = {
|
|
354
356
|
apiKey?: string;
|
|
355
357
|
baseURL?: string;
|
|
356
358
|
name?: string;
|
|
@@ -358,22 +360,24 @@ export type AgentOptions = {
|
|
|
358
360
|
systemPrompt?: string;
|
|
359
361
|
maxTokens?: number;
|
|
360
362
|
maxTurns?: number;
|
|
361
|
-
tools?: Array<ToolDefinition<any>>;
|
|
363
|
+
tools?: Array<ToolDefinition<any, TContext>>;
|
|
362
364
|
skills?: SkillDefinition[];
|
|
363
365
|
workspace?: AgentWorkspaceOptions;
|
|
364
366
|
permission?: (request: PermissionRequest) => Promise<PermissionDecision> | PermissionDecision;
|
|
365
367
|
modelClient?: ModelClient;
|
|
366
368
|
tracer?: ContextTracer;
|
|
367
369
|
};
|
|
370
|
+
export type BareAgentOptions<TContext = unknown> = Omit<AgentOptions<TContext>, "workspace">;
|
|
368
371
|
export type AgentWorkspaceToolsOptions = {
|
|
369
372
|
cwd?: string;
|
|
370
373
|
allowedDirectories?: string[];
|
|
371
374
|
bashTimeoutMs?: number;
|
|
372
375
|
};
|
|
373
|
-
export type QueryOptions = {
|
|
376
|
+
export type QueryOptions<TContext = unknown> = {
|
|
374
377
|
stream?: boolean;
|
|
375
378
|
signal?: AbortSignal;
|
|
376
|
-
|
|
379
|
+
context?: TContext;
|
|
380
|
+
agentRuntime?: AgentRuntimeContext;
|
|
377
381
|
permissions?: RuntimePermissions;
|
|
378
382
|
tracer?: ContextTracer;
|
|
379
383
|
};
|
|
@@ -453,7 +457,8 @@ export declare class ToolPermissionDeniedError extends AgentSDKError {
|
|
|
453
457
|
readonly denial: PermissionDenial;
|
|
454
458
|
constructor(denial: PermissionDenial);
|
|
455
459
|
}
|
|
456
|
-
export declare function tool<TSchema>(name: string, description: string, inputSchema: TSchema, handler: ToolHandler<InferInput<TSchema
|
|
460
|
+
export declare function tool<TContext = unknown>(): <TSchema>(name: string, description: string, inputSchema: TSchema, handler: ToolHandler<InferInput<TSchema>, TContext>) => ToolDefinition<InferInput<TSchema>, TContext>;
|
|
461
|
+
export declare function tool<TSchema, TContext = unknown>(name: string, description: string, inputSchema: TSchema, handler: ToolHandler<InferInput<TSchema>, TContext>): ToolDefinition<InferInput<TSchema>, TContext>;
|
|
457
462
|
export type DelegateToolOptions = {
|
|
458
463
|
wait?: DelegateWaitMode;
|
|
459
464
|
targetMailboxId?: string;
|
|
@@ -483,11 +488,13 @@ export type AgentToolOptions = {
|
|
|
483
488
|
description: string;
|
|
484
489
|
targetMailboxId?: string;
|
|
485
490
|
};
|
|
486
|
-
export declare function agentTool(name: string, agent: AgentLike
|
|
487
|
-
export declare function delegateTool(name: string, description: string, agent: AgentLike
|
|
491
|
+
export declare function agentTool(name: string, agent: AgentLike<any>, options: AgentToolOptions): ToolDefinition<AgentToolInput>;
|
|
492
|
+
export declare function delegateTool(name: string, description: string, agent: AgentLike<any>, options?: DelegateToolOptions): ToolDefinition<{
|
|
488
493
|
task: string;
|
|
489
494
|
}>;
|
|
490
|
-
export declare function createAgent(options: AgentOptions): Agent
|
|
495
|
+
export declare function createAgent<TContext = unknown>(options: AgentOptions<TContext>): Agent<TContext>;
|
|
496
|
+
export declare function createBareAgent<TContext = unknown>(options: BareAgentOptions<TContext>): Agent<TContext>;
|
|
497
|
+
export declare function createBuiltinTools(options?: AgentWorkspaceToolsOptions): Array<ToolDefinition<any, any>>;
|
|
491
498
|
export declare function createJsonlContextTracer(options: JsonlContextTracerOptions): ContextTracer;
|
|
492
499
|
export declare function createCompositeContextTracer(tracers: Array<ContextTracer | undefined | null>): ContextTracer;
|
|
493
500
|
export declare function createLangSmithContextTracer(options: LangSmithContextTracerOptions): ContextTracer;
|
|
@@ -501,21 +508,22 @@ export declare function createMemoryMailbox(): TeamMailbox;
|
|
|
501
508
|
export declare function createSQLiteMailbox(options: SQLiteMailboxOptions): TeamMailbox;
|
|
502
509
|
export declare function createTeam(options: TeamOptions): Team;
|
|
503
510
|
export declare function createTeamRunner(options: TeamRunnerOptions): TeamRunner;
|
|
504
|
-
export declare function createAgentWorkspaceTools(options?: AgentWorkspaceToolsOptions): Array<ToolDefinition<any>>;
|
|
505
|
-
export declare function query(params: AgentOptions & {
|
|
511
|
+
export declare function createAgentWorkspaceTools(options?: AgentWorkspaceToolsOptions): Array<ToolDefinition<any, any>>;
|
|
512
|
+
export declare function query<TContext = unknown>(params: AgentOptions<TContext> & {
|
|
506
513
|
prompt: string;
|
|
507
514
|
stream?: boolean;
|
|
508
515
|
signal?: AbortSignal;
|
|
516
|
+
context?: TContext;
|
|
509
517
|
}): AsyncGenerator<SDKMessage>;
|
|
510
|
-
export declare class Agent {
|
|
518
|
+
export declare class Agent<TContext = unknown> {
|
|
511
519
|
private readonly options;
|
|
512
520
|
private readonly modelClient;
|
|
513
521
|
private readonly messages;
|
|
514
522
|
private readonly sessionId;
|
|
515
|
-
constructor(options: AgentOptions);
|
|
516
|
-
query(prompt: string | ContentBlock[], options?: QueryOptions): AsyncGenerator<SDKMessage>;
|
|
517
|
-
prompt(prompt: string | ContentBlock[], options?: QueryOptions): Promise<SDKResultMessage>;
|
|
518
|
-
addTools(tools: Array<ToolDefinition<any>>): void;
|
|
523
|
+
constructor(options: AgentOptions<TContext>);
|
|
524
|
+
query(prompt: string | ContentBlock[], options?: QueryOptions<TContext>): AsyncGenerator<SDKMessage>;
|
|
525
|
+
prompt(prompt: string | ContentBlock[], options?: QueryOptions<TContext>): Promise<SDKResultMessage>;
|
|
526
|
+
addTools(tools: Array<ToolDefinition<any, TContext>>): void;
|
|
519
527
|
private initMessage;
|
|
520
528
|
private resultMessage;
|
|
521
529
|
private modelTools;
|