agent-lattice 0.9.13 → 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 +48 -1
- package/dist/index.d.ts +40 -35
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -227,6 +227,53 @@ const result = await agent.prompt("What is 2+2?");
|
|
|
227
227
|
console.log(result.result);
|
|
228
228
|
```
|
|
229
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
|
+
|
|
230
277
|
## Permission Callback
|
|
231
278
|
|
|
232
279
|
```ts
|
|
@@ -361,7 +408,7 @@ const mcp = await connectMCPStreamableHTTPServer("https://mcp.example.com/mcp",
|
|
|
361
408
|
`Agent` and `Team` satisfy the same `AgentLike` shape:
|
|
362
409
|
|
|
363
410
|
```ts
|
|
364
|
-
type AgentLike = {
|
|
411
|
+
type AgentLike<TContext = unknown> = {
|
|
365
412
|
query(prompt, options?): AsyncGenerator<SDKMessage | TeamRunnerMessage>;
|
|
366
413
|
prompt(prompt, options?): Promise<SDKResultMessage>;
|
|
367
414
|
};
|
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,23 +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
|
};
|
|
368
|
-
export type BareAgentOptions = Omit<AgentOptions
|
|
370
|
+
export type BareAgentOptions<TContext = unknown> = Omit<AgentOptions<TContext>, "workspace">;
|
|
369
371
|
export type AgentWorkspaceToolsOptions = {
|
|
370
372
|
cwd?: string;
|
|
371
373
|
allowedDirectories?: string[];
|
|
372
374
|
bashTimeoutMs?: number;
|
|
373
375
|
};
|
|
374
|
-
export type QueryOptions = {
|
|
376
|
+
export type QueryOptions<TContext = unknown> = {
|
|
375
377
|
stream?: boolean;
|
|
376
378
|
signal?: AbortSignal;
|
|
377
|
-
|
|
379
|
+
context?: TContext;
|
|
380
|
+
agentRuntime?: AgentRuntimeContext;
|
|
378
381
|
permissions?: RuntimePermissions;
|
|
379
382
|
tracer?: ContextTracer;
|
|
380
383
|
};
|
|
@@ -454,7 +457,8 @@ export declare class ToolPermissionDeniedError extends AgentSDKError {
|
|
|
454
457
|
readonly denial: PermissionDenial;
|
|
455
458
|
constructor(denial: PermissionDenial);
|
|
456
459
|
}
|
|
457
|
-
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>;
|
|
458
462
|
export type DelegateToolOptions = {
|
|
459
463
|
wait?: DelegateWaitMode;
|
|
460
464
|
targetMailboxId?: string;
|
|
@@ -484,13 +488,13 @@ export type AgentToolOptions = {
|
|
|
484
488
|
description: string;
|
|
485
489
|
targetMailboxId?: string;
|
|
486
490
|
};
|
|
487
|
-
export declare function agentTool(name: string, agent: AgentLike
|
|
488
|
-
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<{
|
|
489
493
|
task: string;
|
|
490
494
|
}>;
|
|
491
|
-
export declare function createAgent(options: AgentOptions): Agent
|
|
492
|
-
export declare function createBareAgent(options: BareAgentOptions): Agent
|
|
493
|
-
export declare function createBuiltinTools(options?: AgentWorkspaceToolsOptions): Array<ToolDefinition<any>>;
|
|
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>>;
|
|
494
498
|
export declare function createJsonlContextTracer(options: JsonlContextTracerOptions): ContextTracer;
|
|
495
499
|
export declare function createCompositeContextTracer(tracers: Array<ContextTracer | undefined | null>): ContextTracer;
|
|
496
500
|
export declare function createLangSmithContextTracer(options: LangSmithContextTracerOptions): ContextTracer;
|
|
@@ -504,21 +508,22 @@ export declare function createMemoryMailbox(): TeamMailbox;
|
|
|
504
508
|
export declare function createSQLiteMailbox(options: SQLiteMailboxOptions): TeamMailbox;
|
|
505
509
|
export declare function createTeam(options: TeamOptions): Team;
|
|
506
510
|
export declare function createTeamRunner(options: TeamRunnerOptions): TeamRunner;
|
|
507
|
-
export declare function createAgentWorkspaceTools(options?: AgentWorkspaceToolsOptions): Array<ToolDefinition<any>>;
|
|
508
|
-
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> & {
|
|
509
513
|
prompt: string;
|
|
510
514
|
stream?: boolean;
|
|
511
515
|
signal?: AbortSignal;
|
|
516
|
+
context?: TContext;
|
|
512
517
|
}): AsyncGenerator<SDKMessage>;
|
|
513
|
-
export declare class Agent {
|
|
518
|
+
export declare class Agent<TContext = unknown> {
|
|
514
519
|
private readonly options;
|
|
515
520
|
private readonly modelClient;
|
|
516
521
|
private readonly messages;
|
|
517
522
|
private readonly sessionId;
|
|
518
|
-
constructor(options: AgentOptions);
|
|
519
|
-
query(prompt: string | ContentBlock[], options?: QueryOptions): AsyncGenerator<SDKMessage>;
|
|
520
|
-
prompt(prompt: string | ContentBlock[], options?: QueryOptions): Promise<SDKResultMessage>;
|
|
521
|
-
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;
|
|
522
527
|
private initMessage;
|
|
523
528
|
private resultMessage;
|
|
524
529
|
private modelTools;
|