@looopy-ai/core 2.1.8 → 2.1.11
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/dist/core/agent.d.ts +4 -8
- package/dist/core/agent.js +3 -5
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/iteration.d.ts +3 -3
- package/dist/core/iteration.js +33 -34
- package/dist/core/loop.d.ts +3 -3
- package/dist/core/tools.d.ts +1 -1
- package/dist/core/tools.js +26 -19
- package/dist/events/utils.d.ts +19 -53
- package/dist/events/utils.js +0 -34
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/observability/spans/iteration.d.ts +1 -1
- package/dist/observability/spans/llm-call.d.ts +5 -5
- package/dist/observability/spans/llm-call.js +8 -4
- package/dist/observability/spans/tool.d.ts +3 -3
- package/dist/plugins/agent-academy.d.ts +9 -0
- package/dist/plugins/agent-academy.js +137 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/system-prompt.d.ts +3 -0
- package/dist/plugins/system-prompt.js +20 -0
- package/dist/providers/litellm-provider.d.ts +3 -2
- package/dist/providers/litellm-provider.js +11 -9
- package/dist/stores/artifacts/internal-event-artifact-store.d.ts +2 -2
- package/dist/stores/artifacts/internal-event-artifact-store.js +0 -6
- package/dist/stores/filesystem/filesystem-message-store.d.ts +5 -5
- package/dist/stores/messages/hybrid-message-store.d.ts +7 -7
- package/dist/stores/messages/interfaces.d.ts +8 -8
- package/dist/stores/messages/mem0-message-store.d.ts +5 -5
- package/dist/stores/messages/memory-message-store.d.ts +5 -5
- package/dist/tools/agent-tool-provider.d.ts +5 -5
- package/dist/tools/agent-tool-provider.js +14 -10
- package/dist/tools/artifact-tools.d.ts +2 -2
- package/dist/tools/artifact-tools.js +14 -14
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +0 -1
- package/dist/tools/local-tools.d.ts +4 -3
- package/dist/tools/local-tools.js +8 -8
- package/dist/tools/mcp-tool-provider.d.ts +5 -4
- package/dist/tools/mcp-tool-provider.js +7 -7
- package/dist/tools/tool-result-events.d.ts +3 -4
- package/dist/tools/tool-result-events.js +2 -8
- package/dist/types/a2a.d.ts +2 -2
- package/dist/types/agent.d.ts +1 -1
- package/dist/types/core.d.ts +56 -0
- package/dist/types/core.js +8 -0
- package/dist/types/event.d.ts +6 -5
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/llm.d.ts +3 -3
- package/dist/types/message.d.ts +5 -5
- package/dist/types/prettify.d.ts +3 -0
- package/dist/types/state.d.ts +2 -2
- package/dist/types/tools.d.ts +3 -12
- package/dist/types/tools.js +2 -2
- package/dist/utils/prompt.d.ts +5 -7
- package/dist/utils/prompt.js +12 -10
- package/package.json +5 -3
- package/dist/core/types.d.ts +0 -31
- package/dist/skills/index.d.ts +0 -1
- package/dist/skills/index.js +0 -1
- package/dist/skills/registry.d.ts +0 -14
- package/dist/skills/registry.js +0 -61
- package/dist/tools/client-tool-provider.d.ts +0 -25
- package/dist/tools/client-tool-provider.js +0 -143
- /package/dist/{core/types.js → types/prettify.js} +0 -0
|
@@ -14,7 +14,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
14
14
|
const scheduledStore = new ArtifactScheduler(artifactStore);
|
|
15
15
|
return localTools([
|
|
16
16
|
tool({
|
|
17
|
-
|
|
17
|
+
id: 'create_file_artifact',
|
|
18
18
|
description: 'Create a new file artifact for streaming text or binary content. Use append_file_chunk to add content. Set override=true to replace existing artifact.',
|
|
19
19
|
schema: z.object({
|
|
20
20
|
artifactId: z
|
|
@@ -64,7 +64,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
64
64
|
},
|
|
65
65
|
}),
|
|
66
66
|
tool({
|
|
67
|
-
|
|
67
|
+
id: 'append_file_chunk',
|
|
68
68
|
description: 'Append a chunk of content to a file artifact. Call multiple times to stream content.',
|
|
69
69
|
schema: z.object({
|
|
70
70
|
artifactId: z.string().describe('The artifact ID to append to'),
|
|
@@ -93,7 +93,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
93
93
|
},
|
|
94
94
|
}),
|
|
95
95
|
tool({
|
|
96
|
-
|
|
96
|
+
id: 'get_file_content',
|
|
97
97
|
description: 'Get the complete content of a file artifact',
|
|
98
98
|
schema: z.object({
|
|
99
99
|
artifactId: z.string().describe('The artifact ID to retrieve'),
|
|
@@ -110,7 +110,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
110
110
|
},
|
|
111
111
|
}),
|
|
112
112
|
tool({
|
|
113
|
-
|
|
113
|
+
id: 'create_data_artifact',
|
|
114
114
|
description: 'Create a data artifact with structured JSON data. Set override=true to replace existing artifact.',
|
|
115
115
|
schema: z.object({
|
|
116
116
|
artifactId: z.string().describe('Unique identifier for the artifact'),
|
|
@@ -148,7 +148,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
148
148
|
},
|
|
149
149
|
}),
|
|
150
150
|
tool({
|
|
151
|
-
|
|
151
|
+
id: 'update_data_artifact',
|
|
152
152
|
description: 'Update the data content of an existing data artifact',
|
|
153
153
|
schema: z.object({
|
|
154
154
|
artifactId: z.string().describe('The artifact ID to update'),
|
|
@@ -168,7 +168,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
168
168
|
},
|
|
169
169
|
}),
|
|
170
170
|
tool({
|
|
171
|
-
|
|
171
|
+
id: 'get_data_content',
|
|
172
172
|
description: 'Get the content of a data artifact',
|
|
173
173
|
schema: z.object({
|
|
174
174
|
artifactId: z.string().describe('The artifact ID to retrieve'),
|
|
@@ -185,7 +185,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
185
185
|
},
|
|
186
186
|
}),
|
|
187
187
|
tool({
|
|
188
|
-
|
|
188
|
+
id: 'get_data_artifact',
|
|
189
189
|
description: 'Get the data content of a data artifact',
|
|
190
190
|
schema: z.object({
|
|
191
191
|
artifactId: z.string().describe('The artifact ID to retrieve'),
|
|
@@ -202,7 +202,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
202
202
|
},
|
|
203
203
|
}),
|
|
204
204
|
tool({
|
|
205
|
-
|
|
205
|
+
id: 'create_dataset_artifact',
|
|
206
206
|
description: 'Create a dataset artifact for tabular data with a schema. Set override=true to replace existing artifact.',
|
|
207
207
|
schema: z.object({
|
|
208
208
|
artifactId: z.string().describe('Unique identifier for the dataset'),
|
|
@@ -246,7 +246,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
246
246
|
},
|
|
247
247
|
}),
|
|
248
248
|
tool({
|
|
249
|
-
|
|
249
|
+
id: 'append_dataset_row',
|
|
250
250
|
description: 'Append a single row to a dataset artifact',
|
|
251
251
|
schema: z.object({
|
|
252
252
|
artifactId: z.string().describe('The dataset artifact ID'),
|
|
@@ -265,7 +265,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
265
265
|
},
|
|
266
266
|
}),
|
|
267
267
|
tool({
|
|
268
|
-
|
|
268
|
+
id: 'append_dataset_rows',
|
|
269
269
|
description: 'Append multiple rows to a dataset artifact',
|
|
270
270
|
schema: z.object({
|
|
271
271
|
artifactId: z.string().describe('The dataset artifact ID'),
|
|
@@ -287,7 +287,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
287
287
|
},
|
|
288
288
|
}),
|
|
289
289
|
tool({
|
|
290
|
-
|
|
290
|
+
id: 'get_dataset_rows',
|
|
291
291
|
description: 'Get all rows from a dataset artifact',
|
|
292
292
|
schema: z.object({
|
|
293
293
|
artifactId: z.string().describe('The dataset artifact ID'),
|
|
@@ -305,7 +305,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
305
305
|
},
|
|
306
306
|
}),
|
|
307
307
|
tool({
|
|
308
|
-
|
|
308
|
+
id: 'list_artifacts',
|
|
309
309
|
description: 'List all artifacts in the current context, optionally filtered by task',
|
|
310
310
|
schema: z.object({
|
|
311
311
|
taskId: z.string().optional().describe('Filter artifacts by task ID'),
|
|
@@ -331,7 +331,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
331
331
|
},
|
|
332
332
|
}),
|
|
333
333
|
tool({
|
|
334
|
-
|
|
334
|
+
id: 'get_artifact',
|
|
335
335
|
description: 'Get metadata for a specific artifact by ID',
|
|
336
336
|
schema: z.object({
|
|
337
337
|
artifactId: z.string().describe('The artifact ID to retrieve'),
|
|
@@ -368,7 +368,7 @@ export function createArtifactTools(artifactStore, taskStateStore) {
|
|
|
368
368
|
},
|
|
369
369
|
}),
|
|
370
370
|
tool({
|
|
371
|
-
|
|
371
|
+
id: 'delete_artifact',
|
|
372
372
|
description: 'Delete an artifact by ID',
|
|
373
373
|
schema: z.object({
|
|
374
374
|
artifactId: z.string().describe('The artifact ID to delete'),
|
package/dist/tools/index.d.ts
CHANGED
package/dist/tools/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { ExecutionContext } from '../types/context';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Plugin } from '../types/core';
|
|
4
|
+
import type { ToolResult } from '../types/tools';
|
|
4
5
|
type InternalToolResult = Omit<ToolResult, 'toolCallId' | 'toolName'>;
|
|
5
6
|
export type ToolHandler<TParams, AuthContext> = (params: TParams, context: ExecutionContext<AuthContext>) => Promise<InternalToolResult> | InternalToolResult;
|
|
6
7
|
export interface LocalToolDefinition<TSchema extends z.ZodObject, AuthContext> {
|
|
7
|
-
|
|
8
|
+
id: string;
|
|
8
9
|
description: string;
|
|
9
10
|
icon?: string;
|
|
10
11
|
schema: TSchema;
|
|
11
12
|
handler: ToolHandler<z.infer<TSchema>, AuthContext>;
|
|
12
13
|
}
|
|
13
14
|
export declare function tool<TSchema extends z.ZodObject, AuthContext>(definition: LocalToolDefinition<TSchema, AuthContext>): LocalToolDefinition<TSchema, AuthContext>;
|
|
14
|
-
export declare function localTools<AuthContext>(tools: LocalToolDefinition<z.ZodObject, AuthContext>[]):
|
|
15
|
+
export declare function localTools<AuthContext>(tools: LocalToolDefinition<z.ZodObject, AuthContext>[]): Plugin<AuthContext>;
|
|
15
16
|
export {};
|
|
@@ -15,15 +15,15 @@ const zodToJsonSchema = (schema) => {
|
|
|
15
15
|
export function localTools(tools) {
|
|
16
16
|
const toolMap = new Map();
|
|
17
17
|
for (const tool of tools) {
|
|
18
|
-
if (toolMap.has(tool.
|
|
19
|
-
throw new Error(`Duplicate tool name: ${tool.
|
|
18
|
+
if (toolMap.has(tool.id)) {
|
|
19
|
+
throw new Error(`Duplicate tool name: ${tool.id}`);
|
|
20
20
|
}
|
|
21
|
-
toolMap.set(tool.
|
|
21
|
+
toolMap.set(tool.id, tool);
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
name: 'local-tool-provider',
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
listTools: async () => tools.map((t) => ({
|
|
26
|
+
id: t.id,
|
|
27
27
|
description: t.description,
|
|
28
28
|
icon: t.icon,
|
|
29
29
|
parameters: zodToJsonSchema(t.schema),
|
|
@@ -34,13 +34,13 @@ export function localTools(tools) {
|
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
36
|
return {
|
|
37
|
-
|
|
37
|
+
id: toolDef.id,
|
|
38
38
|
description: toolDef.description,
|
|
39
39
|
icon: toolDef.icon,
|
|
40
40
|
parameters: zodToJsonSchema(toolDef.schema),
|
|
41
41
|
};
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
executeTool: (toolCall, context) => defer(async () => {
|
|
44
44
|
const toolDef = toolMap.get(toolCall.function.name);
|
|
45
45
|
if (!toolDef) {
|
|
46
46
|
return {
|
|
@@ -82,6 +82,6 @@ export function localTools(tools) {
|
|
|
82
82
|
error: err.message,
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
}).pipe(mergeMap((result) => toolResultToEvents(
|
|
85
|
+
}).pipe(mergeMap((result) => toolResultToEvents(result)), catchError((error) => of(toolErrorEvent(toolCall, error instanceof Error ? error.message : String(error))))),
|
|
86
86
|
};
|
|
87
87
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from '..';
|
|
1
2
|
import type { ExecutionContext } from '../types/context';
|
|
2
|
-
import type { ToolCall, ToolDefinition
|
|
3
|
+
import type { ToolCall, ToolDefinition } from '../types/tools';
|
|
3
4
|
export interface MCPProviderConfig<AuthContext> {
|
|
4
5
|
serverId: string;
|
|
5
6
|
serverUrl: string;
|
|
@@ -7,7 +8,7 @@ export interface MCPProviderConfig<AuthContext> {
|
|
|
7
8
|
getHeaders: (authContext?: AuthContext) => Record<string, string>;
|
|
8
9
|
}
|
|
9
10
|
export declare const mcp: <AuthContext>(config: MCPProviderConfig<AuthContext>) => McpToolProvider<AuthContext>;
|
|
10
|
-
export declare class McpToolProvider<AuthContext> implements
|
|
11
|
+
export declare class McpToolProvider<AuthContext> implements Plugin<AuthContext> {
|
|
11
12
|
name: string;
|
|
12
13
|
readonly id: string;
|
|
13
14
|
private readonly client;
|
|
@@ -17,7 +18,7 @@ export declare class McpToolProvider<AuthContext> implements ToolProvider<AuthCo
|
|
|
17
18
|
private ongoingRequest;
|
|
18
19
|
constructor(config: MCPProviderConfig<AuthContext>);
|
|
19
20
|
getTool(toolName: string): Promise<ToolDefinition | undefined>;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
listTools(): Promise<ToolDefinition[]>;
|
|
22
|
+
executeTool(toolCall: ToolCall, context: ExecutionContext<AuthContext>): import("rxjs").Observable<import("..").AnyEvent>;
|
|
22
23
|
private convertMCPTool;
|
|
23
24
|
}
|
|
@@ -21,10 +21,10 @@ export class McpToolProvider {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
async getTool(toolName) {
|
|
24
|
-
const tools = await this.
|
|
25
|
-
return tools.find((tool) => tool.
|
|
24
|
+
const tools = await this.listTools();
|
|
25
|
+
return tools.find((tool) => tool.id === toolName);
|
|
26
26
|
}
|
|
27
|
-
async
|
|
27
|
+
async listTools() {
|
|
28
28
|
if (this.toolCache.size > 0 && this.cacheExpiry && Date.now() < this.cacheExpiry) {
|
|
29
29
|
return Array.from(this.toolCache.values());
|
|
30
30
|
}
|
|
@@ -37,7 +37,7 @@ export class McpToolProvider {
|
|
|
37
37
|
const toolDefs = tools.map(this.convertMCPTool);
|
|
38
38
|
this.toolCache.clear();
|
|
39
39
|
for (const tool of toolDefs) {
|
|
40
|
-
this.toolCache.set(tool.
|
|
40
|
+
this.toolCache.set(tool.id, tool);
|
|
41
41
|
}
|
|
42
42
|
this.cacheExpiry = Date.now() + this.cacheTTL;
|
|
43
43
|
return toolDefs;
|
|
@@ -47,7 +47,7 @@ export class McpToolProvider {
|
|
|
47
47
|
});
|
|
48
48
|
return this.ongoingRequest;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
executeTool(toolCall, context) {
|
|
51
51
|
return defer(async () => {
|
|
52
52
|
const { name, arguments: args } = toolCall.function;
|
|
53
53
|
if (typeof args !== 'object' || args === null) {
|
|
@@ -80,11 +80,11 @@ export class McpToolProvider {
|
|
|
80
80
|
result: null,
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
}).pipe(mergeMap((result) => toolResultToEvents(
|
|
83
|
+
}).pipe(mergeMap((result) => toolResultToEvents(result)), catchError((error) => of(toolErrorEvent(toolCall, error instanceof Error ? error.message : String(error)))));
|
|
84
84
|
}
|
|
85
85
|
convertMCPTool = (mcpTool) => {
|
|
86
86
|
return {
|
|
87
|
-
|
|
87
|
+
id: mcpTool.name,
|
|
88
88
|
description: mcpTool.description,
|
|
89
89
|
parameters: mcpTool.inputSchema,
|
|
90
90
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type Observable } from 'rxjs';
|
|
2
|
-
import type {
|
|
3
|
-
import type { ContextAnyEvent, ContextEvent, ToolCompleteEvent } from '../types/event';
|
|
2
|
+
import type { AnyEvent, ToolCompleteEvent } from '../types/event';
|
|
4
3
|
import type { ToolCall, ToolResult } from '../types/tools';
|
|
5
|
-
export declare const toolErrorEvent:
|
|
6
|
-
export declare const toolResultToEvents:
|
|
4
|
+
export declare const toolErrorEvent: (toolCall: ToolCall, errorMessage: string) => ToolCompleteEvent;
|
|
5
|
+
export declare const toolResultToEvents: (result: ToolResult) => Observable<AnyEvent>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { concat, EMPTY, from, of } from 'rxjs';
|
|
2
|
-
export const toolErrorEvent = (
|
|
2
|
+
export const toolErrorEvent = (toolCall, errorMessage) => ({
|
|
3
3
|
kind: 'tool-complete',
|
|
4
|
-
contextId: context.contextId,
|
|
5
|
-
taskId: context.taskId,
|
|
6
4
|
toolCallId: toolCall.id,
|
|
7
5
|
toolName: toolCall.function.name,
|
|
8
6
|
success: false,
|
|
@@ -10,11 +8,9 @@ export const toolErrorEvent = (context, toolCall, errorMessage) => ({
|
|
|
10
8
|
error: errorMessage,
|
|
11
9
|
timestamp: new Date().toISOString(),
|
|
12
10
|
});
|
|
13
|
-
export const toolResultToEvents = (
|
|
11
|
+
export const toolResultToEvents = (result) => {
|
|
14
12
|
const toolCompleteEvent = {
|
|
15
13
|
kind: 'tool-complete',
|
|
16
|
-
contextId: context.contextId,
|
|
17
|
-
taskId: context.taskId,
|
|
18
14
|
toolCallId: result.toolCallId,
|
|
19
15
|
toolName: result.toolName,
|
|
20
16
|
success: result.success,
|
|
@@ -24,8 +20,6 @@ export const toolResultToEvents = (context, _toolCall, result) => {
|
|
|
24
20
|
};
|
|
25
21
|
const messageEvents = result.messages?.map((message) => ({
|
|
26
22
|
kind: 'internal:tool-message',
|
|
27
|
-
contextId: context.contextId,
|
|
28
|
-
taskId: context.taskId,
|
|
29
23
|
message,
|
|
30
24
|
timestamp: new Date().toISOString(),
|
|
31
25
|
})) ?? [];
|
package/dist/types/a2a.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LLMMessage } from './message';
|
|
2
2
|
export type A2ATaskState = 'submitted' | 'working' | 'input-required' | 'completed' | 'canceled' | 'failed' | 'rejected' | 'auth-required' | 'unknown';
|
|
3
3
|
export interface A2ATaskStatus {
|
|
4
4
|
state: A2ATaskState;
|
|
5
|
-
message?:
|
|
5
|
+
message?: LLMMessage;
|
|
6
6
|
timestamp?: string;
|
|
7
7
|
}
|
|
8
8
|
export type A2APart = A2ATextPart | A2AFilePart | A2ADataPart;
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SerializedError } from '../utils/error';
|
|
2
2
|
export interface AgentState {
|
|
3
|
-
status: 'created' | '
|
|
3
|
+
status: 'created' | 'idle' | 'busy' | 'shutdown' | 'error';
|
|
4
4
|
turnCount: number;
|
|
5
5
|
lastActivity: Date;
|
|
6
6
|
createdAt: Date;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type pino from 'pino';
|
|
2
|
+
import type { Observable } from 'rxjs';
|
|
3
|
+
import type { LLMProvider } from '../types/llm';
|
|
4
|
+
import type { AnyEvent, ContextAnyEvent } from './event';
|
|
5
|
+
import type { ToolCall, ToolDefinition } from './tools';
|
|
6
|
+
export type AgentContext<AuthContext> = Readonly<{
|
|
7
|
+
agentId: string;
|
|
8
|
+
contextId: string;
|
|
9
|
+
parentContext: import('@opentelemetry/api').Context;
|
|
10
|
+
authContext?: AuthContext;
|
|
11
|
+
logger: pino.Logger;
|
|
12
|
+
plugins: readonly Plugin<AuthContext>[];
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
}>;
|
|
15
|
+
export type TurnContext<AuthContext> = AgentContext<AuthContext> & Readonly<{
|
|
16
|
+
taskId: string;
|
|
17
|
+
turnNumber: number;
|
|
18
|
+
}>;
|
|
19
|
+
export type LoopContext<AuthContext> = TurnContext<AuthContext>;
|
|
20
|
+
export type IterationContext<AuthContext> = TurnContext<AuthContext>;
|
|
21
|
+
export type LoopConfig = {
|
|
22
|
+
llmProvider: LLMProvider;
|
|
23
|
+
maxIterations: number;
|
|
24
|
+
stopOnToolError: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type IterationConfig<AuthContext> = {
|
|
27
|
+
llmProvider: LLMProvider | ((context: LoopContext<AuthContext>, systemPromptMetadata: Record<string, unknown> | undefined) => LLMProvider);
|
|
28
|
+
iterationNumber: number;
|
|
29
|
+
};
|
|
30
|
+
export type Plugin<AuthContext> = BasePlugin & Partial<SystemPromptPlugin<AuthContext>> & Partial<ToolPlugin<AuthContext>>;
|
|
31
|
+
type BasePlugin = {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly version?: string;
|
|
34
|
+
};
|
|
35
|
+
export type SystemPromptPlugin<AuthContext> = {
|
|
36
|
+
generateSystemPrompts: (context: IterationContext<AuthContext>) => SystemPrompt[] | Promise<SystemPrompt[]>;
|
|
37
|
+
};
|
|
38
|
+
export declare const isSystemPromptPlugin: <AuthContext>(plugin: Plugin<AuthContext>) => plugin is BasePlugin & SystemPromptPlugin<AuthContext>;
|
|
39
|
+
export type ToolPlugin<AuthContext> = {
|
|
40
|
+
listTools: () => Promise<ToolDefinition[]>;
|
|
41
|
+
getTool: (toolId: string) => Promise<ToolDefinition | undefined>;
|
|
42
|
+
executeTool: (toolCall: ToolCall, context: IterationContext<AuthContext>) => Observable<ContextAnyEvent | AnyEvent>;
|
|
43
|
+
};
|
|
44
|
+
export declare const isToolPlugin: <AuthContext>(plugin: Plugin<AuthContext>) => plugin is BasePlugin & ToolPlugin<AuthContext>;
|
|
45
|
+
export type SystemPrompt = {
|
|
46
|
+
content: string;
|
|
47
|
+
position: 'before' | 'after';
|
|
48
|
+
positionSequence?: number;
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
source?: {
|
|
51
|
+
providerName: string;
|
|
52
|
+
promptName: string;
|
|
53
|
+
promptVersion?: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const isSystemPromptPlugin = (plugin) => {
|
|
2
|
+
return typeof plugin.generateSystemPrompts === 'function';
|
|
3
|
+
};
|
|
4
|
+
export const isToolPlugin = (plugin) => {
|
|
5
|
+
return (typeof plugin.listTools === 'function' &&
|
|
6
|
+
typeof plugin.getTool === 'function' &&
|
|
7
|
+
typeof plugin.executeTool === 'function');
|
|
8
|
+
};
|
package/dist/types/event.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LLMMessage, SystemLLMMessage } from './message';
|
|
2
2
|
import type { ToolCall } from './tools';
|
|
3
3
|
export type TaskStatus = 'working' | 'waiting-input' | 'waiting-auth' | 'waiting-subtask' | 'completed' | 'failed' | 'canceled';
|
|
4
4
|
export type ThoughtVerbosity = 'brief' | 'normal' | 'detailed';
|
|
5
5
|
export type ThoughtType = 'analysis' | 'planning' | 'reasoning' | 'reflection' | 'thinking' | 'decision' | 'observation' | 'strategy';
|
|
6
|
-
export type InputType = '
|
|
6
|
+
export type InputType = 'confirmation' | 'clarification' | 'selection' | 'data';
|
|
7
7
|
export type AuthType = 'oauth2' | 'api-key' | 'password' | 'biometric' | 'custom';
|
|
8
8
|
export type TaskInitiator = 'user' | 'agent';
|
|
9
|
-
export type InputProvider = 'user' | '
|
|
9
|
+
export type InputProvider = 'user' | 'any';
|
|
10
10
|
export interface JSONSchema {
|
|
11
11
|
type?: string;
|
|
12
12
|
properties?: Record<string, JSONSchema>;
|
|
@@ -269,7 +269,7 @@ export interface InternalLLMCallEvent {
|
|
|
269
269
|
}
|
|
270
270
|
export interface InternalToolMessageEvent {
|
|
271
271
|
kind: 'internal:tool-message';
|
|
272
|
-
message:
|
|
272
|
+
message: SystemLLMMessage;
|
|
273
273
|
timestamp: string;
|
|
274
274
|
}
|
|
275
275
|
export interface InternalCheckpointEvent {
|
|
@@ -307,13 +307,14 @@ export interface LLMUsageEvent {
|
|
|
307
307
|
export type UsageEvent = LLMUsageEvent;
|
|
308
308
|
export interface MessageEvent {
|
|
309
309
|
kind: 'message';
|
|
310
|
-
message:
|
|
310
|
+
message: LLMMessage;
|
|
311
311
|
timestamp: string;
|
|
312
312
|
}
|
|
313
313
|
export type AnyEvent = TaskLifecycleEvent | ContentStreamingEvent | ToolExecutionEvent | InputRequestEvent | AuthenticationEvent | ArtifactEvent | SubAgentEvent | ThoughtStreamEvent | InternalDebugEvent | UsageEvent | MessageEvent;
|
|
314
314
|
export type ContextEvent<T> = T & {
|
|
315
315
|
contextId: string;
|
|
316
316
|
taskId: string;
|
|
317
|
+
path?: string[];
|
|
317
318
|
};
|
|
318
319
|
export type ChildTaskEvent<T> = T & {
|
|
319
320
|
parentTaskId: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export * from './a2a';
|
|
|
2
2
|
export * from './agent';
|
|
3
3
|
export * from './artifact';
|
|
4
4
|
export * from './context';
|
|
5
|
+
export * from './core';
|
|
5
6
|
export * from './event';
|
|
6
7
|
export * from './llm';
|
|
7
8
|
export * from './message';
|
|
9
|
+
export * from './prettify';
|
|
8
10
|
export * from './skills';
|
|
9
11
|
export * from './state';
|
|
10
12
|
export * from './tools';
|
package/dist/types/index.js
CHANGED
|
@@ -2,9 +2,11 @@ export * from './a2a';
|
|
|
2
2
|
export * from './agent';
|
|
3
3
|
export * from './artifact';
|
|
4
4
|
export * from './context';
|
|
5
|
+
export * from './core';
|
|
5
6
|
export * from './event';
|
|
6
7
|
export * from './llm';
|
|
7
8
|
export * from './message';
|
|
9
|
+
export * from './prettify';
|
|
8
10
|
export * from './skills';
|
|
9
11
|
export * from './state';
|
|
10
12
|
export * from './tools';
|
package/dist/types/llm.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs';
|
|
2
2
|
import type { AnyEvent } from './event';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LLMMessage } from './message';
|
|
4
4
|
import type { ToolCall, ToolDefinition } from './tools';
|
|
5
5
|
export interface LLMProvider {
|
|
6
6
|
call(request: {
|
|
7
|
-
messages:
|
|
7
|
+
messages: LLMMessage[];
|
|
8
8
|
tools?: ToolDefinition[];
|
|
9
9
|
stream?: boolean;
|
|
10
10
|
sessionId?: string;
|
|
11
11
|
}): Observable<AnyEvent>;
|
|
12
12
|
}
|
|
13
13
|
export interface LLMResponse {
|
|
14
|
-
message:
|
|
14
|
+
message: LLMMessage;
|
|
15
15
|
toolCalls?: ToolCall[];
|
|
16
16
|
finished: boolean;
|
|
17
17
|
finishReason?: 'stop' | 'length' | 'tool_calls' | 'content_filter';
|
package/dist/types/message.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import type { ToolCall } from './tools';
|
|
2
|
-
export type
|
|
2
|
+
export type SystemLLMMessage = {
|
|
3
3
|
role: 'system';
|
|
4
4
|
content: string;
|
|
5
5
|
name?: string;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type UserLLMMessage = {
|
|
8
8
|
role: 'user';
|
|
9
9
|
content: string;
|
|
10
10
|
name?: string;
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
12
|
+
export type AssistantLLMMessage = {
|
|
13
13
|
role: 'assistant';
|
|
14
14
|
content: string;
|
|
15
15
|
name?: string;
|
|
16
16
|
toolCalls?: ToolCall[];
|
|
17
17
|
};
|
|
18
|
-
export type
|
|
18
|
+
export type ToolLLMMessage = {
|
|
19
19
|
role: 'tool';
|
|
20
20
|
content: string;
|
|
21
21
|
name?: string;
|
|
22
22
|
toolCallId: string;
|
|
23
23
|
};
|
|
24
|
-
export type
|
|
24
|
+
export type LLMMessage = SystemLLMMessage | UserLLMMessage | AssistantLLMMessage | ToolLLMMessage;
|
package/dist/types/state.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { LLMResponse } from './llm';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LLMMessage } from './message';
|
|
3
3
|
import type { ToolCall, ToolDefinition, ToolResult } from './tools';
|
|
4
4
|
export interface PersistedLoopState {
|
|
5
5
|
taskId: string;
|
|
6
6
|
agentId: string;
|
|
7
7
|
parentTaskId?: string;
|
|
8
8
|
contextId: string;
|
|
9
|
-
messages:
|
|
9
|
+
messages: LLMMessage[];
|
|
10
10
|
systemPrompt: string;
|
|
11
11
|
iteration: number;
|
|
12
12
|
completed: boolean;
|
package/dist/types/tools.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type { Observable } from 'rxjs';
|
|
2
1
|
import { z } from 'zod';
|
|
3
|
-
import type {
|
|
4
|
-
import type { ContextAnyEvent } from './event';
|
|
5
|
-
import type { SystemMessage } from './message';
|
|
2
|
+
import type { SystemLLMMessage } from './message';
|
|
6
3
|
export interface ToolCall {
|
|
7
4
|
id: string;
|
|
8
5
|
type: 'function';
|
|
@@ -17,7 +14,7 @@ export interface ToolResult {
|
|
|
17
14
|
success: boolean;
|
|
18
15
|
result: unknown;
|
|
19
16
|
error?: string;
|
|
20
|
-
messages?:
|
|
17
|
+
messages?: SystemLLMMessage[];
|
|
21
18
|
}
|
|
22
19
|
export declare const JsonSchemaPropertySchema: z.ZodType<unknown>;
|
|
23
20
|
export type JsonSchemaProperty = z.infer<typeof JsonSchemaPropertySchema>;
|
|
@@ -29,7 +26,7 @@ export declare const FunctionParametersSchema: z.ZodObject<{
|
|
|
29
26
|
}, z.core.$strip>;
|
|
30
27
|
export type FunctionParameters = z.infer<typeof FunctionParametersSchema>;
|
|
31
28
|
export declare const ToolDefinitionSchema: z.ZodObject<{
|
|
32
|
-
|
|
29
|
+
id: z.ZodString;
|
|
33
30
|
description: z.ZodString;
|
|
34
31
|
icon: z.ZodOptional<z.ZodString>;
|
|
35
32
|
parameters: z.ZodObject<{
|
|
@@ -54,9 +51,3 @@ export declare const ToolCallSchema: z.ZodObject<{
|
|
|
54
51
|
arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
55
52
|
}, z.core.$strip>;
|
|
56
53
|
}, z.core.$strip>;
|
|
57
|
-
export type ToolProvider<AuthContext> = {
|
|
58
|
-
get name(): string;
|
|
59
|
-
getTool(toolName: string): Promise<ToolDefinition | undefined>;
|
|
60
|
-
getTools(): Promise<ToolDefinition[]>;
|
|
61
|
-
execute(toolCall: ToolCall, context: ExecutionContext<AuthContext>): Observable<ContextAnyEvent>;
|
|
62
|
-
};
|
package/dist/types/tools.js
CHANGED
|
@@ -25,11 +25,11 @@ export const FunctionParametersSchema = z.object({
|
|
|
25
25
|
additionalProperties: z.boolean().optional(),
|
|
26
26
|
});
|
|
27
27
|
export const ToolDefinitionSchema = z.object({
|
|
28
|
-
|
|
28
|
+
id: z
|
|
29
29
|
.string()
|
|
30
30
|
.min(1)
|
|
31
31
|
.max(64)
|
|
32
|
-
.regex(/^[a-zA-Z0-9_-]+$/, 'Tool
|
|
32
|
+
.regex(/^[a-zA-Z0-9_-]+$/, 'Tool ID must contain only alphanumeric characters, underscores, and hyphens'),
|
|
33
33
|
description: z.string().min(1).max(1024),
|
|
34
34
|
icon: z.string().optional(),
|
|
35
35
|
parameters: FunctionParametersSchema,
|
package/dist/utils/prompt.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
version?: number;
|
|
1
|
+
import type { IterationContext, Plugin, SystemPrompt } from '../types/core';
|
|
2
|
+
export type SystemPrompts = {
|
|
3
|
+
before: readonly SystemPrompt[];
|
|
4
|
+
after: readonly SystemPrompt[];
|
|
6
5
|
};
|
|
7
|
-
export
|
|
8
|
-
export declare const getSystemPrompt: <AuthContext>(systemPrompt: SystemPromptProp | undefined, loopContext: LoopContext<AuthContext>) => Promise<SystemPrompt | undefined>;
|
|
6
|
+
export declare const getSystemPrompts: <AuthContext>(plugins: readonly Plugin<AuthContext>[] | undefined, loopContext: IterationContext<AuthContext>) => Promise<SystemPrompts>;
|
package/dist/utils/prompt.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
export const
|
|
2
|
-
if (!
|
|
3
|
-
return
|
|
1
|
+
export const getSystemPrompts = async (plugins, loopContext) => {
|
|
2
|
+
if (!plugins?.length) {
|
|
3
|
+
return { before: [], after: [] };
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const prompts = await Promise.all(plugins.map((p) => p.generateSystemPrompts?.(loopContext)));
|
|
6
|
+
const flattened = prompts.flat().filter((p) => p !== undefined);
|
|
7
|
+
const before = Object.freeze(flattened
|
|
8
|
+
.filter((p) => p.position === 'before')
|
|
9
|
+
.sort((a, b) => (a.positionSequence ?? 0) - (b.positionSequence ?? 0)));
|
|
10
|
+
const after = Object.freeze(flattened
|
|
11
|
+
.filter((p) => p.position === 'after')
|
|
12
|
+
.sort((a, b) => (a.positionSequence ?? 0) - (b.positionSequence ?? 0)));
|
|
13
|
+
return { before, after };
|
|
12
14
|
};
|